自动点击程序无法正常运行

时间:2017-06-05 11:20:37

标签: java while-loop macros jframe clicking

我正在制作一个自动点击的程序。代码的宏相关部分独立工作,我试图让它与我的GUI一起工作,我最初用一段时间(真实)循环进行测试,但现在我想要正确的功能它不能正常工作。有谁知道为什么?

package Hobabo;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent;

import javax.swing.*;





public class Clicker {


    static String version = "0.3";



    private static JFrame main;
    private static JPanel view;
    private static JButton start;
    private static JButton selfd;
    private static JLabel intro;
    private static JLabel info;


    static boolean on = false;















    public static void gui(){

        main = new JFrame("Hobabo Clicker " + version);
        main.setVisible(true);
        main.setSize(300, 400);
        main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


        view = new JPanel();
        view.setBackground(Color.darkGray);


        start = new JButton("Start");
        start.addActionListener(new ActionListener(){

            @Override
            public void actionPerformed(ActionEvent e) {
                // TODO Auto-generated method stub
                if(on == false){
                    start.setText("Stop");
                    on = true;
                    System.out.println("Started, true");
                }else{
                    start.setText("Start");
                    on = false;
                    System.out.println("Stopped, false");
                }
            }

        });


        selfd = new JButton("Self Destruct");
        selfd.addActionListener(new ActionListener(){

            @Override
            public void actionPerformed(ActionEvent e) {
                // TODO Auto-generated method stub

                main.dispatchEvent(new WindowEvent(main, WindowEvent.WINDOW_CLOSING));


            }

        });


        intro = new JLabel("HES HACKING FOLKS HADEEGA HOBAAAA");
        intro.setForeground(Color.white);

        info = new JLabel("Created by NotRaymond.");
        info.setForeground(Color.white);



        view.add(intro);
        view.add(start);
        view.add(selfd);
        view.add(info);


        main.add(view);


    }



    public static void clicker(){


        while(on == true){



            leftClick();
            delay(1);















        }



    }



    protected static void delay(double seconds){
        createMacro();
        macro.delay((int)(seconds * 1000));
    }


    protected static void leftClick(){
        createMacro();
        macro.mousePress(MouseEvent.BUTTON1_MASK);
        macro.mouseRelease(MouseEvent.BUTTON1_MASK);
    }


    private static Robot macro = null;

    private static void createMacro(){
        try {
            macro = new Robot();
        }catch (AWTException e){
            e.printStackTrace();
        }
    }













    public static void main(String args[]){
        gui();
        clicker();
    }







}

0 个答案:

没有答案