【问题标题】:I'm unable to fix the JOption error in Java, GUI我无法修复 Java、GUI 中的 JOption 错误
【发布时间】:2019-09-14 15:12:08
【问题描述】:

1- 我不明白为什么“frmLOGIN”会给我一个错误。我应该输入什么?

2- 这里 JOption 的正确语法是什么?为什么这是一个错误?

我尝试将 JOption 更改为 JOptionpane,但我认为这不能解决问题 我也尝试将 frmLOGIN 更改为 lblLogIn 但这会更改不应该发生的 JFrame。

JButton btnExit = new JButton("EXIT");
btnExit.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
        frmLOGIN = new JFrame("EXIT");
    if (JOption.showConfirmDialog(frmLOGIN, "Confirm if you want to exit", "LOGIN"),
                JOptionPane.YES_NO_OPTION)==JOptionPane.YES_NO_OPTION){
            System.exit(0); 
        }
    }

this is an image go my GUI so far

【问题讨论】:

    标签: java eclipse user-interface syntax software-design


    【解决方案1】:

    应该是

    if (JOptionPane.showConfirmDialog(frmLOGIN, "Confirm if you want to exit", "LOGIN",
                JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION)
    

    即替换为 YES_OPTION

    【讨论】:

      【解决方案2】:

      你的代码应该是这样的:

      btnExit.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      if (JOptionPane.showConfirmDialog(frmLOGIN, "Confirm if you want to exit", "LOGIN",JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                          System.exit(0);
                      }
                  }
      });
      

      【讨论】:

        猜你喜欢
        • 2012-10-01
        • 2015-03-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多