In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "the mouse wheel event analysis of MouseWheelListener in Java". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "the mouse wheel event analysis of MouseWheelListener in Java".
About the mouse wheel event of MouseWheelListener
The handling of mouse wheel events in the JPanel panel in Java.
I. MouseWheelListener interface
There is only one void mouseWheelMoved (MouseWheelEvent e) method in the MouseWheelListener interface, which is called when the mouse wheel is scrolled. So rewrite this method.
We use the public int getWheelRotation () method in the MouseWheelEvent class.
2. Public int getWheelRotation ()
Negative if the mouse wheel rotates up / away from the user, and positive if the mouse wheel rotates downward towards the user
Code demonstration:
The main realization of the JPanel container, and JFrame window magnification and reduction.
The method used here is the way of push-button roller.
Import java.awt.*;import javax.swing.*;import java.awt.event.*;public class MouseWheelListener01 extends JFrame implements MouseWheelListener {public static void main (String [] args) {new MouseWheelListener01 ();} int h = 300; int w = 300; JPanel j = new JPanel (); / / Constructor MouseWheelListener01 () {super ("zoom roller") This.add (j); this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); this.setSize (hrecow); this.setVisible (true); this.addMouseWheelListener (this) / / add mouse wheel event} / / use the wheel event to zoom in and out of the window public void mouseWheelMoved (MouseWheelEvent e) {/ / if the mouse wheel rotates up or away from the user, it is a negative value, and if the mouse wheel rotates downward or toward the user, it is a positive value if (e.getWheelRotation () = = 1) {h = h + 15 W = w + 15; this.setSize (HJO w); this.validate (); System.out.println ("pulley forward...") ;} if (e.getWheelRotation () = =-1) {h = h-15; w = w-15; this.setSize (hling w); this.validate (); System.out.println ("pulley backward....");}} Java get mouse wheel press event
Both the wheel press event and the mouse click event are in MouseListener.
To determine the roller press, the original method is as follows: public void mouseClicked (MouseEvent e) {int modifiers = e.getModifiers (); if ((modifiers & InputEvent.BUTTON2_MASK) = = InputEvent.BUTTON2_MASK) {System.out.println ("middle button click");}} of course, you can use SwingUtilities public void mouseClicked (MouseEvent e) {if (SwingUtilities.isMiddleMouseButton (e)) {System.out.println ("middle button click") }} at this point, I believe you have a deeper understanding of the "mouse wheel event analysis of MouseWheelListener in Java". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.