How to let the button set to it "latest" text because i suppose to set the button's text to "booked" and the foreground to red. However, everytime i re-run the program, the button re-set. I know i should do something on constructor, but how?
Here is my coding.. Thanks for advance =)...
for(int i=0; i<10; i++){
fcButton[i] = new JButton();
if(fcButton[i].getText() != "Booked"){
fcButton[i].setText("Seat"+(i+1));
buttonPanelL.add(fcButton[i]);
fcButton[i].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
ButtonActionPerformed(e);
}
});
}
}
for(int i=10; i<20; i++){
fcButton[i] = new JButton();
if(fcButton[i].getText() != "Booked"){
fcButton[i].setText("Seat"+(i+1));
buttonPanelR.add(fcButton[i]);
fcButton[i].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
ButtonActionPerformed(e);
}
});
}
}
public void ButtonActionPerformed(ActionEvent e){
for(int i=0; i<20; i++){
if(e.getSource() == fcButton[i]){
if(fcButton[i].getText() != "Booked"){
str = fcButton[i].getText();
fcButton[i].setText("Booked");
fcButton[i].setForeground(Color.red);
JOptionPane.showMessageDialog(null,"Your seat is: "+str);
}
else{
JOptionPane.showMessageDialog(null,"THIS PLACE WAS BOOKED");
}
}
}
}