What am I supposed to put in my main method

Leila MOZAFFAR :

I have an output class receiving an array from an input class. The array is then changed into labels in the output class. I have an error in the main method of my output class. It might have something to deal with the connection between the input class. What should I have put in my main method of the output class to fix the error?

Code of input:

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);

Code of Output Class:

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[]);
}

Keep in mind this is gui. The error is in the line above. int[] isn't the correct thing to enter, but I don't know what is.

rhowell :

You need to actually declare and initialize an array to pass as an argument.

So create an int array first like this.

this creates an array of size 10 (doesn't have values assigned though)

int[] intArr = new int[10]

you can also create an array and populate the values in one line like this

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);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=296334&siteId=1