-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathShapePanel.java
executable file
·49 lines (38 loc) · 1002 Bytes
/
ShapePanel.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
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.util.List;
import javax.swing.JPanel;
/**
* Creates a panel which shapes can be added to for display in the graphics
* window
*
* @author Abdullahi Abdinur,Kyle Goodwin
*
*/
public class ShapePanel extends JPanel implements DrawingView {
private DrawingModel model;
/**
* Updates the window with the latest graphics
*/
public void update(DrawingModel m) {
this.model = m;
repaint();
}
/**
* Override the paintComponet method to display new kinds of graphics
*/
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2D = (Graphics2D) g;
// Turn Antialiasing on
g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
if (model != null) {
List<Shape> shapes = model.getShapes();
for (Shape s : shapes) {
s.draw(g2D);
}
}
}
}