gpt4 book ai didi

java - 我应该在JOptionPane.showMessageDialog()中使用什么组件?

转载 作者:行者123 更新时间:2023-12-02 11:06:52 24 4
gpt4 key购买 nike

我使用Java Swing创建了一个登录框架-Login Frame(1),其中也发生了用户身份验证。

  • 看起来像这样:


  • 因此,如果用户输入了错误的电子邮件ID/密码,则应显示一个消息对话框。这就是为什么我在这里使用:
    JOptionPane.showMessageDialog( this,"plese enter correct id/password")

    但是它显示了一个错误。
    Login.addActionListener((e) -> {
    ArrayList<Registration> list0;
    list0=UserDataReadWriteFromFile.readDataFromFile();
    int idpos=Search.searchId(tuid.getText().trim());
    if(idpos >=0){
    String ueid=tuid.getText().trim();
    String uupass=tpass.getText().trim();
    if(ueid.equals(list0.get(idpos).getId())&& uupass.equals(list0.get(idpos).getPassword())){
    new SearchDisp(idpos);
    }
    else
    JOptionPane.showMessageDialog( this,"plese enter correct id/password");
    }
    });

    我应该在 JOptionPane.showMessageDialog()中使用什么组件?
    这是我的登录框架的代码。在此代码中,用“登录”按钮添加了 Action 侦听器,该 Action 侦听器是在我要求的上面的代码中编写的。
    public class LoginFrame{
    public LoginFrame() {
    JLabel uid, upass;
    JTextField tuid;
    JPasswordField tpass;
    JButton Login;

    JFrame frame = new JFrame("Login");

    frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);

    frame.setLayout(null);
    JLabel background = new JLabel(new ImageIcon(
    "C:\\Users\\Tousif\\Desktop\\Login.jpg"));
    frame.setContentPane(background);

    uid = new JLabel("Email Id");
    uid.setBounds(60, 50, 120, 25);
    frame.add(uid);

    tuid = new JTextField(20);
    tuid.setBounds(120, 50, 150, 24);
    frame.add(tuid);

    upass = new JLabel("Password");
    upass.setBounds(53, 80, 120, 25);
    frame.add(upass);

    tpass = new JPasswordField(20);
    tpass.setBounds(120, 80, 150, 24);
    frame.add(tpass);

    Login = new JButton("Login");
    Login.setBounds(150, 110, 80, 25);
    frame.add(Login);

    frame.setSize(370, 216);
    frame.setResizable(false);


    frame.setLocationRelativeTo(null);

    frame.setVisible(true);
    }

    public static void main(String[] arg) {
    new LoginFrame();
    }
    }

    最佳答案

    您可以只使用 null ,例如:

    JOptionPane.showMessageDialog(null, "Please Enter Correct ID and Password!", 
    "Invalid ID or Password", JOptionPane.WARNING_MESSAGE);

    关于java - 我应该在JOptionPane.showMessageDialog()中使用什么组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41406365/

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