Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package makecalculator;
- import javax.swing.JFrame;
- import javax.swing.JButton;
- import java.awt.TextField;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- public class CALCULATOR extends JFrame
- {
- CALCULATOR()
- {
- /* Constructing Frame */
- JFrame frame = new JFrame();
- frame.setTitle("MY CALCULATOR");
- frame.setBounds(0, 0, 400, 400);
- frame.setVisible(true);
- frame.setLayout(null);
- frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
- /* Construction Text Fields */
- final TextField tf1 = new TextField();
- tf1.setBounds(50, 300, 250, 20);
- frame.add(tf1);
- final TextField tf2 = new TextField();
- tf2.setBounds(50, 200, 250, 20);
- frame.add(tf2);
- final TextField tf3 = new TextField();
- tf3.setBounds(50, 100, 250, 20);
- frame.add(tf3);
- /* Construction Text Fields - Adding TExt fields */
- /*Construction button*/
- JButton b1 = new JButton();
- b1.setLocation(50,50);
- b1.setSize(50,50);
- b1.setText("+");
- /*Construction button - Adding Actions*/
- b1.addActionListener
- (
- new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- String s1 = tf1.getText();
- String s2 = tf2.getText();
- int num1=Integer.parseInt(s1);
- int num2=Integer.parseInt(s2);
- int sum = num1+num2;
- tf3.setText(Integer.toString(sum));
- }
- }
- );
- /*Construction button - adding button b1*/
- frame.add(b1);
- }
- }
- public class MakeCalculator
- {
- public static void main(String[] args)
- {
- CALCULATOR c = new CALCULATOR();
- }
- }
Add Comment
Please, Sign In to add comment