Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

addActionListener to the point  RSS feed

 
Anissa Pary
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I am given an assignment to create an oval using java GUI and give it random colour, after that when I am pressing on this oval it should change its colour. This is where the problem comes from... I understand how to do GUI but the problem is I don't know where to attach actionListener I cannot attach it to the oval because it is not drawn, I thought may be I should attach it to the center of my oval. However, how can attach a Listener to point??? Please help me!!! Thank you in adavnce
 
Zeeshan Sheikh
Ranch Hand
Posts: 144
Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post your code so we can help you better. Thanks
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does it have to be an actionListener?

MouseListener's mousePressed would
be much easier:

calculate the radius of the circle
get the x,y of the center of the circle
get the x,y of the point where the mouse clicks
calculate the distance between those x,y's

if distance > radius = outside circle
 
Campbell Ritchie
Marshal
Posts: 55681
161
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are looking for a particular location, you are working with the component, so that is one of the few instances where the component should implement the listener interface.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!