Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adding multiple Clickable areas in trailing mode to a frame

 
ali honarmand
Ranch Hand
Posts: 32
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
ali honarmand
Ranch Hand
Posts: 32
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic