H:\CSC120\Java\lec12\src\TVSet.java |
1
2 import java.awt.*;
3
4
5
6
7
8
9
10
11
12 @author
13
14 public class TVSet {
15
16 private Integer anchorX, anchorY;
17 private Integer channel, volume;
18 private Boolean turnedOn;
19
20 public TVSet(Integer x, Integer y, Boolean onOff, Integer ch, Integer vol) {
21 anchorX = x;
22 anchorY = y;
23 channel = ch;
24 volume = vol;
25 turnedOn = onOff;
26 }
27
28
29
30 public void setChannel( Integer ch ) {
31 channel = ch;
32 }
33
34 public void setVolume( Integer vol ) {
35 volume = vol;
36 }
37
38 public void setTurnedOn( Boolean onOff ) {
39 turnedOn = onOff;
40 }
41
42
43
44
45 public Integer getChannel() {
46 return channel;
47 }
48
49 public Integer getVolume() {
50 return volume;
51 }
52
53 public Boolean getTurnedOn() {
54 return turnedOn;
55 }
56
57
58
59
60 public String toString() {
61 return "this is a TV Set tuned to channel " + channel
62 + " and set to volume level " + volume
63 + "; it's turnedOn value is " + turnedOn;
64 }
65
66
67
68 public void volumeUp() {
69 Integer temp = volume + 1;
70 volume = temp;
71 }
72
73 public void volumeDown() {
74 volume = volume - 1;
75 }
76
77 public void channelUp() {
78 channel = channel + 1;
79 }
80
81 public void channelDown() {
82 channel = channel - 1;
83 }
84
85 public void turnOff() {
86 turnedOn = false;
87 }
88
89 public void turnOn() {
90 turnedOn = true;
91 }
92
93
94
95
96
97 public void draw(Graphics g) {
98 g.setColor(Color.BLACK);
99 g.fillRect(anchorX, anchorY, 160, 100);
100 if (turnedOn) {
101
102 g.setColor(Color.WHITE);
103 g.fillRect(anchorX+10, anchorY+10, 140, 80);
104
105 g.setColor(Color.BLACK);
106
107 g.drawOval(anchorX+40, anchorY+20, 20, 20);
108 g.drawLine(anchorX+50, anchorY+40, anchorX+50, anchorY+70);
109 g.drawLine(anchorX+50, anchorY+70, anchorX+35, anchorY+85);
110 g.drawLine(anchorX+50, anchorY+70, anchorX+65, anchorY+85);
111 g.drawLine(anchorX+40, anchorY+50, anchorX+60, anchorY+50);
112
113 g.drawOval(anchorX+80, anchorY+50, 20, 20);
114 g.drawLine(anchorX+90, anchorY+70, anchorX+95, anchorY+75);
115 g.drawLine(anchorX+95, anchorY+75, anchorX+120, anchorY+75);
116 g.drawLine(anchorX+95, anchorY+75, anchorX+85, anchorY+85);
117 g.drawLine(anchorX+95, anchorY+75, anchorX+105, anchorY+85);
118 g.drawLine(anchorX+120, anchorY+75, anchorX+110, anchorY+85);
119 g.drawLine(anchorX+120, anchorY+75, anchorX+130, anchorY+85);
120 g.drawLine(anchorX+115, anchorY+75, anchorX+123, anchorY+67);
121
122
123 g.setColor(Color.BLUE);
124 g.drawString(""+channel, anchorX+120, anchorY+30);
125
126 g.setColor(Color.RED);
127 g.fillRect(anchorX+10, anchorY+85, (int) (volume*1.4), 5);
128 }
129
130 }
131
132
133
134 }
135