Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Chapter_5;
- import javax.swing.*;
- import java.awt.BorderLayout;
- import java.awt.GridLayout;
- public class TestCalc {
- /**
- * @param args
- */
- // public static void main(String[] args) {
- // TODO Auto-generated method stub
- JPanel windowContent;
- JTextField displayField;
- JButton button0;
- JButton button1;
- JButton button2;
- JButton button3;
- JButton button4;
- JButton button5;
- JButton button6;
- JButton button7;
- JButton button8;
- JButton button9;
- JButton buttonPoint;
- JButton buttonEqual;
- JButton buttonPlus;
- JButton buttonMinus;
- JButton buttonTimes;
- JButton buttonDivide;
- JPanel pl;
- TestCalc() {
- windowContent = new JPanel();
- BorderLayout bl = new BorderLayout();
- windowContent.setLayout(bl);
- displayField = new JTextField(30);
- windowContent.add("North", displayField);
- button0 = new JButton("0");
- button1 = new JButton("1");
- button2 = new JButton("2");
- button3 = new JButton("3");
- button4 = new JButton("4");
- button5 = new JButton("5");
- button6 = new JButton("6");
- button7 = new JButton("7");
- button8 = new JButton("8");
- button9 = new JButton("9");
- buttonPoint = new JButton(".");
- buttonEqual = new JButton("=");
- buttonPlus = new JButton("+");
- buttonMinus = new JButton("-");
- buttonTimes = new JButton("x");
- buttonDivide = new JButton("/");
- JPanel pl = new JPanel();
- GridLayout gl = new GridLayout(4, 4);
- pl.setLayout(gl);
- pl.add(button1);
- pl.add(button2);
- pl.add(button3);
- pl.add(buttonPlus);
- pl.add(button4);
- pl.add(button5);
- pl.add(button6);
- pl.add(buttonMinus);
- pl.add(button7);
- pl.add(button8);
- pl.add(button9);
- pl.add(buttonTimes);
- pl.add(button0);
- pl.add(buttonPoint);
- pl.add(buttonEqual);
- pl.add(buttonDivide);
- windowContent.add("Center", pl);
- JFrame frame = new JFrame("Calculator");
- frame.setContentPane(windowContent);
- frame.pack();
- frame.setVisible(true);
- }
- public static void main(String[] args) {
- TestCalc calc = new TestCalc();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement