Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. package Chapter_5;
  2.  
  3. import javax.swing.*;
  4. import java.awt.BorderLayout;
  5. import java.awt.GridLayout;
  6.  
  7. public class TestCalc {
  8. /**
  9. * @param args
  10. */
  11. // public static void main(String[] args) {
  12. // TODO Auto-generated method stub
  13. JPanel windowContent;
  14. JTextField displayField;
  15. JButton button0;
  16. JButton button1;
  17. JButton button2;
  18. JButton button3;
  19. JButton button4;
  20. JButton button5;
  21. JButton button6;
  22. JButton button7;
  23. JButton button8;
  24. JButton button9;
  25. JButton buttonPoint;
  26. JButton buttonEqual;
  27. JButton buttonPlus;
  28. JButton buttonMinus;
  29. JButton buttonTimes;
  30. JButton buttonDivide;
  31. JPanel pl;
  32.  
  33. TestCalc() {
  34. windowContent = new JPanel();
  35. BorderLayout bl = new BorderLayout();
  36. windowContent.setLayout(bl);
  37. displayField = new JTextField(30);
  38. windowContent.add("North", displayField);
  39. button0 = new JButton("0");
  40. button1 = new JButton("1");
  41. button2 = new JButton("2");
  42. button3 = new JButton("3");
  43. button4 = new JButton("4");
  44. button5 = new JButton("5");
  45. button6 = new JButton("6");
  46. button7 = new JButton("7");
  47. button8 = new JButton("8");
  48. button9 = new JButton("9");
  49. buttonPoint = new JButton(".");
  50. buttonEqual = new JButton("=");
  51. buttonPlus = new JButton("+");
  52. buttonMinus = new JButton("-");
  53. buttonTimes = new JButton("x");
  54. buttonDivide = new JButton("/");
  55. JPanel pl = new JPanel();
  56. GridLayout gl = new GridLayout(4, 4);
  57. pl.setLayout(gl);
  58. pl.add(button1);
  59. pl.add(button2);
  60. pl.add(button3);
  61. pl.add(buttonPlus);
  62. pl.add(button4);
  63. pl.add(button5);
  64. pl.add(button6);
  65. pl.add(buttonMinus);
  66. pl.add(button7);
  67. pl.add(button8);
  68. pl.add(button9);
  69. pl.add(buttonTimes);
  70. pl.add(button0);
  71. pl.add(buttonPoint);
  72. pl.add(buttonEqual);
  73. pl.add(buttonDivide);
  74. windowContent.add("Center", pl);
  75. JFrame frame = new JFrame("Calculator");
  76. frame.setContentPane(windowContent);
  77. frame.pack();
  78. frame.setVisible(true);
  79. }
  80.  
  81. public static void main(String[] args) {
  82. TestCalc calc = new TestCalc();
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement