aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Adding multiple Clickable areas in trailing mode to a frame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Adding multiple Clickable areas in trailing mode to a frame" Watch "Adding multiple Clickable areas in trailing mode to a frame" New topic
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: 4527
    
    5

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

Darryl Burke wrote: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.


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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Adding multiple Clickable areas in trailing mode to a frame