gpt4 book ai didi

java - 如何使用Java实现简单的密码登录

转载 作者:行者123 更新时间:2023-12-02 10:23:19 24 4
gpt4 key购买 nike

对于一个学校项目,我需要想出一些简单的编程代码,但也对您提出挑战......

现在事情是这样的;我需要用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);
}

关于java - 如何使用Java实现简单的密码登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54165245/

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