• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Adding multiple Clickable areas in trailing mode to a frame

 
Ranch Hand
Posts: 32
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
He baked a muffin that stole my car! And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic