votako

calc

Mar 1st, 2013
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.90 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3.  
  4. public class Calculator{
  5.     JPanel windowContent;
  6.  
  7.     JFormattedTextField displayFormattedField;
  8.  
  9.     JButton[] button = new JButton[10];
  10.  
  11.     JButton buttonPoint;
  12.     JButton buttonEqual;
  13.     JButton buttonPlus;
  14.     JButton buttonMinus;
  15.     JButton buttonDelenie;
  16.     JButton buttonUmnojenie;
  17.     JPanel p2;
  18.     JPanel p1;
  19.     Calculator(){
  20.         windowContent = new JPanel();
  21.  
  22.         BorderLayout bl = new BorderLayout();
  23.         windowContent.setLayout(bl);
  24.  
  25.         displayFormattedField = new JFormattedTextField();
  26.         displayFormattedField.setHorizontalAlignment(SwingConstants.RIGHT);
  27.         windowContent.add("North", displayFormattedField);
  28.  
  29.         for (int i=0; i<10; i++) {
  30.             button[i] = new JButton(""+i);
  31.            
  32.         }
  33.  
  34.         buttonPoint = new JButton(".");
  35.         buttonEqual = new JButton("=");
  36.         buttonDelenie = new JButton("/");
  37.         buttonMinus = new JButton("-");
  38.         buttonUmnojenie = new JButton("*");
  39.         buttonPlus = new JButton("+");
  40.  
  41.         p1 = new JPanel();
  42.         GridLayout gl = new GridLayout(4,3);
  43.         p1.setLayout(gl);
  44.  
  45.         for (int i=0; i<10; i++) {
  46.             p1.add(button[i]);
  47.         }
  48.         p1.add(button[0]);
  49.  
  50.         p1.add(buttonPoint);
  51.         p1.add(buttonEqual);
  52.  
  53.         p2 = new JPanel();
  54.         GridLayout gl2 = new GridLayout(4,1);
  55.         p2.setLayout(gl2);
  56.  
  57.         p2.add(buttonPlus);
  58.         p2.add(buttonMinus);
  59.         p2.add(buttonUmnojenie);
  60.         p2.add(buttonDelenie);
  61.        
  62.         windowContent.add("Center",p1);
  63.         windowContent.add("East", p2);
  64.  
  65.         JFrame frame = new JFrame("Calculator");
  66.         frame.setContentPane(windowContent);
  67.  
  68.         frame.pack();
  69.  
  70.         frame.setVisible(true);
  71.     }
  72.     public static void main(String[] args) {
  73.         Calculator calc = new Calculator();
  74.     }
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment