-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlmanacMenu.java
More file actions
164 lines (133 loc) · 3.8 KB
/
AlmanacMenu.java
File metadata and controls
164 lines (133 loc) · 3.8 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// AlmanacMenu.java
// David Wang
// Displays almanac of plants and zombies.
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
class AlmanacMenu extends JFrame implements ActionListener{
MainMenu menu;
PvZ pvz;
PlantAlmanac plantmenu;
ZombieAlmanac zombiemenu;
AlmanacPanel almanacpanel;
String comingfrom;
javax.swing.Timer myTimer;
public AlmanacMenu(MainMenu menu,String comingfrom,PvZ pvz){
super();
this.menu = menu;
this.comingfrom = comingfrom;
this.pvz = pvz;
setLayout(null);
almanacpanel = new AlmanacPanel(this);
almanacpanel.setSize(818,647);
almanacpanel.setLocation(0,0);
add(almanacpanel);
setVisible(true);
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
setSize(818,647);
myTimer = new javax.swing.Timer(100,this);
myTimer.start();
}
public void actionPerformed(ActionEvent evt){
Object source = evt.getSource();
almanacpanel.draw();
}
public void mainMenu(){
// checks to see where the user came from
// if the user came from the menu, it brings them back to the menu
// when they hit close
// if they came from the game
// it brings them back to the game
if(comingfrom.equals("menu")){
menu.stopAlmanacMusic();
menu.playMusic();
menu.setVisible(true);
setVisible(false);
}
if(comingfrom.equals("game")){
pvz.setVisible(true);
pvz.getPanel().setInAlmanac(false);
pvz.getPanel().setMusicLoop();
setVisible(false);
}
}
public void plantAlmanac(){
plantmenu = new PlantAlmanac(menu,comingfrom,pvz);
setVisible(false);
}
public void zombieAlmanac(){
zombiemenu = new ZombieAlmanac(menu,comingfrom,pvz);
setVisible(false);
}
public static void main(String[] args){
AlmanacMenu menu = new AlmanacMenu(null,null,null);
}
}
class AlmanacPanel extends JPanel implements MouseListener,MouseMotionListener{
AlmanacMenu menu;
Image AlmanacSelect,PlantsHover,ZombieHover,CloseHover;
int[] pos;
boolean clicked;
public void keyPressed(KeyEvent evt){}
public void keyTyped(KeyEvent evt){}
public void keyReleased(KeyEvent evt){}
public void mouseClicked(MouseEvent evt){
clicked = true;
}
public void mouseExited(MouseEvent evt){}
public void mouseEntered(MouseEvent evt){}
public void mouseReleased(MouseEvent evt){
clicked = true;
}
public void mousePressed(MouseEvent evt){
clicked = false;
}
public void mouseMoved(MouseEvent evt){
pos = new int[]{evt.getX(),evt.getY()};
}
public void mouseDragged(MouseEvent evt){
pos = new int[]{evt.getX(),evt.getY()};
}
public AlmanacPanel(AlmanacMenu menu){
super();
setFocusable(true);
grabFocus();
addMouseListener(this);
addMouseMotionListener(this);
this.menu = menu;
pos = new int[]{0,0};
clicked = false;
AlmanacSelect = new ImageIcon("Images/Menus/AlmanacIndex.png").getImage();
PlantsHover = new ImageIcon("Images/Menus/AlmanacIndex - Plants.png").getImage();
ZombieHover = new ImageIcon("Images/Menus/AlmanacIndex - Zombies.png").getImage();
CloseHover = new ImageIcon("Images/Menus/AlmanacIndex - Close.png").getImage();
}
public void draw(){
repaint();
}
public void paintComponent(Graphics g){
Rectangle plantAlmanac = new Rectangle(130,345,150,35);
Rectangle zombieAlmanac = new Rectangle(490,345,150,35);
Rectangle menuexit = new Rectangle(678,570,85,22);
g.drawImage(AlmanacSelect,0,0,this);
if(plantAlmanac.contains(pos[0],pos[1])){ // go back to main menu
g.drawImage(PlantsHover,0,0,this);
if(clicked){
menu.plantAlmanac();
}
}
else if(zombieAlmanac.contains(pos[0],pos[1])){ // view zombies
g.drawImage(ZombieHover,0,0,this);
if(clicked){
menu.zombieAlmanac();
}
}
else if(menuexit.contains(pos[0],pos[1])){ // view plants
g.drawImage(CloseHover,0,0,this);
if(clicked){
menu.mainMenu();
}
}
}
}