Advertisement
Guest User

Untitled

a guest
Jun 18th, 2013
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.02 KB | None | 0 0
  1. import java.awt.*;
  2. import javax.swing.*;
  3.  
  4. public class Main {
  5.  
  6.     public static void  main(String[] args){
  7.  
  8.         int width   = 300;
  9.         int height  = 200;
  10.  
  11. // Main frame
  12.         JFrame frame = new JFrame("Calculator");
  13.         frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  14.         frame.setMinimumSize(new Dimension(width, height));
  15.         frame.setResizable(false);
  16.         frame.setLocationRelativeTo(null);
  17.         frame.setVisible(true);
  18.  
  19. // Main panel
  20.         JPanel panel = new JPanel();
  21.         frame.add(panel);
  22.  
  23. // Box 1
  24.         Box box1;
  25.         box1 = Box.createHorizontalBox();
  26.         JLabel labelNumb1 = new JLabel("Number 1:");
  27.         JTextField textField1 = new JTextField(5);
  28.         textField1.setMinimumSize(textField1.getPreferredSize());
  29.  
  30.         JLabel labelNumb2 = new JLabel("Number 2:");
  31.         JTextField textField2 = new JTextField(5);
  32.         textField2.setMinimumSize(textField1.getPreferredSize());
  33.  
  34.         box1.add(Box.createHorizontalStrut(3));
  35.         box1.add(labelNumb1);
  36.         box1.add(Box.createHorizontalStrut(5));
  37.         box1.add(textField1);
  38.         box1.add(Box.createHorizontalStrut(15));
  39.         box1.add(labelNumb2);
  40.         box1.add(Box.createHorizontalStrut(5));
  41.         box1.add(textField2);
  42.  
  43. // Box 2
  44.         Box box2;
  45.         box2 = Box.createHorizontalBox();
  46.         JButton buttonPlus      = new JButton("plus");
  47.         JButton buttonMinus     = new JButton("minus");
  48.         JButton buttonMultiply  = new JButton("multiply");
  49.         JButton buttonDivide    = new JButton("divide");
  50.  
  51.         box2.add(buttonPlus);
  52.         box2.add(Box.createHorizontalStrut(2));
  53.         box2.add(buttonMinus);
  54.         box2.add(Box.createHorizontalStrut(2));
  55.         box2.add(buttonMultiply);
  56.         box2.add(Box.createHorizontalStrut(2));
  57.         box2.add(buttonDivide);
  58.  
  59. // Box 3
  60.         Box box3;
  61.         box3 = Box.createHorizontalBox();
  62.  
  63.         JLabel labelRes = new JLabel("Result:");
  64.         box3.add(labelRes);
  65.  
  66.         panel.add(box1);
  67.         panel.add(box2);
  68.         panel.add(box3);
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement