Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.FlowLayout;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.JButton;
- import javax.swing.JComponent;
- import javax.swing.JTextField;
- import java.awt.event.ActionEvent;
- import javax.swing.SwingUtilities;
- import java.awt.event.ActionListener;
- /**
- *
- * @author toffe boy Aamir
- */
- public class CurrencyExchange extends JPanel implements ActionListener{
- public JButton change;
- public JTextField ind,usa;
- CurrencyExchange(){
- super(new FlowLayout());
- ind = new JTextField(20);
- ind.setText("250");
- usa = new JTextField(20);
- usa.setEditable(false);
- change = new JButton("Convert");
- add(ind);add(change);add(usa);
- change.addActionListener(this);
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- final double USD = 0.0148993;
- final double INR = Double.parseDouble(ind.getText());
- //1 INR = 0.0148993 USD (24/08/2016)
- // check the current status http://www.xe.com/currencyconverter/convert/?Amount=1&From=INR&To=USD
- usa.setText(Double.toString(INR*USD) +" USD");
- }
- public static void main(String[] args) {
- SwingUtilities.invokeLater(new Runnable() {
- @Override
- public void run() {
- CurrencyExchange.showGUI();
- }
- });
- }
- private static void showGUI() {
- JFrame gui = new JFrame("INR to USD");
- gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- JComponent newContentPane = new CurrencyExchange();
- newContentPane.setOpaque(true);
- gui.setContentPane(newContentPane);
- gui.setResizable(false);
- gui.setVisible(true);
- gui.pack();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment