Hello guys;
I am working on this program for class and I am getting a strange error when trying to compile it. It keeps saying that a ] is expected on line 14 but I have a ] on line 14? I am sure this is something to do with accessing JLabel objects with an array but I am unsure.
Normally I would not ask here for class related stuff but this one has me stumped so any help or pointers to find the solution would be helpful.
Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JDemoResistance extends JFrame implements ActionListener
{
JLabel[] option = new JLabel[6];
final int WIDTH = 250;
final int HEIGHT = 120;
final String CLEAR = "";
int count = 0;
JButton but1 = new JButton("Remove Option");
option[5] = new JLabel("Remove all that do not apply");
option[4] = new JLabel("Makes no sense");
option[3] = new JLabel("Not Enough CREEPERS!");
option[2] = new JLabel("Should include cat ninjas");
option[1] = new JLabel("Too many bugs");
option[0] = new JLabel("Too bright in dark areas");
public JDemoResistance()
{
super("JDemoResistance");
setSize(WIDTH,HEIGHT);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new FlowLayout());
option[6].setFont(new Font("Arial",Font.BOLD,22);
for(int i = 5; i < 0, i--) //add all elements of the array to the Frame
{
add(option[i]);
}
add(but1); // add button to the Frame
but1.addActionListener(this); // capture events and execute actionPerformed
}
public static void main(String[] args)
{
JDemoResistance myStuff = new JDemoResistance();
myStuff.setVisible(true)
}
public void actionPerformed(ActionListener a)
{
if (count < 4) // prevent removing last item and informative label
{
option[count].setText(CLEAR); // clear label at count number
}
count++;
}
}