DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
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



Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links