Untitled
unknown
plain_text
2 years ago
6.6 kB
9
Indexable
import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JPanel; import java.awt.BorderLayout; import javax.swing.GroupLayout; import javax.swing.GroupLayout.Alignment; import java.awt.FlowLayout; import java.awt.CardLayout; import java.awt.Color; import javax.swing.JButton; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.JTextField; import java.awt.Font; import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.SwingConstants; import javax.swing.DefaultComboBoxModel; public class Currency1 { private JFrame frame; private JTextField txtamount; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { Currency1 window = new Currency1(); window.frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the application. */ public Currency1() { initialize(); } /** * Initialize the contents of the frame. */ private void initialize() { frame = new JFrame(); frame.setBounds(100, 100, 434, 367); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); panel.setToolTipText(""); panel.setBackground(new Color(240, 240, 240)); panel.setForeground(new Color(0, 0, 0)); frame.getContentPane().add(panel, BorderLayout.CENTER); panel.setLayout(null); JLabel lblNewLabel = new JLabel("FROM"); lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER); lblNewLabel.setForeground(new Color(0, 0, 0)); lblNewLabel.setFont(new Font("Trebuchet MS", Font.PLAIN, 12)); lblNewLabel.setBounds(63, 131, 96, 21); panel.add(lblNewLabel); JLabel lblNewLabel_1 = new JLabel("Enter the Amount"); lblNewLabel_1.setFont(new Font("Trebuchet MS", Font.PLAIN, 12)); lblNewLabel_1.setBounds(54, 47, 105, 21); panel.add(lblNewLabel_1); JLabel lblTo = new JLabel("TO"); lblTo.setHorizontalAlignment(SwingConstants.CENTER); lblTo.setForeground(Color.BLACK); lblTo.setFont(new Font("Trebuchet MS", Font.PLAIN, 12)); lblTo.setBounds(63, 204, 96, 21); panel.add(lblTo); JComboBox txtfrom = new JComboBox(); txtfrom.setModel(new DefaultComboBoxModel(new String[] {"USD","INR", "JPY","AED"})); txtfrom.setToolTipText(""); txtfrom.setBounds(219, 132, 96, 21); panel.add(txtfrom); JComboBox txtto = new JComboBox(); txtto.setModel(new DefaultComboBoxModel(new String[] {"USD","INR", "JPY","AED"})); txtto.setToolTipText(""); txtto.setBounds(219, 205, 96, 21); panel.add(txtto); JButton btnNewButton = new JButton("Convert"); btnNewButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Double tot; Double amount = Double.parseDouble(txtamount.getText()); if(txtfrom.getSelectedItem().toString() == "USD" && txtto.getSelectedItem().toString() == "INR") { tot = amount * 82.4; JOptionPane.showMessageDialog(null," Your Amoumt will be "+ tot.toString(), "Message",JOptionPane.INFORMATION_MESSAGE); } else if(txtfrom.getSelectedItem().toString() == "USD" && txtto.getSelectedItem().toString() == "JPY") { tot= amount *148.6; JOptionPane.showMessageDialog(null," Your Amoumt will be "+ tot.toString(), "Message",JOptionPane.INFORMATION_MESSAGE); } else if(txtfrom.getSelectedItem().toString() == "USD" && txtto.getSelectedItem().toString() == "AED") { tot = amount * 3.6; JOptionPane.showMessageDialog(null," Your Amoumt will be "+ tot.toString(), "Message",JOptionPane.INFORMATION_MESSAGE); } else if(txtfrom.getSelectedItem().toString() == "AED" && txtto.getSelectedItem().toString() == "INR") { tot = amount * 22.4; JOptionPane.showMessageDialog(null," Your Amoumt will be "+ tot.toString(), "Message",JOptionPane.INFORMATION_MESSAGE); } else if(txtfrom.getSelectedItem().toString() == "AED" && txtto.getSelectedItem().toString() == "USD") { tot = amount * 0.27; JOptionPane.showMessageDialog(null," Your Amoumt will be "+ tot.toString(), "Message",JOptionPane.INFORMATION_MESSAGE); } else if(txtfrom.getSelectedItem().toString() == "AED" && txtto.getSelectedItem().toString() == "JPY") { tot = amount * 40.46; JOptionPane.showMessageDialog(null," Your Amoumt will be "+ tot.toString(), "Message",JOptionPane.INFORMATION_MESSAGE); }else if(txtfrom.getSelectedItem().toString() == "JPY" && txtto.getSelectedItem().toString() == "INR") { tot = amount * 0.55; JOptionPane.showMessageDialog(null," Your Amoumt will be "+ tot.toString(), "Message",JOptionPane.INFORMATION_MESSAGE); }else if(txtfrom.getSelectedItem().toString() == "JPY" && txtto.getSelectedItem().toString() == "USD") { tot = amount * 0.0067; JOptionPane.showMessageDialog(null," Your Amoumt will be "+ tot.toString(), "Message",JOptionPane.INFORMATION_MESSAGE); }else if(txtfrom.getSelectedItem().toString() == "JPY" && txtto.getSelectedItem().toString() == "AED") { tot = amount * 0.0247; JOptionPane.showMessageDialog(null," Your Amoumt will be "+ tot.toString(), "Message",JOptionPane.INFORMATION_MESSAGE); }else if(txtfrom.getSelectedItem().toString() == "INR" && txtto.getSelectedItem().toString() == "JPY") { tot = amount * 1.80; JOptionPane.showMessageDialog(null," Your Amoumt will be "+ tot.toString(), "Message",JOptionPane.INFORMATION_MESSAGE); }else if(txtfrom.getSelectedItem().toString() == "INR" && txtto.getSelectedItem().toString() == "AED") { tot = amount * 0.04; JOptionPane.showMessageDialog(null," Your Amoumt will be "+ tot.toString(), "Message",JOptionPane.INFORMATION_MESSAGE); } else if(txtfrom.getSelectedItem().toString() == "INR" && txtto.getSelectedItem().toString() == "USD") { tot = amount * 0.0121; JOptionPane.showMessageDialog(null," Your Amoumt will be "+ tot.toString(), "Message",JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog(null," Select right the Option", "Message",JOptionPane.ERROR_MESSAGE); } } } ); btnNewButton.setFont(new Font("Tahoma", Font.PLAIN, 14)); btnNewButton.setBounds(157, 270, 85, 32); panel.add(btnNewButton); txtamount = new JTextField(); txtamount.setBounds(219, 49, 96, 19); panel.add(txtamount); txtamount.setColumns(10); } }
Editor is loading...