Results 1 to 4 of 4
- 03-05-2010, 04:22 PM #1
Member
- Join Date
- Jan 2010
- Posts
- 36
- Rep Power
- 0
ButtonWatcher implements ActionListener
Hi I'm trying to use method from other class within ButtonWatcher class but notsure how to do that (both classes are in the came package and method id public).
the code that Im working on is:
and the method that Im trying to implement is in TicTacToe.java class:Java Code:private class ButtonWatcher implements ActionListener { public void actionPerformed (ActionEvent a) { Object buttonPressed = a.getSource(); if (buttonPressed.equals(playButton)) { gameUnderWay = true; } if (buttonPressed.equals(xButton)) { TicTacToe.setFirstPlayerSymbol(0); startingGameButtons(); } if (buttonPressed.equals(oButton)) { setFirstPlayerSymbol(a); startingGameButtons(); } }
I know it must be silly mistake but I really need advide how to implement that method.Java Code:public void setFirstPlayerSymbol(int chosenSymbol) // given { players[0] = chosenSymbol; players[1] = - chosenSymbol; }
- 03-05-2010, 05:32 PM #2
Member
- Join Date
- Jan 2010
- Posts
- 36
- Rep Power
- 0
i.e. this comes up with error: non-static method cannot be referenced from static context:
Please please... How to fix that?Java Code:/** *It lisen for clicks of any of the three buttons: *xButton, oButton and playButton, */ private class ButtonWatcher implements ActionListener { public void actionPerformed (ActionEvent a) { Object buttonPressed = a.getSource(); if (buttonPressed.equals(playButton)) { gameUnderWay = true; } if (buttonPressed.equals(xButton)) { playInstructions(); startingGameButtons(); TicTacToe.setFirstPlayerSymbol(1); } if (buttonPressed.equals(oButton)) { playInstructions(); startingGameButtons(); setFirstPlayerSymbol(-1); } } }
- 03-05-2010, 06:08 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
- 03-05-2010, 06:18 PM #4
Member
- Join Date
- Jan 2010
- Posts
- 36
- Rep Power
- 0
Similar Threads
-
How hibernate implements jpa specification?
By king9527 in forum Advanced JavaReplies: 1Last Post: 02-05-2010, 10:53 AM -
Hashtable implements ActionListener ?
By Zayaan in forum New To JavaReplies: 5Last Post: 11-16-2009, 07:49 PM -
Adding 2 Implements to the class
By jboy in forum New To JavaReplies: 2Last Post: 10-23-2009, 05:19 AM -
HashSet and AbstractSet both Implements Set
By rkjsohi2 in forum New To JavaReplies: 1Last Post: 08-07-2008, 11:04 AM -
How to implements cryptation in a java
By paul in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 05:06 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks