• 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

mouseEntered and exited events to paint

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic