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
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.
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