返回对象时遇到问题

Having trouble returning an object

这是我的程序:

Public class SimpleRGB
{
    //Instance variables

    private int width, height;
    private int[][] red = new int[10][10];
    //same for green/blue

    public SimpleRGB(int aWidth, int aHeight)
    {
        //...
    }

    //Some methods

这是给我带来麻烦的方法。在这种方法中,我应该创建一个新图像(简单的 rgb 对象),使用嵌套的 for 循环将新的简单 rgb 的红色 D 数组设置为这个简单的 rgb 的红色二维数组(不确定我是否没有't that correctly),在同一个循环中将绿色和蓝色设置为 0(认为我做对了)然后 return 新的简单 rgb 对象。我对此很陌生,所以我不确定如何 returning 我的简单对象也会 return 我在 for 循环中设置的数据,而且我不相信我是 creating/returning简单的rgb正确。任何帮助将不胜感激!谢谢。

    Public SimpleRGB getRedImage()
    {

        SimpleRGB redImage = new SimpleRGB(); //Completely lost here. Not sure why but Java won't let me use "new: here. Also I'm confused as to how the data from the for-loop will even bee associated with this objectd       

        for (int i = 0; i < width; i++)
        {
            For (int j  0; j < height; j++)
            {
                red[i][j] = ?? //some code here to set red value of new object to red value
                green[i][j] = 0; //set to 0 b/c we only want red color
                blue[i][j] = 0; //set to 0 b/c we only want red color
            }
        }

        Return redImage(); //not sure if this is correct/if "()" are needed

以下是对您的方法的一些快速修复。首先,您需要将两个 int 参数添加到您的 SimpleRGB() 调用,即 SimpleRGB(int,int) 秒 我在您的 for 循环中将数组作为新对象的目标。

Public SimpleRGB getRedImage()
{

    SimpleRGB redImage = new SimpleRGB(int,int);     

    for (int i = 0; i < width; i++)
    {
        For (int j  0; j < height; j++)
        {
            redImage.red[i][j] = ??;  
            redImage.green[i][j] = 0;
            redImage.blue[i][j] = 0;
        }
    }

    Return redImage; //removed the ()
}