-
Notifications
You must be signed in to change notification settings - Fork 0
/
IconOfRPSKL.java
66 lines (60 loc) · 1.69 KB
/
IconOfRPSKL.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
63
64
65
66
import java.awt.*;
import javax.swing.*;
/**
* This class contains methods related to icon. It implements the interface
* Icon. This code was suggested by StickFigure on Coursework.
*
* @author ChangSu Nam
* @UNI cn2521
* @since Assignment6 2.1
*/
public class IconOfRPSKL extends Component implements Icon {
/**
* This constructor creates with icon of given width, height and draggable object.
*
* @param Draggable the object that implement Draggable
* @param iconWidth the width of icon to be created
* @param iconHeight the height of icon to be created
*/
public IconOfRPSKL(Draggable draggableObject, int iconWidth, int iconHeight) {
this.draggableObject =draggableObject;
this.iconWidth = iconWidth;
this.iconHeight = iconHeight;
}
/**
* Get method to return the width.
* @return iconWidth the width of icon
*
*/
public int getIconWidth() {
return iconWidth;
}
/**
* Get method to return the height.
* @return iconWidth the height of icon
*
*/
public int getIconHeight() {
return iconHeight;
}
/**
* This method draws draggable object with Graphics2D.
*
* @param iconComponent the observer component used when icon has no image observer
* @param iconGraphics the graphic context
* @param x the x coordinate of the top left corner
* @param y the y coordinate of the top left corner
*/
public void paintIcon(Component iconComponent, Graphics iconGraphics, int x, int y) {
Graphics2D g2D = (Graphics2D) iconGraphics;
draggableObject.draw(g2D);
}
/**
* iconWidth the width of icon
* iconHeight the height of icon
* draggableObject the draggable object
*/
private int iconWidth;
private int iconHeight;
private Draggable draggableObject;
}