Results 1 to 4 of 4
  1. #1
    thover is offline Member
    Join Date
    Jun 2013
    Posts
    2
    Rep Power
    0

    Default Java currency calculator error

    Dear readers,

    For a project on school I am developing a simple Currency Calculator. It should calculate the amount Great British Pounds intoo Euro's. This works however when I fill in a non-numeric character such as a letter it comes up with an error message. I would like to create an error message stating the filled in character is not valid when a non numeric character is filled intoo the field.

    Please excuse me for the Dutch methods. The if else statement error message states "The ammount is to high" when ever its greater as 1000 pounds.

    Any suggestions or tips are highly appriciated. You can find the code below.

    Kinds regards,

    Thomas


    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.text.DecimalFormat;
    
    public class Euro extends JFrame implements ActionListener {
    
    private JLabel valutaLabel; 
        private JTextField valutaField;
        private JButton button; 
        private JTextField euroTextField; 
        private final double euro = 1.18371; 
        
    
        public static void main(String[] args) {
            Euro omreken = new Euro(); 
            omreken.setSize(550,150); 
            omreken.createGUI(); 
            omreken.setVisible(true); 
        }
    
        private void createGUI() {
            setDefaultCloseOperation(EXIT_ON_CLOSE); 
            Container window = getContentPane();
            window.setLayout(new FlowLayout());
            setTitle("Valuta calculator"); 
    
            valutaLabel = new JLabel("Factuurbedrag in Britse Pond"); 
            window.add(valutaLabel); 
            valutaField = new JTextField(5);
            window.add(valutaField);         
            button = new JButton("Bereken");
            window.add(button); 
            button.addActionListener(this);        
            euroTextField = new JTextField(5);
            window.add(euroTextField);
        }
    
        public void actionPerformed(ActionEvent event) {
            String codeString; 
            int code;
    	double outcome;
            
            DecimalFormat format = new DecimalFormat("€####.##");
            codeString = valutaField.getText();
            code = Integer.parseInt(codeString);
            if (code > 1000) {
             JOptionPane.showMessageDialog(null, "Bedrag te hoog");   
            } else {
    	outcome = code / euro;
            euroTextField.setText(format.format(outcome));
               
        }
        }
    }
    Last edited by thover; 06-17-2013 at 07:14 PM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Java currency calculator error

    Moved from New to Java

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: Java currency calculator error

    In a word: JFormattedTextField.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    thover is offline Member
    Join Date
    Jun 2013
    Posts
    2
    Rep Power
    0

    Default Re: Java currency calculator error

    And where do I place this class?

Similar Threads

  1. Error in calculator program
    By Programmer3 in forum New To Java
    Replies: 3
    Last Post: 10-02-2012, 01:49 PM
  2. Calculator error?
    By RexBox in forum New To Java
    Replies: 5
    Last Post: 09-05-2012, 01:12 PM
  3. java currency
    By alfarida in forum New To Java
    Replies: 4
    Last Post: 05-23-2011, 02:11 PM
  4. [SOLVED] Simple Calculator Applet Weird Error
    By sari in forum New To Java
    Replies: 5
    Last Post: 01-28-2009, 05:57 AM
  5. Setting currency
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-16-2007, 03:08 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •