Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the effect of random mouse movement by Java

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how to achieve random mouse movement effect in Java". In daily operation, I believe many people have doubts about how to achieve random mouse movement effect in Java. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to achieve random mouse movement effect in Java". Next, please follow the editor to study!

The implementation code import javax.swing.*;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.Random;/** * Java implements random mouse movement * / public class MouseController implements Runnable {private Robot robot; private boolean isStop = false; public MouseController () {try {ControllerFrame frame = new ControllerFrame ("Prevent Locking"); frame.setVisible (true) Robot = new Robot ();} catch (AWTException e) {e.printStackTrace ();} @ Override public void run () {int x; int y; Random random = new Random (); while (! isStop) {/ / randomly generate coordinates. X = random.nextInt (1000); y = random.nextInt (1000); / / start moving robot.mouseMove (x, y); / / move robot.delay (6000) every 5 seconds }} / * GUI Frame generates a button, control program * * @ author max * / private class ControllerFrame extends JFrame {private static final long serialVersionUID = 1L; private JButton close = new JButton ("close"); public ControllerFrame (String title) {this (); setTitle (title) } public ControllerFrame () {setLayout (new FlowLayout (FlowLayout.LEADING)); setSize (100,100); setResizable (false); setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); setLocationRelativeTo (null); Dimension preferredSize = new Dimension (100,60); Font font = new Font (", 1,14) / / set button size, text and other attributes such as close.setPreferredSize (preferredSize); close.setFont (font); close.setBorderPainted (true); close.setFocusable (false); add (close); / / after clicking button, the program terminates. Close.addActionListener (new ActionListener () {@ Override public void actionPerformed (ActionEvent e) {isStop = true; dispose ();}});}} public static void main (String [] args) {MouseController m = new MouseController (); m.run () }} effect picture

After running, a box will pop up, and then you can switch to the application window that will expire.

If you don't want to keep the mouse moving, just click close.

At this point, the study on "how to achieve random mouse movement in Java" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report