-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDeathPanel.java
110 lines (98 loc) · 3.67 KB
/
DeathPanel.java
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
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
/**
* Creates a death panel for when a player dies in The Wellesley Trail.
* Provides the user with options of restarting or quitting the game.
*
* @author Nolen Belle Bryant
* @author Giulia Bronzi
* @author Zahra Thabet
* @version 12.17.18
*/
public class DeathPanel extends JPanel {
private JPanel death, deck, background;
private JButton cont, quit;
/**
* Constructor for objects of class DeathPanel
*/
public DeathPanel()
{
deck = death();
JLayeredPane content = new JLayeredPane();//can hold all the things
background = new JPanel();//holds the scenario image
try {
//scaling all input files to be the same size
ImageIcon image =
new ImageIcon(ImageIO.read(new File("images/deathScreen.jpg")));
Image pic = image.getImage(); // transform it
Image newimg = pic.getScaledInstance(1200, 800,
java.awt.Image.SCALE_SMOOTH);
image = new ImageIcon(newimg); // transform it back
background.add(new JLabel(image));
} catch (IOException e) {
e.printStackTrace();
}
setPreferredSize(new Dimension(1200, 800));
setLayout(new BorderLayout());
content.setBounds(0, 0, 1200, 800); //same as frame
//((where the panel starts),(the panel size))
deck.setBounds(500, 300, 200, 100);
background.setOpaque(true);
background.setBounds(0, 0, 1200, 800);
deck.setOpaque(true);
deck.setBackground(new Color(0,0,0,0));
content.add(background, new Integer(0), 0); //sets to the background
content.add(deck, new Integer(1),0);//sets to the foregound
add(content);
}
/**
* Impliments the action listeners for the two button option on this panel
*/
protected class ButtonListener implements ActionListener {
/**
* Depending on which button is selected, users will either be taken to
* the home screen or the window will close
*
* @param event action of clicking a button
*/
public void actionPerformed(ActionEvent event){
//restarts the game
if (event.getSource() == cont){
JFrame frame = new JFrame("Wellesley Trails");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
TrailGUI newGame = new TrailGUI();
newGame.addComponents(frame.getContentPane());
frame.pack();
frame.setVisible(true);
//quits the game
}else{
JPanel startPanel = (JPanel)death.getParent().getParent();
JPanel layeredPane =
(JPanel)startPanel.getParent().getParent().getParent();
JRootPane rootPane = (JRootPane)layeredPane.getParent()
.getParent().getParent();
JFrame frame = (JFrame) rootPane.getParent();
frame.dispose();
}
}
}
/**
* Creates the game over panel which holds two buttons
*
* @return JPanel the game over panels
*/
private JPanel death(){
death = new JPanel();
cont = new JButton("Try Again");
quit = new JButton("Quit Game");
cont.addActionListener(new ButtonListener());
quit.addActionListener(new ButtonListener());
death.add(cont);
death.add(quit);
return death;
}
}