-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTitleScreen.java
More file actions
97 lines (80 loc) · 2.72 KB
/
TitleScreen.java
File metadata and controls
97 lines (80 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.imageio.*;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
/**
* Displays the title screen at the beginning of the game
*
* @Avi and Amar Ruthen
* @12.22.2020
*/
public class TitleScreen extends JFrame implements ActionListener
{
JPanel buttonPanel;
JPanel textPanel;
JPanel picPanel;
JButton startButton;
JLabel welcome;
JLabel backgroundPic;
BufferedImage titlePic;
final Color DARK_BLUE = new Color(0, 0, 204);
int WIDTH;
int HEIGHT;
/**
* Constructor for creating initial title screen
*/
public TitleScreen()
{
super("BlockPlusMenu");
//the JFrame/Graphics Window size:
WIDTH = 1000;
HEIGHT = 700;
Font font = new Font("Verdana", Font.BOLD, 32);
this.setLayout(new BorderLayout());
//Create the panel for the welcoming text
textPanel = new JPanel();
textPanel.setBackground(DARK_BLUE);
welcome = new JLabel();
welcome.setText("Welcome to BlockPlus!");
welcome.setFont(font);
welcome.setForeground(Color.WHITE);
//Add welcome mensage to the panel
textPanel.add(welcome);
//Create the button panel
buttonPanel = new JPanel();
buttonPanel.setBackground(DARK_BLUE);
startButton = new JButton("BEGIN");
startButton.addActionListener(this);
startButton.setActionCommand("startButton");
//Add start button to panel
buttonPanel.add(startButton);
//Create the picture panel
picPanel = new JPanel();
picPanel.setBackground(DARK_BLUE);
ImageIcon titlePic = new ImageIcon("resources/TitleBackground.png");
backgroundPic = new JLabel(titlePic);
//Add picture to the whole paenl
picPanel.add(backgroundPic);
//Arrange panels on screen
this.add(buttonPanel, BorderLayout.CENTER);
this.add(textPanel, BorderLayout.NORTH);
this.add(picPanel, BorderLayout.SOUTH);
//Fine-tuning screen settings
this.setPreferredSize(new Dimension(WIDTH, HEIGHT));
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.pack();
this.setVisible(true);
}
/**
* Actionperformed: when a button is pressed, this is automatically called:
*/
public void actionPerformed(ActionEvent e) {
//Transfer to powerup screen
if (e.getActionCommand().equals("startButton")) {
PowerupScreen ps = new PowerupScreen();
this.setVisible(false);
}
}
}