• Post Reply Bookmark Topic Watch Topic
  • New Topic

help with mouse methods in paint  RSS feed

 
alaina peeler
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im trying to create a program what when the mouse enters the left side of my window the background should change to red; if the mouse moves into the right side i need to change it to green. once i find the size of my window by saying d = yourFrame.getSize(); where do i calculate to find which side my mouse pointer is on at that time. could i use an if else statement in the mouseEntered and mouseExited? and how could i define to diff background colors in the paint method?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the Swing forum for expert advice...
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
add a MouseMotionListener, and in mouseMoved():
mouseEvent.getX() will give you the current point relative to the width
container.getBackground() will get you the current background

then its just a matter of determining what color the background should be,
for the getX() position, and comparing it to the current background.
if the comparison is different, change the color to the correct background
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!