-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWelcomeScreen.java
More file actions
127 lines (104 loc) · 3.77 KB
/
WelcomeScreen.java
File metadata and controls
127 lines (104 loc) · 3.77 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener;
@SuppressWarnings("serial")
public class WelcomeScreen extends JFrame {
public WelcomeScreen() {
JPanel mainPanel = new JPanel();
mainPanel.setBackground(FrontEnd.backgroundColor);
mainPanel.setLayout(new BorderLayout());
//Settings menu
JMenuBar menuBar = new JMenuBar();
JMenu settingsMenu = new JMenu("Settings");
settingsMenu.addMenuListener(new OpenSettingsListener());
menuBar.setBackground(FrontEnd.backgroundColor);
settingsMenu.setBackground(FrontEnd.backgroundColor);
menuBar.add(settingsMenu);
setJMenuBar(menuBar);
//Minesweeper text
JLabel welcomeText = new JLabel("Minesweeper");
welcomeText.setFont(new Font("Krungthep", Font.PLAIN, 50));
welcomeText.setHorizontalAlignment(SwingConstants.CENTER);
mainPanel.add(welcomeText, BorderLayout.NORTH);
//Minesweeper image
MinesweeperImage imagePanel = new MinesweeperImage();
imagePanel.setBackground(FrontEnd.backgroundColor);
mainPanel.add(imagePanel, BorderLayout.CENTER);
//My name
JLabel myName = new JLabel("By Dan Saba");
myName.setFont(new Font("Marker Felt", Font.PLAIN, 24));
myName.setHorizontalAlignment(SwingConstants.CENTER);
//Start button
JPanel startButtonPanel = new JPanel();
JButton startGame = new JButton("Start Game");
startButtonPanel.setBackground(FrontEnd.backgroundColor);
startGame.addActionListener(new StartButtonListener());
startGame.setPreferredSize(new Dimension(300, 50));
startGame.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 24));
startButtonPanel.add(startGame);
//Name and start button panel
JPanel SandN = new JPanel(new BorderLayout());
SandN.setBackground(FrontEnd.backgroundColor);
SandN.add(myName, BorderLayout.NORTH);
SandN.add(startButtonPanel, BorderLayout.SOUTH);
mainPanel.add(SandN, BorderLayout.SOUTH);
add(mainPanel);
setTitle("Minesweeper");
setSize(MinesweeperUtils.getSquareScreenSize(1.0/3.0));
setLocation(MinesweeperUtils.getCornerPoint(getSize()));
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
class MinesweeperImage extends JPanel {
public void paintComponent(Graphics g){
super.paintComponent(g);
ImageIcon imgIcon = FrontEnd.msIcons().getIcon(MinesweeperIcons.MINESWEEPER);
Image img = imgIcon.getImage();
int x = MinesweeperUtils.roundToInt(getSize().getWidth() / 4);
int y = 0;
int width = MinesweeperUtils.roundToInt(getSize().getWidth() / 2);
int height = MinesweeperUtils.roundToInt(getSize().getHeight());
g.drawImage(img, x, y, width, height, this);
}
}
class StartButtonListener implements ActionListener {
public void actionPerformed(ActionEvent arg0) {
FrontEnd.welcomeScreen().dispose();
FrontEnd.gameScreen();
}
}
class OpenSettingsListener implements MenuListener {
SettingsMenu settingsMenu = null;
@Override
public void menuSelected(MenuEvent e) {
if (settingsMenu == null){
settingsMenu = new SettingsMenu();
}
else if (!settingsMenu.isVisible()){
settingsMenu.setVisible(true);
}
}
@Override
public void menuDeselected(MenuEvent e) {
// TODO Auto-generated method stub
}
@Override
public void menuCanceled(MenuEvent e) {
// TODO Auto-generated method stub
}
}
}