-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScreenPanel.java
More file actions
38 lines (35 loc) · 1.22 KB
/
ScreenPanel.java
File metadata and controls
38 lines (35 loc) · 1.22 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
/**
* Final Game Screenpanel Class
* @Author Ilya Kononov
* @Date = January 22 2023
* This class represents the framework that the screen panels within RunNGun.java will follow
* Additonally all screen panels are located within the RunNGun Class because they can't a shouldn't exist without RunNGun existing.
*/
import javax.swing.JPanel;
import java.awt.Graphics;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
abstract public class ScreenPanel extends JPanel {
private Image background;
public ScreenPanel(){
setFocusable(true);
this.background = null;
this.addComponentListener(this.FOCUS_WHEN_SHOWN);
}
public ScreenPanel(Image backgroundImage){
setFocusable(true);
this.background = backgroundImage;
this.addComponentListener(this.FOCUS_WHEN_SHOWN);
}
public void paintComponent(Graphics graphics){
super.paintComponent(graphics);
if (this.background != null) {
this.background.draw(graphics, 0, 0);
}
}
public final ComponentAdapter FOCUS_WHEN_SHOWN = new ComponentAdapter(){
public void componentShown(ComponentEvent event){
requestFocusInWindow();
}
};
}