-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathT1Field.java
More file actions
42 lines (34 loc) · 963 Bytes
/
Copy pathT1Field.java
File metadata and controls
42 lines (34 loc) · 963 Bytes
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
/**
* T1Field.java
* Table 1
* Daniel Alexander Miranda
*
* Responsibilities:
* - Render the Pong field and game elements (like the ball)
* - Provide a basic graphical interface for testing
* - Should be refreshed regularly by the game loop
*/
import javax.swing.*;
import java.awt.*;
public class T1Field extends JPanel {
private T1Ball ball;
private T1Fans fans;
public T1Field(T1Ball ball, T1Fans fans) {
this.ball = ball;
this.fans = fans;
setPreferredSize(new Dimension(800, 600));
setBackground(Color.BLACK);
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
// Draw ball
g.setColor(Color.WHITE);
g.fillOval(ball.getX(), ball.getY(), ball.getWidth(), ball.getHeight());
// Draw decorations from fans
fans.draw(g);
}
public void refresh() {
repaint();
}
}