Ok im lost in trying to create a button array to test them out with an if statement in the actionlistner method. I need to create 2 buttons one name "Go" and another named "Clear" for an application. In the actionlistener i then have to use an if statement to test which button was pressed and perform the rest of the code depending which of the buttons was pressed. This is what i have came up with thus far and this section of code alone gets me 18 errors.

Panel buttonPanel = new Panel();
		Button buttons = new Button;
		buttons = new Button[2];
		buttons[0] = new Button("Go");
		buttons[1] = new Button("Clear");

You need to declare your variable "buttons" as an array of Buttons, as in

JButton[] myArrayOfJButtons;

then, and only then, you can assign an new array of buttons to that variable

myArrayOfJButtons = new JButton[2];

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.