| | |
updating variable on ouseMoved
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Mar 2008
Posts: 76
Reputation:
Solved Threads: 3
Class A has a MouseMotionListener which updates cursorLocation every time its called;
Class B extends A. the idea is to make B's lastSelected update once cursorLocation is updated and println the new coords. i thought paintComponent could be used for that but im sure theres something obvious im missing:
Class B extends A. the idea is to make B's lastSelected update once cursorLocation is updated and println the new coords. i thought paintComponent could be used for that but im sure theres something obvious im missing:
java Syntax (Toggle Plain Text)
import java.awt.*; import java.awt.event.*; import javax.swing.*; class A extends JPanel{ Point cursorLocation; A() { setPreferredSize(new Dimension(200,200)); addMouseMotionListener(new MouseMotionHandler()); } private class MouseMotionHandler extends MouseMotionAdapter { public void mouseMoved(MouseEvent e) { cursorLocation = new Point(e.getX(), e.getY());} } }
java Syntax (Toggle Plain Text)
import java.awt.*; import javax.swing.*; public class B extends A{ Point lastSelected; static public void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(600,400); B b = new B(); frame.getContentPane().add(BorderLayout.CENTER,b); frame.setVisible(true); } B() { super(); } /* public void paintComponent(Graphics g) { if (lastSelected != cursorLocation) { lastSelected = new Point(cursorLocation); repaint(); } System.out.println(lastSelected); */ } }
![]() |
Similar Threads
- sorting (C++)
- Updating StreamReader (C#)
- how to find largest number? (Java)
- multithreading exception (C#)
- Need help making this program do high and low temperature (C++)
- Please help on updating instance variable (Java)
- SOAP call constructor each time (Java)
- Updating Controls (C++)
- updating 2 HTML tables on one PHP page (PHP)
Other Threads in the Java Forum
- Previous Thread: Help needed with Push and Pop methods
- Next Thread: beginner question <<save an image in a folder>>
| Thread Tools | Search this Thread |
-xlint android api applet application array arrays automation bi binary blackberry block bluetooth chat class classes client code compile compiler component database developmenthelp draw eclipse error event exception fractal freeze game gameprogramming givemetehcodez graphics gui html ide image input integer j2me j2seprojects java javac javaprojects jetbrains jni jpanel jtable julia learningresources lego linux list login loop loops mac map method methods mobile netbeans newbie notdisplaying number online oracle page print problem program programming project qt recursion scanner screen server set singleton size sms sort sql string swing system template textfields threads time title tree tutorial-sample update variablebinding windows working xor





