Advertisement
Guest User

Untitled

a guest
Oct 12th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. public PGM_1_3_Panel() {
  2. // Set BorderLayout for this panel
  3. setLayout(new BorderLayout());
  4. // Instantiate Dimensions of border layout areas
  5. Dimension north = new Dimension(110, 50);
  6. Dimension south = new Dimension(110, 50);
  7. Dimension east = new Dimension(50, 50);
  8. Dimension west = new Dimension(50, 50);
  9. Dimension center = new Dimension(150, 200);
  10. // north and south: 110 x 50; east and west: 50 x 50; center: 150, 200
  11. // Instantiate JLabels for north, south, east and west border areas
  12. JLabel JNorth = new JLabel("My Keypad");
  13. JLabel JSouth = new JLabel("Press Any Button...");
  14. JLabel JEast = new JLabel("");
  15. JLabel JWest = new JLabel("");
  16.  
  17.  
  18.  
  19. // Add and center text to north and south JLabels
  20. JLabel text1 = new JLabel("My Keypad");
  21. JLabel text2 = new JLabel("Press Any Button...");
  22. JNorth.add(text1);
  23. JSouth.add(text2);
  24.  
  25.  
  26. // Set the preferred size of the north, south, east, and west JLabels
  27. JNorth.setPreferredSize(north);
  28. JSouth.setPreferredSize(south);
  29. JEast.setPreferredSize(east);
  30. JWest.setPreferredSize(west);
  31. // Instantiate and set north JLabel font to Lucida Console, bold, 20 point
  32. JNorth.setFont(new Font("Lucida Console", Font.BOLD, 20));
  33. // Instantiate and set south JLabel font to Lucida Console, bold, 12 point
  34. JSouth.setFont(new Font("Lucida Console", Font.BOLD, 12));
  35. // Instantiate the keypad JPanel and set the panel layout to a GridLayout of 4 rows by 3 columns
  36. JPanel keypad = new JPanel();
  37. keypad.setLayout(new GridLayout(4, 3));
  38.  
  39. one = new KeypadButton("1");
  40. two = new KeypadButton("2");
  41. three = new KeypadButton("3");
  42. four = new KeypadButton("4");
  43. five = new KeypadButton("5");
  44. six = new KeypadButton("6");
  45. seven = new KeypadButton("7");
  46. eight = new KeypadButton("8");
  47. nine = new KeypadButton("9");
  48. zero = new KeypadButton("0");
  49. star = new KeypadButton("*");
  50. hash = new KeypadButton("#");
  51. // Add keypad JButtons to the keypad JPanel
  52. keypad.add(one);
  53. keypad.add(two);
  54. keypad.add(three);
  55. keypad.add(four);
  56. keypad.add(five);
  57. keypad.add(six);
  58. keypad.add(seven);
  59. keypad.add(eight);
  60. keypad.add(nine);
  61. keypad.add(star);
  62. keypad.add(zero);
  63. keypad.add(hash);
  64.  
  65. add(keypad, BorderLayout.CENTER);
  66. add(JNorth, BorderLayout.NORTH);
  67. add(JSouth, BorderLayout.SOUTH);
  68. add(JWest, BorderLayout.WEST);
  69. add(JEast, BorderLayout.EAST);
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement