-
Notifications
You must be signed in to change notification settings - Fork 0
/
KDScreen.java
123 lines (102 loc) · 3.98 KB
/
KDScreen.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
111
112
113
114
115
116
117
118
119
120
121
122
123
/* [KDScreen.java]
* A program that displays information about Kevin Durant
* June 12th, 2019
* @author: Jerry Jiao
*/
//imports
import java.awt.Toolkit;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.*;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
class KDScreen extends JFrame {
private static final long serialVersionUID = 1L;
Image kevin= Toolkit.getDefaultToolkit().getImage("kd.gif");
int maxX = 1366;
int maxY = 768;
static GameAreaPanel gamePanel;
JFrame thisFrame, startFrame;
//Constructor - this runs first
KDScreen(JFrame startingFrame) {
super("My Game");
thisFrame = this;
startFrame = startingFrame;
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(1366,768);
this.setResizable(false);
//Set up the game panel (where we put our graphics)
gamePanel = new GameAreaPanel();
this.add(new GameAreaPanel());
Font font = new Font("Press Start 2P", Font.PLAIN, 25);
JPanel mainPanel = new JPanel();
mainPanel.setPreferredSize(new Dimension(100, 150));
JButton previous = new JButton("Lebron James");
previous.addActionListener(new PreviousButtonListener());
previous.setFont(font);
mainPanel.add(previous);
JButton start = new JButton("Starting screen");
start.addActionListener(new StartButtonListener());
start.setFont(font);
mainPanel.add(start);
JButton next = new JButton("Stephen Curry");
next.addActionListener(new NextButtonListener());
next.setFont(font);
mainPanel.add(next);
GridLayout layout1 = new GridLayout(1,3);
mainPanel.setLayout(layout1);
thisFrame.add(mainPanel,BorderLayout.SOUTH);
this.requestFocusInWindow(); //make sure the frame has focus
this.setVisible(true);
//Start the game loop in a separate thread
Thread t = new Thread(); //start the gameLoop
t.start();
} //End of Constructor
/** --------- INNER CLASSES ------------- **/
// Inner class for drawing
private class GameAreaPanel extends JPanel {
private static final long serialVersionUID = 1L;
public void paintComponent(Graphics g) {
super.paintComponent(g); //required
setDoubleBuffered(true);
g.setColor(Color.RED);
g.setFont(new Font("Press Start 2P", Font.BOLD, 35));
g.drawString("KEVIN DURANT",maxX/2-220,50);
g.drawImage(kevin,0,60,440,500,this);
g.setColor(Color.BLACK);
g.setFont(new Font("Press Start 2P", Font.PLAIN, 20));
g.drawString("(Health: 180 Base Hit Chance: 90)",maxX/2-320,80);
g.setFont(new Font("Press Start 2P", Font.PLAIN, 14));
g.drawString("BUCKETS - deal 20 damage, high hit chance.",maxX/2-220,180);
g.drawString("MVP SPEECH - gain 10 health, 5 hit chance,",maxX/2-220,240);
g.drawString("medium hit chance",maxX/2-100,260);
g.drawString("SNAKE - steal 10 hit chance from the enemy, medium hit chance.",maxX/2-220,320);
g.drawString("BURNER ACCOUNT - put enemy player to sleep, low hit chance",maxX/2-220,380);
}
}
//inner class for start screen button press
class StartButtonListener implements ActionListener {
public void actionPerformed(ActionEvent event) {
thisFrame.dispose();
startFrame.setVisible(true);
}
}
//inner class for next screen button press
class NextButtonListener implements ActionListener {
public void actionPerformed(ActionEvent event) {
thisFrame.dispose();
new CurryScreen(startFrame);
}
}
//inner class for previous screen button press
class PreviousButtonListener implements ActionListener {
public void actionPerformed(ActionEvent event) {
thisFrame.dispose();
new LBJScreen(startFrame);
}
}
}