不完全确定我在这里做错了什么,可能只是错过了什么。 这是GUI类
package me.(removed).clicker.gui;
import java.awt.Container;
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JSlider;
public class GUI
{
public JFrame ClownClicker;
public JSlider slider1;
public JSlider slider2;
public JLabel lblNewLabelXd;
public JSlider slider;
public GUI()
{
initialize();
}
private void initialize()
{
this.ClownClicker = new JFrame();
this.ClownClicker.setResizable(false);
this.ClownClicker.setTitle("Clown Clicker 0.3 BETA");
this.ClownClicker.setFont(new Font("Arial", 0, 12));
this.ClownClicker.setBounds(100, 100, 450, 120);
this.ClownClicker.setDefaultCloseOperation(3);
this.slider1 = new JSlider();
this.slider1.setMaximum(500);
this.slider1.setMinimum(75);
this.slider1.setValue(165);
this.ClownClicker.getContentPane().add(this.slider1, "Center");
this.slider2 = new JSlider();
this.slider2.setMinimum(25);
this.slider2.setMaximum(200);
this.slider2.setValue(75);
this.ClownClicker.getContentPane().add(this.slider2, "West");
this.lblNewLabelXd = new JLabel("New label\n xd");
this.lblNewLabelXd.setFont(new Font("Arial", 0, 11));
this.lblNewLabelXd.setHorizontalAlignment(0);
this.ClownClicker.getContentPane().add(this.lblNewLabelXd, "North");
this.slider = new JSlider();
this.slider.setMaximum(1000);
this.slider.setMinimum(1);
this.slider.setValue(100);
this.ClownClicker.getContentPane().add(this.slider, "South");
JLabel label = new JLabel();
}
}
这是主类
package me.(Removed).clicker.main;
import java.awt.AWTException;
import java.awt.EventQueue;
import java.awt.Point;
import java.awt.Robot;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JSlider;
import me.ciarandev.clicker.MouseListener;
import me.ciarandev.clicker.Timer;
import me.ciarandev.clicker.gui.GUI;
import org.jnativehook.GlobalScreen;
import org.jnativehook.NativeHookException;
public class Clowns
{
public static Robot robot;
public static Point mousePos;
public static boolean toggled = false;
public static boolean activated = false;
public static boolean skipNext = false;
public static boolean blockHit = false;
private static int delay = -1;
public static long lastTime = 0L;
public static int minCPS = 8;
public static int maxCPS = 12;
public static String[] toggleKey = { ",", "," };
public static int toggleMouseButton = 3;
public static Timer time = new Timer();
public static void main(String[] args)
{
LogManager.getLogManager().reset();
Logger.getLogger(GlobalScreen.class.getPackage().getName()).setLevel(Level.OFF);
GUI frame = new GUI();
EventQueue.invokeLater(new Runnable()
{
public void run()
{
try
{
Clowns.this.ClownClicker.setVisible(true);
}
catch (Exception e)
{
e.printStackTrace();
}
}
});
try
{
robot = new Robot();
GlobalScreen.registerNativeHook();
GlobalScreen.addNativeMouseListener(new MouseListener());
}
catch (NativeHookException|AWTException e)
{
e.printStackTrace();
}
try
{
for (;;)
{
Thread.sleep(1L);
minCPS = frame.slider2.getValue();
maxCPS = frame.slider1.getValue();
int minusMin = frame.slider.getValue() - frame.slider2.getValue();
int plusMax = frame.slider.getValue() + frame.slider1.getValue();
frame.lblNewLabelXd.setText("Min: " + minCPS + ", Max: " + maxCPS + ", Middleman: " + frame.slider.getValue() + ", CPS: " + MouseListener.cps + ", delay is from " + minusMin + " to " + plusMax);
Random random = new Random();
Random r = new Random();
if (delay == -1) {
delay = random.nextInt(1000 / minCPS - 1000 / maxCPS + 1) + 1000 / maxCPS;
}
if ((activated) && (toggled) && (!frame.frmNiggazClickerV.isFocused()) &&
(time.hasTimePassed(frame.slider.getValue() + (random.nextInt(maxCPS - minCPS + 1) + minCPS))) && (random.nextBoolean()) && (r.nextBoolean()))
{
click();
lastTime = System.currentTimeMillis();
time.reset();
}
}
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
private static void click()
{
skipNext = true;
robot.mousePress(16);
robot.mouseRelease(16);
if (blockHit)
{
robot.mousePress(4);
robot.mouseRelease(4);
}
}
public static void toggle()
{
if (toggled) {
toggled = false;
} else {
toggled = true;
}
activated = false;
skipNext = false;
blockHit = false;
}
}
这是我目前正在处理的自动转换器,我不知道问题是什么,它发生在Clowns.this.ClownClicker.setVisible(true)行;
答案 0 :(得分:1)
这是存在ClownClicker的GUI类。
public class GUI
{
public JFrame ClownClicker;
它不属于Clowns.this
,因此请使用GUI
实例。
final GUI frame = new GUI();
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
frame.ClownClicker.setVisible(true);
答案 1 :(得分:0)
而不是:
ClownClicker.setVisible(true);
试试这个。
frame.ClownClicker.setVisible(true);
答案 2 :(得分:0)
ClownClicker声明,在GUI类中不是静态变量,所以你不能做Clowns.this.ClownClicker.setVisible(true);
合适的解决方案是
frame.ClownClicker.setVisible(true);