对于一个学校项目,我需要想出一些简单的编程代码,但也对您提出挑战......
现在事情是这样的; 我需要用Java -> JFrame Form 制作一个游戏,您需要使用密码登录。如果错了,可以重新做。如果正确,您将可以继续游戏。
这是我想出的一些代码...不要 mock 我..我是菜鸟
public kleurFrame() {
initComponents();
JOptionPane.showInputDialog("Password?");
String geheugen;
geheugen = JOptionPane.INPUT_VALUE_PROPERTY;
String password;
password = "Hay";
while(geheugen != password){
JOptionPane.showInputDialog("Password?");
if (geheugen == password){
JOptionPane.EXIT and continue program;
请您参考如下方法:
第一个 JOptionPane.showInputDialog("Password?");
没有用,它只会显示一个忽略该值的对话框,第二个 geheugen = JOptionPane.INPUT_VALUE_PROPERTY;
code> 指向一个常量,它没有获取输入的密码,我在这里尝试满足您的需求,我希望它有所帮助:
public void kleurFrame() {
initComponents();
String geheugen = null ;
String password = "Hay"; // even if it is a bad practice to hardcode a password !!
while (!password.equals(geheugen)) {
geheugen = JOptionPane.showInputDialog("Password?");
}
// once the blocking loop ended, that means
// the password is correct and you can exit
// the dialog and continue normally
JOptionPane.showMessageDialog(null/*or the calling component*/,"the password is correct, now you can continue",
"this is just an example",JOptionPane.INFORMATION_MESSAGE);
}