Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- public class Calculator{
- JPanel windowContent;
- JFormattedTextField displayFormattedField;
- JButton[] button = new JButton[10];
- JButton buttonPoint;
- JButton buttonEqual;
- JButton buttonPlus;
- JButton buttonMinus;
- JButton buttonDelenie;
- JButton buttonUmnojenie;
- JPanel p2;
- JPanel p1;
- Calculator(){
- windowContent = new JPanel();
- BorderLayout bl = new BorderLayout();
- windowContent.setLayout(bl);
- displayFormattedField = new JFormattedTextField();
- displayFormattedField.setHorizontalAlignment(SwingConstants.RIGHT);
- windowContent.add("North", displayFormattedField);
- for (int i=0; i<10; i++) {
- button[i] = new JButton(""+i);
- }
- buttonPoint = new JButton(".");
- buttonEqual = new JButton("=");
- buttonDelenie = new JButton("/");
- buttonMinus = new JButton("-");
- buttonUmnojenie = new JButton("*");
- buttonPlus = new JButton("+");
- p1 = new JPanel();
- GridLayout gl = new GridLayout(4,3);
- p1.setLayout(gl);
- for (int i=0; i<10; i++) {
- p1.add(button[i]);
- }
- p1.add(button[0]);
- p1.add(buttonPoint);
- p1.add(buttonEqual);
- p2 = new JPanel();
- GridLayout gl2 = new GridLayout(4,1);
- p2.setLayout(gl2);
- p2.add(buttonPlus);
- p2.add(buttonMinus);
- p2.add(buttonUmnojenie);
- p2.add(buttonDelenie);
- windowContent.add("Center",p1);
- windowContent.add("East", p2);
- JFrame frame = new JFrame("Calculator");
- frame.setContentPane(windowContent);
- frame.pack();
- frame.setVisible(true);
- }
- public static void main(String[] args) {
- Calculator calc = new Calculator();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment