| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 6273 人关注过本帖
标题:QQ刷屏机器人
只看楼主 加入收藏
JiaJinz21
Rank: 2
等 级:论坛游民
帖 子:7
专家分:20
注 册:2021-7-15
收藏
 问题点数:0 回复次数:5 
QQ刷屏机器人
思路:收集内容,放入剪贴板,启动线程模拟按键
代码如下:
程序代码:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.datatransfer.*;

/**

 *@author Jiang

 *@Date 2021/7/11 15:55

 *@version QQRobot1.0
*/
public class QQRobot_1 extends JFrame implements Runnable
{
    //等待时间
    private int waitTime = 0;
    //内容
    private JLabel textLabel = null;
    private JTextField textInput = null;
    //次数
    private JLabel numLabel = null;
    private JTextField numInput = null;
    //高级设置
    private JButton settingButton = null;
    //开始、暂停
    private JButton startButton = null;
    private JButton suspendButton = null;
    //退出
    private JButton exitButton = null;
    //机器人
    private Robot robot = null;
    //线程
    private Thread thread = null;
    //作者信息
    private JButton infoButton = null;
    //构造方法
    private QQRobot_1()
    {
    //机器人
    try
        {
        this.robot = new Robot();
        }catch(Exception e)
        {
        JOptionPane.showMessageDialog(this,"程序错误,请重启!");
        System.exit(1);
        }
    //等待时间
    this.waitTime = 1000;
    //窗口设置
    this.setSize(250,200);
    this.setResizable(false);

    this.setLayout(new FlowLayout());
    this.setTitle("QQRobot");
    //内容
    textLabel = new JLabel("内容:");
    textInput = new JTextField(17);
    textInput.setText("感谢使用!");
    //次数
    numLabel = new JLabel("次数:");
    numInput = new JTextField(17);
    numInput.setText("50");
    //高级设置
    settingButton = new JButton("高级设置");
    settingButton.addActionListener((ActionEvent e)->
                    {
                        setting.setVisible(true);
                    });
    //开始,暂停
    startButton = new JButton("开始");
    startButton.addActionListener((ActionEvent e)->
                      {
                      thread = new Thread(this);
                      thread.start();
                      });
    suspendButton = new JButton("取消");
    suspendButton.addActionListener((ActionEvent e)->
                    {
                        if(thread!=null)
                        {
                            thread.stop();
                            thread = null;
                        }else
                        {
                            return;
                        }
                    });
    infoButton = new JButton("关于");
    infoButton.addActionListener((ActionEvent e)->
                     {
                     new Info();
                     });
    exitButton = new JButton("退出");
    exitButton.addActionListener((ActionEvent e)->
                     {
                     System.exit(0);
                     });
    //组装
    this.add(textLabel);
    this.add(textInput);
    this.add(numLabel);
    this.add(numInput);
    this.add(settingButton);
    this.add(startButton);
    this.add(suspendButton);
    this.add(infoButton);
    this.add(exitButton);
    }
    //高级设置
    private Setting setting = new Setting();

    private class Setting extends JFrame
    {
    //延迟设置
    public JLabel delayLabel = null;
    public JTextField delayInput = null;
    //等待时间
    public JLabel waitLabel = null;
    public JTextField waitInput = null;
    //确认、取消、应用
    public JButton confirmButton = null;
    public JButton cancelButton = null;
        public JButton applyButton = null;
    //构造方法
    public Setting()
    {
        this.setLayout(new FlowLayout());
        //延迟
        this.delayLabel = new JLabel("延迟");
        this.delayInput = new JTextField(17);
        this.delayInput.setText("50");
        //等待时间
        this.waitLabel = new JLabel("等待");
        this.waitInput = new JTextField(17);
        this.waitInput.setText("1000");
        //确认、取消、应用
        this.confirmButton = new JButton("确认");
        confirmButton.addActionListener((ActionEvent e)->
                        {
                        try
                            {
                            QQRobot_1.this.robot.setAutoDelay(Integer.valueOf(delayInput.getText()));//设置延迟
                            QQRobot_1.this.waitTime = Integer.valueOf(waitInput.getText());
                            this.setVisible(false);
                            }catch(Exception ee)
                            {
                            JOptionPane.showMessageDialog(this,"设置失败");
                            }
                        });
        this.cancelButton = new JButton("取消");
        cancelButton.addActionListener((ActionEvent e)->
                       {
                           this.delayInput.setText("50");//恢复文字
                           this.waitInput.setText("1000");
                           this.setVisible(false);//关闭窗口
                       });
        this.applyButton = new JButton("应用");
        applyButton.addActionListener((ActionEvent e)->
                      {
                          try
                            {
                            QQRobot_1.this.robot.setAutoDelay(Integer.valueOf(delayInput.getText()));//设置延迟
                            QQRobot_1.this.waitTime = Integer.valueOf(waitInput.getText());
                            }catch(Exception eee)
                            {
                            JOptionPane.showMessageDialog(this,"设置失败");
                            }
                      });
        //组装
        this.setSize(250,150);
        this.add(delayLabel);
        this.add(delayInput);
        this.add(waitLabel);
        this.add(waitInput);
        this.add(confirmButton);
        this.add(cancelButton);
        this.add(applyButton);
    }
    }
    public void run()
    {
    try
        {
        Thread.sleep(this.waitTime);
        var clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        clipboard.setContents(new StringSelection(textInput.getText()),null);
        var number = Integer.valueOf(numInput.getText());
        for(int i=0;i<number;i++)
            {
            this.robot.keyPress(KeyEvent.VK_CONTROL);
            this.robot.keyPress(KeyEvent.VK_V);
            this.robot.keyRelease(KeyEvent.VK_CONTROL);
            this.robot.keyRelease(KeyEvent.VK_V);
            this.robot.keyPress(KeyEvent.VK_ENTER);
            this.robot.keyRelease(KeyEvent.VK_ENTER);
            }
        }catch(Exception e)
        {
        JOptionPane.showMessageDialog(this,"程序错误");
        return;
        }
    }
    public static void main(String[] args)
    {
    new QQRobot_1().setVisible(true);
    }
    private class Info extends JFrame
    {
    public Info()
    {
        this.setTitle("关于");
        this.setLayout(new FlowLayout());
        this.setSize(150,140);
        this.add(new JLabel("作者QQ&邮箱"));
        this.add(new JLabel("2794942751"));
        this.add(new JLabel("JiaJinz21@));
        this.setDefaultCloseOperation​(0);
        JButton ExitButton = new JButton("退出");
        ExitButton.addActionListener((ActionEvent e)->
                     {
                         this.setVisible(false);
                     });
        this.add(ExitButton);
        this.setResizable​(false);
        this.setVisible(true);
    }
    }
}

搜索更多相关主题的帖子: new add null this private 
2021-07-15 13:48
hwdream
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2021-8-9
收藏
得分:0 
var clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(new StringSelection(textInput.getText()),null);
var number = Integer.valueOf(numInput.getText());
语法错误
this.setDefaultCloseOperation​(0);
this.setResizable​(false);
没有此方法
2021-08-09 17:58
JiaJinz21
Rank: 2
等 级:论坛游民
帖 子:7
专家分:20
注 册:2021-7-15
收藏
得分:0 
回复 2楼 hwdream
我在我的环境测试了没有问题的
2021-08-16 18:45
JiaJinz21
Rank: 2
等 级:论坛游民
帖 子:7
专家分:20
注 册:2021-7-15
收藏
得分:0 
2021-08-16 18:53
DOLd
Rank: 2
等 级:论坛游民
帖 子:6
专家分:13
注 册:2020-3-17
收藏
得分:0 
2021-11-15 15:12
player2000
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2022-5-28
收藏
得分:0 
霸屏杀手,给损友用用
2022-05-28 17:33
快速回复:QQ刷屏机器人
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.108729 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved