java - Moving undecorated JFrame using mouse event and thread to update -
I would like to have my undecorted Therefore, in an attempt to understand threads better, I have a very simple undercotted and at the same time a thread continually updates the However, I can not understand why the controlling rhythm does not move more than one? Also, there is an explanation that the code below will be highly appreciated due to the horrific code. Your Secondly, if you want to move the frame continuously while moving your mouse, then you have to register a At the time of dragging ( JFrame s happy, then using a fixed reference
location.
JFrame
JFrame
MouseListener
point:
point p = mousewot.gatepoint ();
JFrame s location.
Public animation () headless expansion {P = this.getLocation (); Run (); Class Control Thread Extended Thread {JFrame j; Public Controllerthread (JFRM J) {this.j = j; } @ Override Public Wide Run () {this.j.setLocation (P); }} Controllertrade CT = new controllthread (this); Ct.run (); //ct.start (); } @ Override Public Wide Run () {this.setSize (d); Container CP = this.getContentPane (); P = this.getLocation (); This.setUndecorated (true); This.setVisible (true); This.setAlwaysOnTop (right); This.addMouseListener {newMovieListener} {@Override Public void mouseClicked (mouse EventM) {P = me.getPoint ();} @ Override Public Zero Mouse Mouse Pressed (Mouse Event Me) {P = me.getPoint ();} @ Override Public Zero Mouse Relayed (Mouse Event Me) {P = me.getPoint ();} @ Override Public Wide Mice Enter (Mouse Event Me) {} @ Override Public Wide Mouse Accord (Mouse Event Me) {}}); }
ControllerTrade does not run in different thread Because you call your
run () method to launch a new thread, you have to call your
start () method.
MouseMotionListener , a
MouseListener Only the mouse is pressed and receives the released events (and not the mouse moved or drawn events). Recommended solution:
mouse mouse) () and
MouseMotionListener
MouseListener register how much a frame was drawn (
mouseDragged () ), and the distance pulled by dragging that frame:
Public Animation () {MouseAdapter ma = new MouseAdapter () {Int lastX, last y; @ Override Public Zero Mouse Mouse (Mouse Event E) {lastX = E.x. OnScreen (;); LastY = E.A.G.O.OnScreen (); } @ Override Public Wide MouseDrag Ged (Mouse Event E) {int x = e.getXOnScreen (); Int y = e.getYOnScreen (); // Move the mouse delta by location (getLocationOnScreen () .x + x - lastX, getLocationOnScreen (). Y + y - the previous Y); LastX = x; Last Y = y; }}; AddMouseListener (ma); AddMouseMotionListener (ma); }
Comments
Post a Comment