| Author |
Adding multiple Clickable areas in trailing mode to a frame
|
ali honarmand
Ranch Hand
Joined: Oct 12, 2009
Posts: 32
|
|
Hi everyone,
I'm working on a Naughts & Cross like game and I have problems with its GUI. I'm not familiar with JFX which seems to make it a peace of cake so I have to handle it using simple Swing. The problem is that I need to add a square(3^2) number of cells to my game area which are clickable(listen to events) - buttons are not a good choice - and change the surface according to the user clicks.
thanks
|
A. Honarmand
|
 |
Darryl Burke
Bartender
Joined: May 03, 2008
Posts: 4167
|
|
A JLabel (or indeed any Component) can respond to mouse events by adding a MouseListener (or as applicable, a MouseMotionListener). A GridLayout(3, 3) can take care of positioning andsizing of components.
More here: Creating a GUI With Swing.
|
luck, db
There are no new questions, but there may be new answers.
|
 |
ali honarmand
Ranch Hand
Joined: Oct 12, 2009
Posts: 32
|
|
thanks a lot. It solved the problem. I added the mouse listener to my JPanel class but as I click the underlying frame the event is again invoked.
I have got a JPanelClickEventListener as follows:
and I added an instance of the event Listener class to my JPanels as follows:
I should mention that the preceding code resides in a class extending JFrame.
|
 |
 |
|
|
subject: Adding multiple Clickable areas in trailing mode to a frame
|
|
|