简体   繁体   中英

I'm unable to fix the JOption error in Java, GUI

1- I don't get why "frmLOGIN" is giving me an error. What should I input instead?

2- what's the right syntax for JOption here? why is that an error?

I tried changing JOption to JOptionpane but I don't think that fixes the issue I also tried changing frmLOGIN to lblLogIn but that changes the JFrame which shouldn't occur.

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

your code should be like this :

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);
                }
            }
});

It should be

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

Ie replace by YES_OPTION

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM