[RESOLVED] Call one class from another
Hi,
I am working on an exercise for class which, work and everything but I am having trouble figuring out how to have my classes setup to be called from multli locations. I know you can use:
java Code:
private JButton Play = new JButton();
PlayGame gameHandler
Play = new JButton();
Play.setText("Play");
Play.setVisible(true);
Play.addActionListener(gameHandler);
class PlayGame implements ActionListener {
public void actionPerformed(ActionEvent e) {
for (int i = 0; i < 9; i++) {
btnKeypad[i].setText(" ");
btnKeypad[i].setEnabled(true);
}
}
}
to call a function from a button. However, how would I call the function from within another function?
Thanks,
Nightwalker
Re: Call one class from another
I have come up with:
java Code:
if (result == JOptionPane.NO_OPTION) {
System.exit(0);
} else {
resetGame();
}
private void resetGame() {
clickCount = 0;
for (int i = 0; i < 9; i++) {
btnKeypad[i].setText(" ");
btnKeypad[i].setEnabled(true);
}
}
class playGame implements ActionListener {
public void actionPerformed(ActionEvent e) {
resetGame();
}
This code works with the code in post #1 just replace the code in the post #1 actionpreformed with: