-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGamePanel.java
More file actions
63 lines (52 loc) · 1.24 KB
/
GamePanel.java
File metadata and controls
63 lines (52 loc) · 1.24 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
import java.awt.Color;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Image;
import javax.swing.JPanel;
/**
* Game Panel
*
* An extension of JPanel, this is the panel where the game is played.
* It creates and stores each grid square.
*
* @author Quinten Houck
* @version 8/1/2021
*
*/
public class GamePanel extends JPanel {
Image background;
Data data;
Square[][] grid;
public GamePanel(Data data) {
super();
this.data = data;
this.setLayout(new GridLayout(10,10));
this.setBackground(Color.RED);
this.setVisible(true);
//Makes the grid//
grid = new Square[10][10];
//Creates each square//
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
Square square = new Square(data,i,j);
grid[i][j] = square;
this.add(square);
}
}
}
//Calls the reset feature for each grid square//
public void reset() {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
grid[i][j].reset();
}
}
}
public void paintComponent(Graphics g) {
g.drawImage(background, 0, 0, null);
}
public void changeBackground() {
background = Images.getImage("sprites/GridGameWords.PNG");
repaint();
}
}