Jump to content

currency converter using swing along with database connectivity,help me out!

- - - - -

  • Please log in to reply
1 reply to this topic

#1
keerthika

keerthika

    Newbie

  • Members
  • Pip
  • 1 posts
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class cc extends JApplet implements ActionListener
  {

   // applet title   
String str;
   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 lbleuro = new JLabel("EURO");
   JLabel lblyen = new JLabel("YEN");
   JLabel lblcdollar = new JLabel("CANADA DOLLAR");
   JLabel lbladollar = new JLabel("AUSTRALIAN DOLLAR");
   JLabel lblukd= new JLabel("UKDOLLAR");
   JLabel lblusd= new JLabel("USDOLLAR");
   JLabel lblrr= new JLabel("RUSSIAN RUBLE");
   JLabel lblnzd= new JLabel("NEWZEALAND DOLLAR");
   JLabel lblzd= new JLabel("ZIMBABWE DOLLAR");

   // Labels to display value of currency converted
 
   JLabel lbleuroamount = new JLabel("0");
   JLabel lblyenamount = new JLabel("0");
  JLabel lblcdollaramount = new JLabel("0");
  JLabel lbladollaramount = new JLabel("0");
   JLabel lblukdamount = new JLabel("0");
   JLabel lblusdamount= new JLabel("0");
   JLabel lblrramount= new JLabel("0");
   JLabel lblnzdamount= new JLabel("0");
   JLabel lblzdamount= 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.pink);
  

  // (input)
  content.add(lblinput);
  content.add(txtinput);
  txtinput.setText("0");
  

  
content.add(lbleuro);
  content.add(lbleuroamount);  

  content.add(lblyen); 
   content.add(lblyenamount);

content.add(lblcdollar);
  content.add(lblcdollaramount);

  content.add(lbladollar );  
content.add(lbladollaramount);

  content.add(lblukd);
  content.add(lblukdamount);

  content.add(lblusd);
  content.add(lblusdamount);

  content.add(lblrr);
  content.add(lblrramount);

  content.add(lblnzd);
  content.add(lblnzdamount);

  content.add(lblzd);
  content.add(lblzdamount);

  content.add(btnclear);
  content.add(btnconvert);

   }
   





 public void actionPerformed(ActionEvent event)
     {   
/*try
{

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con=DriverManager.getConnection("jdbc:odbc:converter","scott","tiger");
    Statement stmt=con.createStatement();
//String str ="select *from emp";
    //if(str.equals(""))
    ResultSet rs=stmt.executeQuery("select * from EMP");
    while(rs.next())
    {
        System.out.println(rs.getString("name"));
        System.out.println(rs.getString(1));

    }
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
*/
       if(event.getSource()==btnclear)
         {txtinput.setText("0");   
          lbleuroamount .setText("0");
lblyenamount.setText("0");
lblcdollaramount.setText("0");
lbladollaramount .setText("0");
lblukdamount .setText("0");
lblusdamount.setText("0");
lblrramount.setText("0");
lblnzdamount.setText("0");
lblzdamount.setText("0");
}
          
          if(event.getSource()==btnconvert)
         {  
double k;
k=Double.valueOf(txtinput.getText()).doubleValue(); 
Double euro=k*0.2;
Double yen=k*0.4;
Double cdollar=k*0.6;
Double adollar=k*0.8;
Double ukd=k*0.10;
Double usd=k*0.12;
Double rr=k*0.14;
Double nzd=k*0.16;
Double zd=k*0.16;





lbleuroamount .setText(""+euro);
lblyenamount.setText(""+yen);
lblcdollaramount.setText(""+cdollar);
lbladollaramount .setText(""+adollar);
lblukdamount .setText(""+ukd);
lblusdamount.setText(""+usd);
lblrramount.setText(""+rr);
lblnzdamount.setText(""+nzd);
lblzdamount.setText(""+zd);

}
          
        }
    }

Edited by Alexander, 13 November 2010 - 02:57 AM.
(code tags, unfortunately formatting was lost)


#2
eafkuor

eafkuor

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 218 posts
You want us to complete your code? If you want help, ask a precise question about something you are not able to do on your own rather than post an entire Java class asking us to correct it.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users