Results 1 to 4 of 4
  1. #1
    MarkL410 is offline Member
    Join Date
    Jun 2010
    Posts
    3
    Rep Power
    0

    Default Currency Converter Applet Help...

    Hello there, I am in the process of creating a currency converter applet. I have the layout done and the applet runs in my web browser but I am having trouble coding the calculation for the converter. Could somebody point me in the right direction please, here is my code...

    Java Code:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    
    public class CurrencyConverter extends JApplet implements ActionListener
      {
       // applet title   
       JLabel lblTitle = new JLabel ("Currency Converter Applet");
       
       // label for promt input + input box
       JLabel lblinput = new JLabel("Enter a Value GBP");
       JTextField txtinput = new JTextField(10);
    
       
      
       // Labels to display name of currency converter
       JLabel lbldollar = new JLabel("US Dollars = ");  
       JLabel lbleuro = new JLabel("Euro = ");
       JLabel lblyen = new JLabel("Yen = ");
       JLabel lblpound = new JLabel("GBP = ");
    
       // Labels to display value of currency converted
       JLabel lbldollaramount = new JLabel("0");
       JLabel lbleuroamount = new JLabel("0");
       JLabel lblyenamount = new JLabel("0");
       JLabel lblpoundamount = new JLabel("0");
       
       // button convert + clear
       JButton btnconvert = new JButton ("Convert");
       JButton btnclear = new JButton ("Clear");
         
    public void init()
    {
            // this is a workaround for a security conflict with some browsers
            // including some versions of Netscape & Internet Explorer which do 
            // not allow access to the AWT system event queue which JApplets do 
            // on startup to check access. May not be necessary with your browser. 
            JRootPane rootPane = this.getRootPane();    
            rootPane.putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE);
        
            // provide any initialisation necessary for your JApplet
    }
    
      public void start()
        {
            // provide any code required to run each time 
            // web page is visited 
            display(); 
        }
        
    public void display()
    {  
      /**
       * set font size and colour of labels
      */
      // lblinput
      lblinput.setFont(new Font("Algerian", Font.BOLD, 18));
      lblinput.setForeground(Color.black);
      
      txtinput.setFont(new Font("Algerian", Font.BOLD, 18));
      txtinput.setForeground(Color.black);
      
      //dollar
      lbldollar.setFont(new Font("Algerian", Font.BOLD, 18));
      lbldollar.setForeground(Color.black);
      
      lbldollaramount.setFont(new Font("Algerian", Font.BOLD, 18));
      lbldollaramount.setForeground(Color.black);
      
      //euro
      lbleuro.setFont(new Font("Algerian", Font.BOLD, 18));
      lbleuro.setForeground(Color.black);
      
      lbleuroamount.setFont(new Font("Algerian", Font.BOLD, 18));
      lbleuroamount.setForeground(Color.black);
      
      //yen
      lblyen.setFont(new Font("Algerian", Font.BOLD, 18));
      lblyen.setForeground(Color.black);
      
      lblyenamount.setFont(new Font("Algerian", Font.BOLD, 18));
      lblyenamount.setForeground(Color.black);
      
      //gbp
      lblpound.setFont(new Font("Algerian", Font.BOLD, 18));
      lblpound.setForeground(Color.black);
      
      lblpoundamount.setFont(new Font("Algerian", Font.BOLD, 18));
      lblpoundamount.setForeground(Color.black);
      
      //buttons font, size, colour  and attach action listener
      
      btnconvert.setFont(new Font("Algerian", Font.BOLD, 18));
      btnconvert.setForeground(Color.black);
      btnconvert.addActionListener(this);
      
      btnclear.setFont(new Font("Algerian", Font.BOLD, 18));
      btnclear.setForeground(Color.black);
      btnclear.addActionListener(this);
       
      /**
       * add items to main panel
       */
    
       Container content = getContentPane();
      // set layout
      content.setLayout(new GridLayout(6,2));
      // set colour
      content.setBackground(Color.red);
      
      // (input)
      content.add(lblinput);
      content.add(txtinput);
      txtinput.setText("0");
      
      // (dollar)
      content.add(lbldollar);
      content.add(lbldollaramount);
      
      //(euro)
      content.add(lbleuro);
      content.add(lbleuroamount);
      
      //(yen)
      content.add(lblyen);
      content.add(lblyenamount);
     
      //(pound)
      content.add(lblpound);
      content.add(lblpoundamount);
      
      content.add(btnclear);
      content.add(btnconvert);
    
       }
       
         public void actionPerformed(ActionEvent event)
         {   
           if(event.getSource()==btnclear)
             {txtinput.setText("0");   
              lbldollaramount.setText("0");
              lbleuroamount.setText("0");
              lblyenamount.setText("0");
              lblpoundamount.setText("0");}
              
              if(event.getSource()==btnconvert)
             {txtinput.setText("1");   
              lbldollaramount.setText("1");
              lbleuroamount.setText("1");
              lblyenamount.setText("1");
              lblpoundamount.setText("1");}
              
            }
        }
    Thanks in advance.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

    Default

    Rather looks like this thread will go the same way as the OP's earlier thread
    Java Slideshow in BlueJ...Help!

    db

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Currency Converter!!!!
    By Pascal Nouma in forum AWT / Swing
    Replies: 2
    Last Post: 04-02-2009, 07:23 AM
  2. Formatting a number to currency
    By Java Tip in forum java.text
    Replies: 0
    Last Post: 04-16-2008, 10:59 PM
  3. Setting currency
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-16-2007, 02:08 PM

Posting Permissions

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