Charles Bell
Posts: 519
Nickname: charles
Registered: Feb, 2002
|
|
Re: JOptionPane Problem
|
Posted: Sep 17, 2002 2:29 PM
|
|
In the test2 method I used the method: public static int showOptionDialog( Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon, Object[] Object initialValue) if you look carefully at the dialog that comes up the yes button is default selected in the test1() and the no button is selected in test2().
import javax.swing.*; class JOptionTest extends JFrame{ public static void main(String[] args){ JOptionTest tester = new JOptionTest(); tester.test1(); tester.test2(); System.exit(0); } public void test1(){ String message = "Are you sure?"; int result=JOptionPane.showConfirmDialog(this, message, message, JOptionPane.YES_NO_OPTION); if (result == JOptionPane.NO_OPTION){ JOptionPane.showMessageDialog(this,"You picked No."); }else{ JOptionPane.showMessageDialog(this,"You picked Yes."); } } public void test2(){ String message = "Are you sure?"; Object[] options = {"Yes", "No"}; int result = JOptionPane.showOptionDialog(this, message, message, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]); if (result == JOptionPane.NO_OPTION){ JOptionPane.showMessageDialog(this,"You picked No."); }else{ JOptionPane.showMessageDialog(this,"You picked Yes."); } } }
|
|