iamaamir

INR to USD Converter

Aug 19th, 2014
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.80 KB | None | 0 0
  1. import java.awt.FlowLayout;
  2. import javax.swing.JFrame;
  3. import javax.swing.JPanel;
  4. import javax.swing.JButton;
  5. import javax.swing.JComponent;
  6. import javax.swing.JTextField;
  7. import java.awt.event.ActionEvent;
  8. import javax.swing.SwingUtilities;
  9. import java.awt.event.ActionListener;
  10.  
  11. /**
  12.  *
  13.  * @author toffe boy Aamir
  14.  */
  15. public class CurrencyExchange extends JPanel implements ActionListener{
  16.     public JButton change;
  17.     public JTextField ind,usa;
  18.     CurrencyExchange(){
  19.         super(new FlowLayout());
  20.         ind = new JTextField(20);
  21.         ind.setText("250");
  22.         usa = new JTextField(20);
  23.         usa.setEditable(false);
  24.         change = new JButton("Convert");
  25.         add(ind);add(change);add(usa);
  26.         change.addActionListener(this);
  27.        
  28.     }
  29.  
  30.     @Override
  31.     public void actionPerformed(ActionEvent e) {
  32.        
  33.         final double USD = 0.0148993;
  34.         final double INR = Double.parseDouble(ind.getText());
  35.         //1 INR = 0.0148993 USD (24/08/2016)
  36.         // check the current status http://www.xe.com/currencyconverter/convert/?Amount=1&From=INR&To=USD
  37.         usa.setText(Double.toString(INR*USD) +" USD");
  38.        
  39.     }
  40.    
  41.    
  42.     public static void main(String[] args) {
  43.         SwingUtilities.invokeLater(new Runnable() {
  44.             @Override
  45.             public void run() {
  46.                 CurrencyExchange.showGUI();
  47.             }
  48.         });
  49.     }
  50.    
  51.    
  52.     private static void showGUI() {
  53.         JFrame gui = new JFrame("INR to USD");
  54.         gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  55.         JComponent newContentPane = new CurrencyExchange();
  56.         newContentPane.setOpaque(true);
  57.         gui.setContentPane(newContentPane);
  58.         gui.setResizable(false);
  59.         gui.setVisible(true);
  60.         gui.pack();
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment