Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, I am having problems with the f

Status
Not open for further replies.

croucherj3

Programmer
Sep 13, 2003
5
US
Hi, I am having problems with the following code. It works okay if I use the mouse to select the Yes/No option from the dialog box. However, if I use the Tab/Enter keys to select No, the "E statement is always displayed when n is tested. Any ideas why this only works with the mouse?

Thanks for your help,
John
Athens, OH
============================================================
import javax.swing.*;

class DemoDialog2
{
public static void main(String[] args)
{
int n = JOptionPane.showConfirmDialog(
null, "Do you like green eggs and ham?",
"An Inane Question",
JOptionPane.YES_NO_OPTION);

if (n == JOptionPane.YES_OPTION)
System.out.println("E else
if (n == JOptionPane.NO_OPTION)
System.out.println("Me neither!");

System.exit(0);

}
}
 
Sorry about the subject heading. Can anyone tell me how to edit it?
 
import javax.swing.*;
class DemoDialog2
{
public static void main(String[] args)
{
int n = JOptionPane.showConfirmDialog(
null, "Do you like green eggs and ham?",
"An Inane Question",
JOptionPane.YES_NO_OPTION);

if (n == JOptionPane.YES_OPTION)
{
System.out.println("E System.exit(0);
}
else
if (n == JOptionPane.NO_OPTION)
{
System.out.println("Me neither!");
System.exit(0);
}


}
}
It works now!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top