-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChipClass.java
More file actions
149 lines (115 loc) · 2.02 KB
/
ChipClass.java
File metadata and controls
149 lines (115 loc) · 2.02 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// The ChipClass Class
// Second in a series of demonstration programs for introducing Java
import hsa.Console;
import java.awt.*;
public class ChipClass extends ShapeClass
{
// global variables for this class
// encapsulated data
protected int cValue = 5000;
Font fc = new Font ("SanSerif", Font.PLAIN, 14);
// constructor methods
ChipClass ()
{
height = width;
}
ChipClass (int w, int h)
{
width = w;
height = h;
}
ChipClass (int w, int h, int chipvalue)
{
width = w;
height = h;
cValue = chipvalue;
}
ChipClass (int centerx, int centery, int w, int h, int chipvalue)
{
cx = centerx;
cy = centery;
width = w;
height = h;
cValue = chipvalue;
}
// communicator methods
public void setChipValue (int nValue)
{
if (nValue < 0)
{
//TODO
//Return error message
}
else
{
cValue = nValue;
}
}
public void setChipColor (int nValue)
{
if (nValue == 1)
{
setColor (Color.white);
}
else if (nValue == 5)
{
setColor (Color.red);
}
else if (nValue == 10)
{
setColor (Color.blue);
}
else if (nValue == 25)
{
setColor (Color.green);
}
else if (nValue == 100)
{
setColor (Color.black);
}
else if (nValue == 250)
{
setColor (Color.pink);
}
else if (nValue == 1000)
{
setColor (Color.yellow);
}
else if (nValue == 5000)
{
setColor (Color.orange);
}
}
public int getChipValue ()
{
return cValue;
}
public Color getChipColor ()
{
return iColor;
}
public void drawChipValue (Graphics g, int nValue)
{
g.setFont (fc);
if (nValue == 1)
{
g.setColor (Color.black);
}
else
{
g.setColor (Color.white);
}
g.drawString (Integer.toString (cValue), cx + width / 2 - 5, cy + width / 2 + 5);
g.setColor (iColor);
}
public void draw (Console c)
{
}
public void draw (Graphics g)
{
setChipColor (cValue);
g.setColor (iColor);
g.fillOval (cx, cy, width, height);
drawChipValue (g, cValue);
}
}