Duplicate :
|
|
Relates :
|
|
Relates :
|
FULL PRODUCT VERSION : java version "1.5.0" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64) Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode) ADDITIONAL OS VERSION INFORMATION : Windows XP Home SP2 A DESCRIPTION OF THE PROBLEM : In the code sample below the JOptionPane pops up 4 times before one can enter the Textfield again after an erroneous input. STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : Compile and run EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - JOptionPane should appear only once. ACTUAL - Clicking [OK] made the OptionPane reappear. REPRODUCIBILITY : This bug can be reproduced always. ---------- BEGIN SOURCE ---------- import java.awt.*; import java.awt.event.*; import javax.swing.*; public class T extends JFrame { JTextField tf1; public T() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container cp= getContentPane(); cp.setLayout(null); setSize(500,300); tf1= new JTextField(); tf1.setBounds(200,80,100,25); tf1.addFocusListener(new FocusAdapter() { public void focusLost(FocusEvent e) { try { double d= Double.parseDouble(tf1.getText()); if (d<4. || d>50.) { throw new NumberFormatException(); } } catch (NumberFormatException nfe) { JOptionPane.showMessageDialog(T.this, "Erroneous input.\nValid range is 4-50.", "Error", JOptionPane.ERROR_MESSAGE); tf1.requestFocus(); } } }); cp.add(tf1); JTextField tf2= new JTextField(); tf2.setBounds(200,120,100,25); cp.add(tf2); setVisible(true); } static public void main(String args[]) { new T(); } } ---------- END SOURCE ---------- ###@###.### 2004-12-24 10:11:24 GMT
|