H:\CSC120\Java\lec16\src\TVSet.java |
1
2 import java.awt.*;
3
4 public class TVSet {
5
6 private Integer over;
7 private Integer down;
8 private Integer channel;
9 private Integer volume;
10 private Boolean turnedOn;
11
12 public TVSet(Integer ov, Integer d, Boolean on, Integer c, Integer v) {
13 over = ov;
14 down = d;
15 turnedOn = on;
16 channel = c;
17 volume = v;
18 }
19
20 public void setVolume(Integer v) {
21 volume = v;
22 }
23
24 public void setChannel(Integer c) {
25 channel = c;
26 }
27
28 public void setTurnedOn(Boolean on) {
29 turnedOn = on;
30 }
31
32 public Integer getVolume() {
33 return volume;
34 }
35
36 public Integer getChannel() {
37 return channel;
38 }
39
40 public Boolean getTurnedOn() {
41 return turnedOn;
42 }
43
44
45
46
47 public void channelUp() {
48 if (turnedOn) {
49 if (channel != 125) {
50 channel++;
51 }
52 else {
53 channel = 2;
54 }
55 }
56 }
57
58
59 public void channelDown() {
60 if (channel >= 3) {
61 channel -= 1;
62 }
63 else {
64 channel = 125;
65 }
66 }
67
68
69 public void volumeUp() {
70 if (volume != 100) {
71 volume = volume + 1;
72 }
73 }
74
75
76 public void volumeDown() {
77 if (volume > 0) {
78 volume--;
79 }
80 }
81
82
83
84
85
86
87 public void draw(Graphics g) {
88 g.setColor(Color.BLACK);
89 g.fillRect(over, down, 160, 100);
90 if (turnedOn) {
91
92 g.setColor(Color.WHITE);
93 g.fillRect(over+10, down+10, 140, 80);
94
95 g.setColor(Color.BLACK);
96
97 g.drawOval(over+40, down+20, 20, 20);
98 g.drawLine(over+50, down+40, over+50, down+70);
99 g.drawLine(over+50, down+70, over+35, down+85);
100 g.drawLine(over+50, down+70, over+65, down+85);
101 g.drawLine(over+40, down+50, over+60, down+50);
102
103 g.drawOval(over+80, down+50, 20, 20);
104 g.drawLine(over+90, down+70, over+95, down+75);
105 g.drawLine(over+95, down+75, over+120, down+75);
106 g.drawLine(over+95, down+75, over+85, down+85);
107 g.drawLine(over+95, down+75, over+105, down+85);
108 g.drawLine(over+120, down+75, over+110, down+85);
109 g.drawLine(over+120, down+75, over+130, down+85);
110 g.drawLine(over+115, down+75, over+123, down+67);
111
112
113 g.setColor(Color.BLUE);
114 g.drawString(""+channel, over+120, down+30);
115
116 g.setColor(Color.RED);
117 g.fillRect(over+10, down+85, (int) (volume*1.4), 5);
118 }
119
120 }
121
122 }
123