└── currency converter.txt /currency converter.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | import javax.swing.*; 4 | import java.awt.*; 5 | import java.awt.event.*; 6 | public class GFG { 7 | 8 | 9 | public static void converter() 10 | { 11 | 12 | 13 | JFrame f = new JFrame("CONVERTER"); 14 | 15 | 16 | JLabel l1, l2; 17 | 18 | 19 | JTextField t1, t2; 20 | 21 | 22 | JButton b1, b2, b3; 23 | 24 | // Naming the labels and setting 25 | // the bounds for the labels 26 | l1 = new JLabel("Rupees:"); 27 | l1.setBounds(20, 40, 60, 30); 28 | l2 = new JLabel("Dollars:"); 29 | l2.setBounds(170, 40, 60, 30); 30 | 31 | // Initializing the text fields with 32 | // 0 by default and setting the 33 | // bounds for the text fields 34 | t1 = new JTextField("0"); 35 | t1.setBounds(80, 40, 50, 30); 36 | t2 = new JTextField("0"); 37 | t2.setBounds(240, 40, 50, 30); 38 | 39 | // Creating a button for INR, 40 | // one button for the dollar 41 | // and one button to close 42 | // and setting the bounds 43 | b1 = new JButton("INR"); 44 | b1.setBounds(50, 80, 60, 15); 45 | b2 = new JButton("Dollar"); 46 | b2.setBounds(190, 80, 60, 15); 47 | b3 = new JButton("close"); 48 | b3.setBounds(150, 150, 60, 30); 49 | 50 | // Adding action listener 51 | b1.addActionListener(new ActionListener() { 52 | public void actionPerformed(ActionEvent e) 53 | { 54 | // Converting to double 55 | double d 56 | = Double.parseDouble(t1.getText()); 57 | 58 | // Converting rupees to dollars 59 | double d1 = (d / 65.25); 60 | 61 | // Getting the string value of the 62 | // calculated value 63 | String str1 = String.valueOf(d1); 64 | 65 | // Placing it in the text box 66 | t2.setText(str1); 67 | } 68 | }); 69 | 70 | 71 | b2.addActionListener(new ActionListener() { 72 | public void actionPerformed(ActionEvent e) 73 | { 74 | 75 | double d2 76 | = Double.parseDouble(t2.getText()); 77 | 78 | // converting Dollars to rupees 79 | double d3 = (d2 * 65.25); 80 | 81 | // Getting the string value of the 82 | // calculated value 83 | String str2 = String.valueOf(d3); 84 | 85 | // Placing it in the text box 86 | t1.setText(str2); 87 | } 88 | }); 89 | 90 | 91 | b3.addActionListener(new ActionListener() { 92 | public void actionPerformed(ActionEvent e) 93 | { 94 | f.dispose(); 95 | } 96 | }); 97 | 98 | 99 | f.addWindowListener(new WindowAdapter() { 100 | public void windowClosing(WindowEvent e) 101 | { 102 | System.exit(0); 103 | } 104 | }); 105 | 106 | // Adding the created objects 107 | // to the form 108 | f.add(l1); 109 | f.add(t1); 110 | f.add(l2); 111 | f.add(t2); 112 | f.add(b1); 113 | f.add(b2); 114 | f.add(b3); 115 | 116 | f.setLayout(null); 117 | f.setSize(400, 300); 118 | f.setVisible(true); 119 | } 120 | 121 | // Driver code 122 | public static void main(String args[]) 123 | { 124 | converter(); 125 | } 126 | } 127 | 128 | --------------------------------------------------------------------------------