Afternoon folks, just after a bit of advise really, as there MUST be a better way of doing this. I have a GUI with a numpad type interface, now for each button 0-9 I have an action listener like so:
Then later on I'll add the action Listener to the button like so
But seeing as each button basically has the same behaviour there must a better way of coding this, as If I decide I need to change the behaviour I have to change 10 actionPerformed() methods which is a bit of a maintenance nightmare
So over to you
Code:
private class Keypad0ActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
if(vmachine.giveChange()>0) {
if(messageString=="MACHINE READY")
productCode = "0";
else
productCode += "0";
balanceAmount = Double.toString(vMachine.giveChange);
messageString = balance + balanceAmount +"\t" + product + productCode;
message.setText(messageString);
} else {
message.setText("INSERT MONEY");
Thread.sleep(3000);
message.setText("MACHINE READY");
}
}
}
Then later on I'll add the action Listener to the button like so
Code:
kpad0.addActionListener(new Keypad0ActionListener());
But seeing as each button basically has the same behaviour there must a better way of coding this, as If I decide I need to change the behaviour I have to change 10 actionPerformed() methods which is a bit of a maintenance nightmare
So over to you
