Advertisement
Guest User

GridWindow

a guest
Jul 20th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. import javax.swing.*; // Needed for Swing classes
  2. import java.awt.*; // Needed for GridLayout class
  3.  
  4. /**
  5. This class demonstrates the GridLayout manager.
  6. */
  7.  
  8. public class GridWindow extends JFrame
  9. {
  10. private final int WINDOW_WIDTH = 400; // Window width
  11. private final int WINDOW_HEIGHT = 200; // Window height
  12.  
  13. /**
  14. Constructor
  15. */
  16.  
  17. public GridWindow()
  18. {
  19. // Set the title bar text.
  20. setTitle("Grid Layout");
  21.  
  22. // Set the size of the window.
  23. setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
  24.  
  25. // Specify an action for the close button.
  26. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  27.  
  28. // Add a GridLayout manager to the content pane.
  29. setLayout(new GridLayout(2, 3));
  30.  
  31. // Create six buttons.
  32. JButton button1 = new JButton("Button 1");
  33. JButton button2 = new JButton("Button 2");
  34. JButton button3 = new JButton("Button 3");
  35. JButton button4 = new JButton("Button 4");
  36. JButton button5 = new JButton("Button 5");
  37. JButton button6 = new JButton("Button 6");
  38.  
  39. // Add the six buttons to the content pane.
  40. add(button1); // Goes into row 1, column 1
  41. add(button2); // Goes into row 1, column 2
  42. add(button3); // Goes into row 1, column 3
  43. add(button4); // Goes into row 2, column 1
  44. add(button5); // Goes into row 2, column 2
  45. add(button6); // Goes into row 2, column 3
  46.  
  47. // Display the window.
  48. setVisible(true);
  49. }
  50.  
  51. /**
  52. The main method creates an instance of the GridWindow
  53. class, causing it to display its window.
  54. */
  55.  
  56. public static void main(String[] args)
  57. {
  58. new GridWindow();
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement