【发布时间】:2013-11-21 05:59:49
【问题描述】:
我正在用 Java 中的 JOptionPane 进行试验,我想制作一个简单的密码程序。在创建它时,我想实现一个密码自动保存功能。我不知道实际访问文本框(输入文本的区域)的方法。
import javax.swing.JOptionPane;
public class passWord_GUI {
public static void main(String[] args) {
String username = JOptionPane.showInputDialog("Enter username");
String password = JOptionPane.showInputDialog("Enter password");
//password.setTheConentOfTheTextBox(passwordSave);
//Set up the UI.
if (username != null
&& password != null
&& username.equals("asdf")
&& password.equals("swordfish")) {
JOptionPane.showMessageDialog(null, "You're in!");
String passwordSave = "swordfish";
} else {
JOptionPane.showInternalMessageDialog(null, "Wrong! Try again.");
}
}
}
我只是想知道一种无需在其中实际输入内容即可编辑文本框内容的方法。在这种情况下,请输入密码。
感谢您的帮助!
【问题讨论】:
-
阅读 JOptionPane API。您将在
How to Use Option Panes上找到指向 Swing 教程的链接,该链接为您提供了使用输入对话框的示例。
标签: java swing passwords joptionpane