constructing actionPerformed method without using if statements
Hi,
I'm currently writing a basic swing program, and have used 'if' statements within the actionPerformed methods. I wondered if there was a better, neater way of doing this without using the 'if' statements.
My code so far is as follows,
method 1:
staticprivateclass IncrementDecrementActionimplements ActionListener{
boolean oddNumberClick =true;
publicvoid actionPerformed(ActionEvent e){
if (oddNumberClick= !oddNumberClick)
SimpleSwing.label.setText(labelPrefix +"Decrement");
else
SimpleSwing.label.setText(labelPrefix +"Increment");
}
}
method 2:
staticprivateclass ClickActionimplements ActionListener{
publicint numClicks = 0;
publicvoid actionPerformed(ActionEvent e){
if (SimpleSwing.label.getText().equals(labelPrefix +"Increment"))
numClicks++;
else
numClicks--;
SimpleSwing.label2.setText(labelPrefix2 + numClicks);
}
}
Any ideas or advice appreciated.
Thanks

