Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. public DisplayMainMenu() throws HeadlessException {
  2. //add variables
  3. final JFrame frame = new JFrame("Checker (menu)");
  4. final int numberOfSquares = 10;
  5. final int buttonTextSize = 25;
  6. final Dimension preferredSize =
  7. new Dimension(BoardAndMouse.SQUARE_SIZE * numberOfSquares, BoardAndMouse.SQUARE_SIZE * numberOfSquares);
  8.  
  9. //create start button, first button
  10. JPanel startGamePanel = new JPanel();
  11. startGamePanel.setLayout(null);
  12. frame.add(startGamePanel);
  13.  
  14. JButton startGameButton = new JButton("Start new game");
  15. startGameButton.setFont(new Font("Times", Font.PLAIN, buttonTextSize));
  16. startGameButton.setBounds(200,200, 220, 75); //x,y and then width and height
  17. startGamePanel.add(startGameButton);
  18.  
  19. //create quit button, second button
  20. JPanel quitGamePanel= new JPanel();
  21. quitGamePanel.setLayout(null);
  22. frame.add(quitGamePanel);
  23.  
  24. JButton quitGameButton = new JButton("Quit");
  25. quitGameButton.setFont(new Font("Times", Font.PLAIN, buttonTextSize));
  26. quitGameButton.setBounds(200,300, 220, 75); //x,y and then widht and height
  27. quitGamePanel.add(quitGameButton);
  28.  
  29. //manage frame
  30. frame.setPreferredSize(preferredSize);
  31. frame.setResizable(false);
  32. //frame.setContentPane(menu); //make use of paintComponent in MainMenu
  33.  
  34. frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  35. frame.setLocationRelativeTo(null);
  36. frame.pack(); //size the frame so all its content are at or above their preferred sizes
  37. frame.setVisible(true);
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement