java - Moving undecorated JFrame using mouse event and thread to update -


I would like to have my undecorted JFrame s happy, then using a fixed reference location.

Therefore, in an attempt to understand threads better, I have a very simple undercotted JFrame JFrame

  • Add MouseListener
  • onMousePressed: point:
    • P = Mousevent.getPoint ();
    • On -Mouse Release: point p = mousewot.gatepoint ();

      and at the same time a thread continually updates the JFrame s location.

      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.

        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) {}}); }    

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

      Secondly, if you want to move the frame continuously while moving your mouse, then you have to register a MouseMotionListener , a MouseListener Only the mouse is pressed and receives the released events (and not the mouse moved or drawn events). Recommended solution:

      At the time of dragging ( 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

    Popular posts from this blog

    ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

    Matlab transpose a table vector -

    c# - Textbox not clickable but editable -