help please


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: help please

  1. #1
    Join Date
    Feb 2005
    Posts
    55

    help please

    I can't get hte message dialogs to appear in the JTextField if the number is typed incorrectly. for example if I type 256 the dialog should appear saying invalid range and it doesnt. What have I done wrong.

    JButton calculate = new JButton("Calculate");

    public void actionPerformed(ActionEvent event)
    {
    int f1 = Integer.parseInt(field1.getText());
    int f2 = Integer.parseInt(field2.getText());
    int f3 = Integer.parseInt(field3.getText());
    int f4 = Integer.parseInt(field4.getText());
    if (event.getSource() == calculate)
    {

    if (f2 < 0 && f2 > 255)
    JOptionPane.showMessageDialog(frame, "Invalid Range!", "Error", JOptionPane.ERROR_MESSAGE);
    if (f3 < 0 && f3 > 255)
    JOptionPane.showMessageDialog(frame, "Invalid Range!", "Error", JOptionPane.ERROR_MESSAGE);
    if (f4 < 0 && f4 > 255)
    JOptionPane.showMessageDialog(frame, "Invalid Range!", "Error", JOptionPane.ERROR_MESSAGE);
    }
    }

  2. #2
    Join Date
    Jan 2005
    Posts
    45
    Hi trixma,

    Could you imagine a number < 0 and > 255 ? probably you can't

    Your tests should be rebuilt like this: if (f2 <0 || f2 > 255) ...

    Best regards,
    Lionel Badiou
    CodeFutures -
    Java Code Generation

    http://www.codefutures.com



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center