Java 我应该在我的主要方法中加入什么

Java 我应该在我的主要方法中加入什么,java,user-interface,Java,User Interface,我有一个输出类从输入类接收数组。然后将数组更改为输出类中的标签。我的输出类的main方法中有一个错误。它可能需要处理输入类之间的连接。我应该在输出类的主方法中添加什么来修复错误 输入代码: int[]output = new int[4]; output[0] = addObj.getSumA(); output[1] = addObj.getSumB(); output[2] = addObj.getSumC(); output[3] = addObj.getS

我有一个输出类从输入类接收数组。然后将数组更改为输出类中的标签。我的输出类的main方法中有一个错误。它可能需要处理输入类之间的连接。我应该在输出类的主方法中添加什么来修复错误

输入代码:

int[]output = new int[4];
    output[0] = addObj.getSumA();
    output[1] = addObj.getSumB();
    output[2] = addObj.getSumC();
    output[3] = addObj.getSumD();

    Output outputObj = new Output(output);
输出类代码:

public class Output extends JFrame implements ActionListener
{
    private JLabel numberA;
    private JLabel numberB;
    private JLabel numberC;
    private JLabel numberD;
    private Box numberBox;
    private Box numberBox2;

public Output(int output[])
{
    super("Output Frame");
    this.setBounds(430,300,600,450);
    this.getContentPane().setBackground(Color.PINK);
    this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    this.setLayout(new BorderLayout());

    this.numberA = new JLabel(Integer.toString(output[0]));
    this.numberB = new JLabel(Integer.toString(output[1]));
    this.numberC = new JLabel(Integer.toString(output[2]));
    this.numberD = new JLabel(Integer.toString(output[3]));

    numberBox = Box.createVerticalBox();
    numberBox.add(numberA);
    numberBox.add(numberC);

    numberBox2 = Box.createVerticalBox();
    numberBox2.add(numberB);
    numberBox2.add(numberD);

    this.setVisible(true);
}

public static void main (String[] args)
{
    Output outputObj = new Output(int[]);
}

请记住,这是gui。错误在上面的行中。int[]不是正确的输入,但我不知道是什么。

您需要实际声明并初始化一个数组以作为参数传递

首先创建一个int数组,如下所示

这将创建一个大小为10的数组(但没有指定值)

您还可以创建一个数组,并像这样在一行中填充值

int[] intArr = new int[]{ 1,2,3,4,5,6,7,8,9,10 }; 
// now you can call your method and pass the array you created
Output outputObj = new Output(intArr);

张贴错误,请回答您的问题?因此,即使这与我的课程无关,我也会这样做,并将其保留在我的主要方法中?@LeilaMOZAFFAR这样想。查看输出类内部的代码。您可以看到哪里有这样的代码:
output[0]
?这是访问传递给它的数组。因此,如果不创建数组并传递它,它将无法访问,您将得到一个错误。
int[] intArr = new int[]{ 1,2,3,4,5,6,7,8,9,10 }; 
// now you can call your method and pass the array you created
Output outputObj = new Output(intArr);