-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIconOfCars.java
64 lines (58 loc) · 1.59 KB
/
IconOfCars.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
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 Assignment4 2.1
*/
public class IconOfCars implements Icon {
/**
* This constructor creates with icon of given width, height and movable object.
*
* @param movingObject the object that implement Movable
* @param iconWidth the width of icon to be created
* @param iconHeight the height of icon to be created
*/
public IconOfCars(Movable movingObject, int iconWidth, int iconHeight) {
this.movingObject = movingObject;
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;
}
/**
* @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;
movingObject.drawCar(g2D);
}
/**
* iconWidth the width of icon
* iconHeight the height of icon
* movingObject the movable object
*/
private int iconWidth;
private int iconHeight;
private Movable movingObject;
}