gpt4 book ai didi

Java应用程序: Getting input before running

转载 作者:行者123 更新时间:2023-12-01 17:36:13 24 4
gpt4 key购买 nike

public class checkUsernames extends JFrame {
private static JTextArea textArea1;
private static JButton button1;
private static JScrollPane scrollPane1;
private static JTextField textField1;
private static JPasswordField passwordField1;
private static JLabel label3;
private static JButton button2;
private static JLabel label1;
private static JLabel label2;

public checkUsernames() {
initComponents();
}

public static void main(String[] args) throws IOException {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Nimbus isn't available");
}

javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
checkUsernames GUI = new checkUsernames();
GUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GUI.setVisible(true);
}
});
String username = textField1.toString();
String password = passwordField1.toString();

线程“main”中的异常 java.lang.NullPointerException

checkUsernames 是唯一的类。当我尝试运行应用程序时,程序将进一步执行(无需字符串用户名和字符串密码即可继续),而无需等待输入。我该如何解决这个问题?

最佳答案

如果您希望代码执行在等待输入时停止,请将 JFrame 设为模态 JDialogJOptionPane

关于Java应用程序: Getting input before running,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5972455/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com