-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpeningScreen.java
More file actions
107 lines (90 loc) · 3.37 KB
/
OpeningScreen.java
File metadata and controls
107 lines (90 loc) · 3.37 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
//Filename: OpeningScreen.java
//Authors: Alex Bangu, Costa Giannaras, Humza Chaudhry
//Date: June 9, 2023
//Description: Generates the Opening screen which is the first screen the user sees
//after opening scoreforge. It allows them to access the library, help, or credits page.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/** Generates the library screen from the opening screen
*@author Alex Bangu, Costa Giannaras, Humza Chaudhry */
public class OpeningScreen extends JFrame implements ActionListener
{
//initialize variables
/**Open help button */
private JButton btnHelp;
/**Open library button */
private JButton btnLibrary;
/**Open credits button */
private JButton btnCredits;
public OpeningScreen() //constructor
{
initialize();
JPanel mainPanel =
new JPanel(null)
{
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
drawBackground(g);
}
};
btnHelp = new JButton("Help");
btnHelp.setFont(new Font("Impact", Font.PLAIN, 40));
btnHelp.setBounds(300, 250, 300, 200);
btnHelp.addActionListener(this);
btnCredits = new JButton("Credits");
btnCredits.setFont(new Font("Impact", Font.PLAIN, 40));
btnCredits.setBounds(300, 450, 300, 200);
btnCredits.addActionListener(this);
btnLibrary = new JButton("Library");
btnLibrary.setFont(new Font("Impact", Font.PLAIN, 60));
btnLibrary.setBounds(600, 250, 350, 400);
btnLibrary.addActionListener(this);
mainPanel.add(btnHelp);
mainPanel.add(btnCredits);
mainPanel.add(btnLibrary);
add(mainPanel);
}
/**Sets screensize, name, and makes the x button work */
private void initialize() //a method that sets screensize, name, and makes x button work
{
setTitle("SCOREFORGE");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); //uses a default operation to make the x button close the program
setSize(1280,720);
setResizable(false);
setVisible(true);
setLocationRelativeTo(null); //centres screen
}
/**Creates graphics for the opening screen */
private void drawBackground(Graphics g)
{
Toolkit tk = Toolkit.getDefaultToolkit();
Image background = tk.getImage("mainpage_background.png"); //Background photo for homescreen.
g.drawImage(background, 0, 0, this);
Image logo = tk.getImage("scoreforgegif.gif"); //scoreforge logo gif.
g.drawImage(logo,350,30,this);
}
/**Listens for action events and reacts to them */
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == btnHelp)
{
HelpPage helpPage = new HelpPage();
helpPage.setVisible(true);
dispose();
}
else if (e.getSource() == btnLibrary)
{
LibraryScreen libraryScreen = new LibraryScreen();
libraryScreen.setVisible(true);
dispose(); // Close the current OpeningScreen
}
else if (e.getSource() == btnCredits)
{
AboutUsPage CreditsScreen = new AboutUsPage();
CreditsScreen.setVisible(true);
dispose(); // Close the current OpeningScreen
}
}
}