2017-06-02 40 views
0

不完全確定我在這裏做了什麼錯誤,可能是錯過了某些東西。 這是GUI類無法將Java Swing GUI可見性設置爲true

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

這是一個autoclicker我目前工作的,我不知道是什麼問題,它發生在該行Clowns.this.ClownClicker.setVisible(true);

+3

'Clowns.this.ClownClicker'是不是有效的變量...另外,請了解'static'爲你實際做了些什麼 –

回答

1

這是GUI類,其中ClownClicker存在。

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); 
0

相反的:

ClownClicker.setVisible(true); 

試試這個。

frame.ClownClicker.setVisible(true); 
0

ClownClicker聲明,是不是在GUI類的靜態變量,因此你無法做Clowns.this.ClownClicker.setVisible(true); 合適的解決方案是 frame.ClownClicker.setVisible(true);

相關問題