Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

mouseEntered and exited events to paint

 
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 create variables that define the left half of my window and right half
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you'd use "if" statements in those event handlers. You can declare whatever variables you need as member variables, and the event handlers can use them. You'll probably want to use a member variable to hold the current background color so the event handlers can set it and the painting method can see it.

Moving this to our Swing/AWT forum for followup.
 
alaina peeler
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok so if i use the JPanel's getSize() method and find the windows size i should divide that in half to get the windows center. so how could i put it in code which side would be left and which side would be the right side? i know i need mouseMotion events to get the cursers current x position, but how would i declare the two sides of my window
 
We're all out of roofs. But we still have tiny ads:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!