7/11/2023 0 Comments Mouseadapter mouse coordinates![]() Similarly, any window component also has its internal coordinate system. Through the mouse listener of the window, we can also get the coordinates of the mouse in the window. The coordinate system of components and windows is as follows: The location of the above component refers to the location (coordinate) of the left vertex of the component. setBounds(x coordinate, y coordinate, component width, component height) coordinates refer to the coordinates of the coordinate system of this window setBounds usage: component object name. For example, set the location for the JLabel object: JLabel l=new JLabel("assembly") The setBounds method is used to set the component location. If we understand the coordinate system in the window, we can set the position of the window component. The left vertex of the window is (0,0), the positive direction of x axis is from left to right, and the positive direction of y axis is from top to bottom. Then, for a window in Java, there is a coordinate system inside the window. Of course, the mouse listener can get the coordinates of the mouse in the screen. The left vertex position of the window is the window position. In our commonly used JFrame method setLocation method (set window position), the coordinates set are relative to the coordinate system in this screen. The left vertex of the screen is (0,0), the positive direction of x axis is from left to right, and the positive direction of y axis is from top to bottom. How is this achieved? Let me share a demo of Java's draggable components.įirst of all, in Java, we have a coordinate system in our screen. Reset public void reset() Utility method calls FSMouseListener.reset() for all listeners currently being tracked.A lot of daily software, some of the components (pictures, buttons, etc.) can be dragged in the window. Specified by: mouseDragged in interface MouseMotionListener Overrides: mouseDragged in class MouseAdapter MouseDragged public void mouseDragged( MouseEvent e) Specified by: mousePressed in interface MouseListener Overrides: mousePressed in class MouseAdapter MousePressed public void mousePressed( MouseEvent e) Specified by: mouseReleased in interface MouseListener Overrides: mouseReleased in class MouseAdapter ![]() MouseReleased public void mouseReleased( MouseEvent e) Specified by: mouseMoved in interface MouseMotionListener Overrides: mouseMoved in class MouseAdapter MouseMoved public void mouseMoved( MouseEvent e) Specified by: mouseExited in interface MouseListener Overrides: mouseExited in class MouseAdapter MouseExited public void mouseExited( MouseEvent e) Specified by: mouseEntered in interface MouseListener Overrides: mouseEntered in class MouseAdapter MouseEntered public void mouseEntered( MouseEvent e) Returns: a (new) list of all listeners currently tracked for receiving events. GetListeners public List getListeners() Returns a (new) list of all listeners currently tracked for receiving events. RemoveListener public void removeListener( FSMouseListener l) Removes the given listener, after which it will no longer receive callbacks on mouse events. Method DetailĪddListener public void addListener( FSMouseListener l) Adds a listener to receive callbacks on mouse events. Parameters: panel - the panel for which mouse events should be delegated. MouseTracker public MouseTracker( BasicPanel panel) Instantiates a MouseTracker to listen to mouse events for the given panel. ![]() ObjectĬlone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait Utility method calls FSMouseListener.reset() for all listeners currently being tracked. Removes the given listener, after which it will no longer receive callbacks on mouse events. Returns a (new) list of all listeners currently tracked for receiving events. Instantiates a MouseTracker to listen to mouse events for the given panel.Īdds a listener to receive callbacks on mouse events. The MouseTracker is also responsible for using MouseEvent coordinates to located the Box on which the mouse is Via the add and remove methods and the tracker will remain active as long as the tracker has at least one listener. The tracker will start receiving events as soonĪs the first listener is added (via addListener(FSMouseListener) and will stop receiving events as soonĪs the last listener is removed via removeListener(FSMouseListener). Public class MouseTracker extends MouseInputAdapterĪ MouseTracker is used to delegate mouse events to the FSMouseListener instancesĪssociated with a BasicPanel. SUMMARY: NESTED | FIELD | CONSTR | METHODĬlass MouseTracker All Implemented Interfaces: MouseListener, MouseMotionListener, MouseWheelListener, EventListener, MouseInputListener MouseTracker (Flying Saucer Core Renderer 9.0.1 API)
0 Comments
Leave a Reply. |