-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShapeIcon.java
55 lines (48 loc) · 1.27 KB
/
ShapeIcon.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
import java.awt.*;
import java.util.*;
import javax.swing.*;
/**
* An icon that contains a moveable shape.
*/
public class ShapeIcon implements Icon {
/**
* Creates a new ShapeIcon with the given parameters
*
* @param shape a MoveableShape to be contained in this ShapeIcon
* @param width the desired width
* @param height the desired height
*/
public ShapeIcon(MoveableShape shape,
int width, int height) {
this.shape = shape;
this.width = width;
this.height = height;
}
/**
* @return this ShapeIcon's width
*/
public int getIconWidth() {
return width;
}
/**
* @return this ShapeIcon's height
*/
public int getIconHeight() {
return height;
}
/**
* Paint this ShapeIcon with the given parameters
*
* @param c Component for painting
* @param g Graphics for painting
* @param x X-coordinate in which to paint this ShapeIcon
* @param y Y-coordinate in which to paint this ShapeIcon
*/
public void paintIcon(Component c, Graphics g, int x, int y) {
Graphics2D g2 = (Graphics2D) g;
shape.draw(g2);
}
private int width;
private int height;
private MoveableShape shape;
}