-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameWindow.java
62 lines (51 loc) · 1.47 KB
/
GameWindow.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
import java.awt.Color;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JFrame;
public class GameWindow extends JFrame implements WindowListener {
private static final long serialVersionUID = 1L;
private GamePanel gamePanel;
public GameWindow() {
setFrame();
addComponents();
setVisible(true);
}
private void setFrame() {
setSize(400, 550); // Adjusted size to fit game panel
setTitle("Apple Catching Game");
setLocationRelativeTo(null);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setResizable(false);
addWindowListener(this);
}
private void addComponents() {
gamePanel = new GamePanel();
gamePanel.setBackground(Color.CYAN); // Background color for the game
add(gamePanel);
}
@Override
public void windowClosing(WindowEvent e) {
System.out.println("Window was closed");
if (gamePanel != null) {
gamePanel.windowClose(); // Ensures the game stops on close
}
}
@Override
public void windowActivated(WindowEvent e) {
}
@Override
public void windowClosed(WindowEvent e) {
}
@Override
public void windowDeactivated(WindowEvent e) {
}
@Override
public void windowDeiconified(WindowEvent e) {
}
@Override
public void windowIconified(WindowEvent e) {
}
@Override
public void windowOpened(WindowEvent e) {
}
}