我正在将autoclicker作为一个项目,当我现在打开窗口设计时,它只是显示一个空白。
我试图要求用户在微调器中写一个数字
微调器将其发送到延迟。
而不是按一个键来运行自动点击器并将其停止
但是我现在仍然没有把keylistener放在即时消息中,只是试图从微调器中获得延迟,直到现在还不能正常工作。
package autoclicker;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.InputEvent;
import java.util.*;
import javax.swing.JFormattedTextField;
public class auto {
static Scanner console = new Scanner(System.in);
private Robot robot;
private int delay;
public void AutoClicker1() {
try
{
robot = new Robot();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void clickMouse(int button)
{
try {
robot.mousePress(button);
robot.delay(10);
robot.mouseRelease(button);
robot.delay(delay);
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void setDelay(int delayy)
{
this.delay = delayy;
}
}
这是主要的
package autoclicker;
import javax.swing.*;
import java.awt.event.InputEvent;
import java.lang.Thread;
import java.util.Scanner;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
public class autoclicker {
private static KeyEvent e;
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner console = new Scanner(System.in);
JFrame frame = new JFrame("AutoClicker");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 500);
frame.setVisible(true);
frame.setResizable(false);
JPanel Panel = new JPanel();
Panel.setBackground(Color.DARK_GRAY);
Panel.setLayout(null);
JLabel AutoClicker = new JLabel("delay\r\n in ms");
AutoClicker.setBounds(10, 80, 151, 30);
AutoClicker.setForeground(Color.WHITE);
AutoClicker.setFont(new Font("Secular One", Font.PLAIN, 20));
JLabel label = new JLabel("AutoClicker");
label.setForeground(Color.CYAN);
label.setFont(new Font("Secular One", Font.PLAIN, 30));
label.setBounds(10, 11, 200, 57);
Panel.add(label);
JSpinner spinner = new JSpinner();
int Delayy = (int) spinner.getValue();
spinner.setBounds(128, 87, 69, 20);
Panel.add(spinner);
frame.add(Panel);
auto clicker = new auto();
System.out.println("----Auto Clicker----");
System.out.println("Enter delay in ms:");
while(Delayy==0)
{
}
clicker.setDelay(Delayy);
System.out.println("Program will start in 3 seconds.");
try {
System.out.println(3);
Thread.sleep(1000);
System.out.println(2);
Thread.sleep(1000);
System.out.println(1);
Thread.sleep(1000);
}
catch (Exception e)
{
e.printStackTrace();
}
clicker.AutoClicker1();
for(int i = 0; i<100; i++)
{
clicker.clickMouse(InputEvent.BUTTON1_DOWN_MASK);
}
}
}
最佳答案
您需要将面板添加到JFrame。
frame.add(Panel);
将组件添加到JFrame之后,您需要将Visibility()设置为true才能显示。
frame.setVisible(true);