开发者社区> 问答> 正文

我应该在主要方法中输入什么

我有一个输出类,它从输入类接收数组。然后,将数组更改为输出类中的标签。我的输出类的main方法出错。它可能需要处理输入类之间的连接。我应该在输出类的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 []输入不正确,但是我不知道是什么。

问题来源:Stack Overflow

展开
收起
montos 2020-03-22 09:02:43 824 0
1 条回答
写回答
取消 提交回答
  • 您实际上需要声明并初始化要作为参数传递的数组。

    因此,首先像这样创建一个int数组。

    这将创建一个大小为10的数组(虽然没有分配值)

    int[] intArr = new int[10] 您还可以创建一个数组并像这样在一行中填充值

    // now you can call your method and pass the array you created
    Output outputObj = new Output(intArr);```
    
    回答来源:Stack Overflow
    2020-03-22 09:03:20
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载