I need to write an event driven JApplet, with 15 labeled buttons. The buttons say nearly identical things, with the exception of a number. I do not want to write them individually, and I need to know a way I can group them in a JApplet.
Essentially I need a way I can just write one string such as:
buttons [i] = new JButton ("Seat " + (i+1) + " is open.");
and have it label all the buttons.
I have an hour to figure out how to do this.
Help is greatly appreciated.
Name:
Anonymous2008-12-20 1:07
Here's the section of code I need it for:
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand( ).equals("Exit")){
int choice = JOptionPane.showConfirmDialog(null, "Do you want to exit?", "Confirm", JOptionPane.YES_NO_CANCEL_OPTION);
if(choice == JOptionPane.YES_OPTION){
createFile();
System.exit(0);
}
}
if(buttons[i].getText().equals("Occupied")){
int choice = JOptionPane.showConfirmDialog(null, "This seat is occupied - do you want to unbook this seat?", "Confirm", JOptionPane.YES_NO_OPTION);
if(choice == JOptionPane.YES_OPTION){
String code = JOptionPane.showInputDialog(null,"Enter code to unbook");
if(code.equals("7777")){
buttons[i].setText("Seat " +(i+1)+" is open.");
seatCounter--;
}
}
}
else{
int choice = JOptionPane.showConfirmDialog(null, "Do you want to book this seat?", "Confirm", JOptionPane.YES_NO_CANCEL_OPTION);
if(choice == JOptionPane.YES_OPTION){