Untitled
Rohit143
plain_text
2 years ago
5.2 kB
7
Indexable
import java.awt.*; import java.awt.event.*; import javax.swing.*; /* <applet code="CurrencyConverter" width=400 height=400> </applet> */ public class CurrencyConverter extends JApplet implements ActionListener { JTextField t1,t2; JButton b1,b2; JComboBox c1,c2; String[] currency={"US Dollar","Indian Rupee","British Pound","Euro","Canadian Dollar","Emirati Dirham","Chinese Yaun"}; public void init() { GridBagLayout gbag=new GridBagLayout(); GridBagConstraints gbc=new GridBagConstraints(); setLayout(gbag); c1=new JComboBox(currency); c1.setSelectedIndex(0); c2=new JComboBox(currency); c2.setSelectedIndex(1); t1=new JTextField(10); t2=new JTextField(15); b1=new JButton("Convert"); b2=new JButton("Clear"); JLabel h=new JLabel("Currency Converter"); JLabel l1=new JLabel("Select the Input Currency:"); JLabel l2=new JLabel("Enter the amount: "); JLabel l3=new JLabel("Select the Output Currency:"); JLabel l4=new JLabel("Converted amount: "); gbc.weighty=1.0; gbc.gridwidth=GridBagConstraints.REMAINDER; gbc.anchor=GridBagConstraints.NORTH; gbag.setConstraints(h, gbc); gbc.anchor=GridBagConstraints.EAST; gbc.gridwidth=GridBagConstraints.RELATIVE; gbag.setConstraints(l1, gbc); gbc.gridwidth=GridBagConstraints.REMAINDER; gbag.setConstraints(c1, gbc); gbc.gridwidth=GridBagConstraints.RELATIVE; gbag.setConstraints(l2, gbc); gbc.gridwidth=GridBagConstraints.REMAINDER; gbag.setConstraints(t1, gbc); gbc.gridwidth=GridBagConstraints.RELATIVE; gbag.setConstraints(l3, gbc); gbc.gridwidth=GridBagConstraints.REMAINDER; gbag.setConstraints(c2, gbc); gbc.gridwidth=GridBagConstraints.RELATIVE; gbag.setConstraints(l4, gbc); gbc.gridwidth=GridBagConstraints.REMAINDER; gbag.setConstraints(t2, gbc); gbc.anchor=GridBagConstraints.CENTER; gbag.setConstraints(b1, gbc); gbc.gridwidth=GridBagConstraints.CENTER; gbag.setConstraints(b2, gbc); add(h); add(l1); add(c1); add(l2); add(t1); add(l3); add(c2); add(b1); add(l4); add(t2); add(b2); t1.addActionListener(this); t2.addActionListener(this); b1.addActionListener(this); b2.addActionListener(this); c1.addActionListener(this); c2.addActionListener(this); } public void actionPerformed(ActionEvent ae) { double a,c=0; a=Double.valueOf(t1.getText()); try { if(c1.getSelectedIndex()==0 & c2.getSelectedIndex()==1) c= a*76.06; if(c1.getSelectedIndex()==0 & c2.getSelectedIndex()==2) c= a*0.76; if(c1.getSelectedIndex()==0 & c2.getSelectedIndex()==3) c= a*0.89; if(c1.getSelectedIndex()==0 & c2.getSelectedIndex()==4) c= a*1.29; if(c1.getSelectedIndex()==0 & c2.getSelectedIndex()==5) c= a*3.67; if(c1.getSelectedIndex()==0 & c2.getSelectedIndex()==6) c= a*6.37; if(c1.getSelectedIndex()==1 & c2.getSelectedIndex()==0) c= a*0.0131475; if(c1.getSelectedIndex()==1 & c2.getSelectedIndex()==2) c= a*0.0099; if(c1.getSelectedIndex()==1 & c2.getSelectedIndex()==3) c= a*0.012; if(c1.getSelectedIndex()==1 & c2.getSelectedIndex()==4) c= a*0.017; if(c1.getSelectedIndex()==1 & c2.getSelectedIndex()==5) c= a*0.048; if(c1.getSelectedIndex()==1 & c2.getSelectedIndex()==6) c= a*0.084; if(c1.getSelectedIndex()==2 & c2.getSelectedIndex()==0) c= a*1.32; if(c1.getSelectedIndex()==2 & c2.getSelectedIndex()==1) c= a*100.71; if(c1.getSelectedIndex()==2 & c2.getSelectedIndex()==3) c= a*1.17; if(c1.getSelectedIndex()==2 & c2.getSelectedIndex()==4) c= a*1.70; if(c1.getSelectedIndex()==2 & c2.getSelectedIndex()==5) c= a*4.86; if(c1.getSelectedIndex()==2 & c2.getSelectedIndex()==6) c= a*8.43; if(c1.getSelectedIndex()==3 & c2.getSelectedIndex()==0) c= a*1.13; if(c1.getSelectedIndex()==3 & c2.getSelectedIndex()==1) c= a*85.73; if(c1.getSelectedIndex()==3 & c2.getSelectedIndex()==2) c= a*0.85; if(c1.getSelectedIndex()==3 & c2.getSelectedIndex()==4) c= a*1.45; if(c1.getSelectedIndex()==3 & c2.getSelectedIndex()==5) c= a*4.14; if(c1.getSelectedIndex()==3 & c2.getSelectedIndex()==6) c= a*7.17; if(c1.getSelectedIndex()==4 & c2.getSelectedIndex()==0) c= a*0.78; if(c1.getSelectedIndex()==4 & c2.getSelectedIndex()==1) c= a*59.19; if(c1.getSelectedIndex()==4 & c2.getSelectedIndex()==2) c= a*0.59; if(c1.getSelectedIndex()==4 & c2.getSelectedIndex()==3) c= a*0.69; if(c1.getSelectedIndex()==4 & c2.getSelectedIndex()==5) c= a*2.86; if(c1.getSelectedIndex()==4 & c2.getSelectedIndex()==6) c= a*4.95; if(c1.getSelectedIndex()==5 & c2.getSelectedIndex()==0) c= a*0.27; if(c1.getSelectedIndex()==5 & c2.getSelectedIndex()==1) c= a*20.71; if(c1.getSelectedIndex()==5 & c2.getSelectedIndex()==2) c= a*0.21; if(c1.getSelectedIndex()==5 & c2.getSelectedIndex()==3) c= a*0.24; if(c1.getSelectedIndex()==5 & c2.getSelectedIndex()==4) c= a*0.35; if(c1.getSelectedIndex()==5 & c2.getSelectedIndex()==6) c= a*1.73; if(c1.getSelectedIndex()==6 & c2.getSelectedIndex()==0) c= a*0.16; if(c1.getSelectedIndex()==6 & c2.getSelectedIndex()==1) c= a*11.95; if(c1.getSelectedIndex()==6 & c2.getSelectedIndex()==2) c= a*0.12; if(c1.getSelectedIndex()==6 & c2.getSelectedIndex()==3) c= a*0.14; if(c1.getSelectedIndex()==6 & c2.getSelectedIndex()==4) c= a*0.20; if(c1.getSelectedIndex()==6 & c2.getSelectedIndex()==5) c= a*0.58; t2.setText(String.valueOf(c)); } catch(Exception x) { System.out.println("Error"); } if(ae.getSource()==b2) { t1.setText("0000"); t2.setText("0000"); } } } Outpu
Editor is loading...