JavaFX ToolKit未初始化

时间:2017-12-28 01:50:46

标签: java

我试图为管理员用户名/密码设置两个输入,但错误的名称为" java.lang.IllegalStateException:Toolkit未初始化"。这个程序工作正常,直到我添加了JTextField的东西,我检查了大量的网站(Oracle,StackOverFlow等),但无法找到答案。我不认为我在任何地方的代码中使用JavaFX。提前致谢 :) 完整的错误代码位于底部。

这是我的代码:

import javax.swing.JOptionPane;
import javax.swing.JTextField;
//import java.awt.*;
//import java.awt.event.*;
//import java.util.Scanner; Replaced with JOptionPane;
import java.util.concurrent.TimeUnit;
//import java.io.File;                 
//import java.io.FileWriter;
//import java.io.FileReader; //Needed for a previous version
//import java.io.IOException;
//import java.io.BufferedReader;
import java.text.DateFormat;
import java.text.SimpleDateFormat;   
import java.util.Date;
public class HackerGame {
public static void Credentials() throws InterruptedException {
    System.out.println('\u000C');
    String[] names = new String[]{"Hugh Jackman","David Lowe","Ethan Reed"};
    String[] usernames = new String[]{"HughMan13","BigDave13","Ethanol13"};
    String[] passwords = new String[]{"SmallMan31","SmallDave31","Diesel31"};
    System.out.println("Gathering Employee Information...");
    TimeUnit.SECONDS.sleep(3);
    System.out.println("Listing Employee Credentials: ");
    System.out.println(""); //Kept for distance purposes
    for (int i = 0; i < 3; i++) {
        System.out.println("Name: " + names[i] + " Username: " +
                            usernames[i] + " Password: " + passwords[i]);
        System.out.println("---");
        TimeUnit.SECONDS.sleep(1);
}
    TimeUnit.SECONDS.sleep(5);
}
public static void Growth() throws InterruptedException {
    int years = 2012;
    int value = 150000;
    System.out.println('\u000C');
    System.out.println("Company Growth By Year: ");
    for (int i = 0; i < 5; i++) {
        System.out.println("Year: " + (years + i) + " Value: " + "$" +
                            (value + (45000 * i)));
        System.out.println("---");
        TimeUnit.SECONDS.sleep(1);                    
    }
    TimeUnit.SECONDS.sleep(5);
}
public static void Console() throws InterruptedException {
    System.out.println('\u000C');
    DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    Date date = new Date();
    System.out.println("Accessing Console Log For: " + dateFormat.format(date) + " ...");
    TimeUnit.SECONDS.sleep(3);
    System.out.println("---------------");
    System.out.println("IP 153.131.132.64 Connected");
    System.out.println("IP 153.131.132.64 Opened /bin/users/admin/username.txt");
    System.out.println("IP 153.131.132.64 Closed /bin/users/admin/username.txt");
    System.out.println("IP 153.131.132.64 Opened /bin/users/admin/password.txt");
    System.out.println("IP 153.131.132.64 Closed /bin/users/admin/password.txt");
    System.out.println("IP 153.131.132.64 Cleared /bin/console/cache");
    System.out.println("IP 153.131.132.64 Disconnected");
    System.out.println("IP 233.132.104.140 Connected");
    System.out.println("IP 233.132.104.140 Opened /bin/console/cache");
    System.out.println("IP 233.132.104.140 Restored /bin/console/cache");
    System.out.println("IP 233.132.104.140 Copied /bin/console/cache");
    System.out.println("IP 233.132.104.140 Closed /bin/console/cache");
    System.out.println("IP 233.132.104.140 Disconnected");
    System.out.println("End of Log For: " + dateFormat.format(date));
    TimeUnit.SECONDS.sleep(5);
}
public static void main(String[] args) throws InterruptedException {
    System.out.println('\u000C');
    System.out.println("You are hacking into the system. Use these numbers to");
    System.out.println("help you: 33472001, 123, and 321. Good Luck.");
    System.out.println("");
    System.out.println("Loading Game...");
    TimeUnit.SECONDS.sleep(7);     
    String[] firewallpass = new String[]{"33472001","10027433","20013347"};
    String[] firewallreq = new String[3];
        firewallreq[0] = "Enter First FireWall Password: ";
        firewallreq[1] = "Enter Second FireWall Password: ";
        firewallreq[2] = "Enter Third FireWall Password: ";
    String[] database = new String[]{"Employee Credentials","Company Growth","Console Log"};
    System.out.println('\u000C');
    String input;
    input = JOptionPane.showInputDialog
                ("Launch Program? Y/N: ");
    if (input.equalsIgnoreCase("Y")) {
        System.out.println("Initializing...");
        TimeUnit.SECONDS.sleep(3);
        System.out.println('\u000C');
    } else if (input.equalsIgnoreCase("N")) {
        System.out.println("Exiting...");
        TimeUnit.SECONDS.sleep(3);
        System.exit(0);            
    } else {
        System.out.println("Exiting...");
        TimeUnit.SECONDS.sleep(3);
        System.exit(0);
    }
    for (int i = 0; i < 3; i++) {
    //System.out.println(firewallreq[i]);
    String firewall; 
    firewall = JOptionPane.showInputDialog(firewallreq[i]);
    System.out.println('\u000C');
    if (firewall.equals(firewallpass[i])) {
        System.out.println("Bypassing...");
        TimeUnit.SECONDS.sleep(3);
    } else {
        System.out.println("You have been blocked. Exiting...");
        TimeUnit.SECONDS.sleep(3);
        System.exit(0);
    }
}
boolean adminLogIn = true;
while(adminLogIn) {
    System.out.println('\u000C');
    System.out.println("Enter Administrator Credentials: ");
    String adminusername = "admin";
    String adminpassword = "admin123";
    TimeUnit.SECONDS.sleep(1);

    JTextField username = new JTextField();      
    JTextField password = new JTextField();
    Object[] message = {
        "Username: ", username,
        "Password: ", password
    };
    int option = JOptionPane.showConfirmDialog(null, message, "Login", JOptionPane.OK_CANCEL_OPTION);
    if (option == JOptionPane.OK_OPTION) {
        if (username.getText().equals(adminusername) && password.getText().equals(adminpassword)) {
            System.out.println("Logging In...");
            TimeUnit.SECONDS.sleep(3);
            adminLogIn = false;
        } else {
            System.out.println("Wrong username/password. Try Again");
    }
}
}
    System.out.println('\u000C');
    boolean loggedIn = true;
    while(loggedIn) {
    System.out.println("Enter Q to logout");
    System.out.println("You have access to these databases: ");
    System.out.println("----------");
    for (int i = 0; i < 3; i++) {
        System.out.println(database[i]);
        System.out.println("----------");
        TimeUnit.SECONDS.sleep(1);
}
    boolean methodChoice = true;
    while(methodChoice) {
        String method;
    method = JOptionPane.showInputDialog("Enter A Method: ");
if (method.equalsIgnoreCase(database[0])) {
    Credentials();
    methodChoice = false;
} else if (method.equalsIgnoreCase(database[1])) {
    Growth();
    methodChoice = false;
} else if (method.equalsIgnoreCase(database[2])) {
    Console();
    methodChoice = false;
} else if (method.equalsIgnoreCase("Q")) {
    System.out.println("Logging Out...");
    TimeUnit.SECONDS.sleep(3);
    System.exit(0);
} else {
    System.out.println("Enter A Valid Inquiry.");
}
}
}
}
}

这是例外

"java.lang.IllegalStateException: Toolkit not initialized"
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:273)
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:268)
at javafx.application.Platform.runLater(Platform.java:83)
at bluej.runtime.ExecServer.runOnTargetThread(ExecServer.java:902)
at bluej.runtime.ExecServer.access$700(ExecServer.java:78)
at bluej.runtime.ExecServer$3.run(ExecServer.java:767)

1 个答案:

答案 0 :(得分:2)

所以问题是我使用的应用程序BlueJ在某种程度上被破坏了,因为我无法运行任何程序。重新下载和删除已损坏的程序修复了此问题。谢谢大家的帮助:)