0

I'm making a program that automatically clicks. The macro related part of the code works on its own and I'm trying to get it to work with my GUI, I originally had it with a while(true) loop for testing but now that I want proper functionality it isn't working. Does anyone know why??

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();
    }







}
leon
  • 39
  • 2
  • 7

0 Answers0