|
-
Mar 9th, 2012, 06:56 PM
#1
[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
Last edited by Nightwalker83; Mar 9th, 2012 at 07:14 PM.
Reason: Forgot to add the actionlistener
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Mar 16th, 2012, 09:03 PM
#2
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:
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|