Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import javax.swing.*;
- public class Main {
- public static void main(String[] args){
- int width = 300;
- int height = 200;
- // Main frame
- JFrame frame = new JFrame("Calculator");
- frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
- frame.setMinimumSize(new Dimension(width, height));
- frame.setResizable(false);
- frame.setLocationRelativeTo(null);
- frame.setVisible(true);
- // Main panel
- JPanel panel = new JPanel();
- frame.add(panel);
- // Box 1
- Box box1;
- box1 = Box.createHorizontalBox();
- JLabel labelNumb1 = new JLabel("Number 1:");
- JTextField textField1 = new JTextField(5);
- textField1.setMinimumSize(textField1.getPreferredSize());
- JLabel labelNumb2 = new JLabel("Number 2:");
- JTextField textField2 = new JTextField(5);
- textField2.setMinimumSize(textField1.getPreferredSize());
- box1.add(Box.createHorizontalStrut(3));
- box1.add(labelNumb1);
- box1.add(Box.createHorizontalStrut(5));
- box1.add(textField1);
- box1.add(Box.createHorizontalStrut(15));
- box1.add(labelNumb2);
- box1.add(Box.createHorizontalStrut(5));
- box1.add(textField2);
- // Box 2
- Box box2;
- box2 = Box.createHorizontalBox();
- JButton buttonPlus = new JButton("plus");
- JButton buttonMinus = new JButton("minus");
- JButton buttonMultiply = new JButton("multiply");
- JButton buttonDivide = new JButton("divide");
- box2.add(buttonPlus);
- box2.add(Box.createHorizontalStrut(2));
- box2.add(buttonMinus);
- box2.add(Box.createHorizontalStrut(2));
- box2.add(buttonMultiply);
- box2.add(Box.createHorizontalStrut(2));
- box2.add(buttonDivide);
- // Box 3
- Box box3;
- box3 = Box.createHorizontalBox();
- JLabel labelRes = new JLabel("Result:");
- box3.add(labelRes);
- panel.add(box1);
- panel.add(box2);
- panel.add(box3);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement