This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Game Development and the fly likes ActionEvent and JButton Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Game Development
Bookmark "ActionEvent and JButton Question" Watch "ActionEvent and JButton Question" New topic
Author

ActionEvent and JButton Question

Bear Kim
Greenhorn

Joined: Feb 25, 2012
Posts: 9
I'm creating an interactive tic-tac-toe game using swing graphics, in which I have nine buttons for the nine squares. Is it possible to keep track of which button is pressed as an ActionEvent?
For example, I'm trying to do this: JButton buttonChosen = _____________ where the blank would be which button was clicked by the mouse.

I'd really appreciate any help, thank you!

Bear
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
[actionEvent].getSource();
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: ActionEvent and JButton Question
 
Similar Threads
how to call a new .class file in Actionlistener
JButton Syntax Question
A simple calculator help!
How to handle events in java
JApplet Problem - HELP