klasscho

MainMenuPanel

May 31st, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.97 KB | None | 0 0
  1. package com.packadge.gui;
  2.  
  3. import com.packadge.DrawUtils;
  4. import com.packadge.Game;
  5.  
  6. import java.awt.*;
  7. import java.awt.event.ActionEvent;
  8. import java.awt.event.ActionListener;
  9.  
  10. public class MainMenuPanel extends GuiPanel{
  11.  
  12.     private Font titleFont = Game.main.deriveFont(100f);
  13.     private String title = "2048";
  14.     private int buttonWidth = 220;
  15.     private int spacing = 90;
  16.     private int buttonHeight = 60;
  17.  
  18.     public MainMenuPanel(){
  19.         super();
  20.         GuiButton playButton = new GuiButton(Game.WIDTH/2 - buttonWidth/2, 220, buttonWidth, buttonHeight);
  21.         GuiButton scoreButton = new GuiButton(Game.WIDTH/2 - buttonWidth/2, playButton.getY() + spacing, buttonWidth, buttonHeight);
  22.         GuiButton quitButton = new GuiButton(Game.WIDTH/2 - buttonWidth/2, scoreButton.getY() + spacing, buttonWidth, buttonHeight);
  23.  
  24.         playButton.setText("Play");
  25.         scoreButton.setText("Best scores");
  26.         quitButton.setText("Quit");
  27.  
  28.         playButton.addActionListener(new ActionListener() {
  29.             @Override
  30.             public void actionPerformed(ActionEvent arg0) {
  31.                 GuiScreen.getInstance().setCurrentPanel("Play");
  32.             }
  33.         });
  34.  
  35.         scoreButton.addActionListener(new ActionListener() {
  36.             @Override
  37.             public void actionPerformed(ActionEvent e) {
  38.                 GuiScreen.getInstance().setCurrentPanel("Best Score");
  39.             }
  40.         });
  41.  
  42.         quitButton.addActionListener(new ActionListener() {
  43.             @Override
  44.             public void actionPerformed(ActionEvent e) {
  45.                 System.exit(0);
  46.             }
  47.         });
  48.         add(playButton);
  49.         add(scoreButton);
  50.         add(quitButton);
  51.     }
  52.  
  53.     @Override
  54.     public void render(Graphics2D g){
  55.         super.render(g);
  56.         g.setFont(titleFont);
  57.         g.setColor(Color.black);
  58.         g.drawString(title, Game.WIDTH/2 - DrawUtils.getMessageWidth(title, titleFont, g)/2, 150);
  59.     }
  60.  
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment