-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemperatureCanvas.java
More file actions
42 lines (36 loc) · 1.13 KB
/
TemperatureCanvas.java
File metadata and controls
42 lines (36 loc) · 1.13 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
package Temperature;
/**
* Exemple adapté de:
* https://csis.pace.edu/~bergin/mvc/mvcgui.html
* Joseph Bergin, Pace University, jbergin@pace.edu
*/
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
class TemperatureCanvas extends Canvas
{
private TemperatureGauge _farenheit;
private static final int width = 20;
private static final int top = 20;
private static final int left = 100;
private static final int right = 250;
private static final int height = 200;
public TemperatureCanvas(TemperatureGauge farenheit)
{
_farenheit = farenheit;
}
public void paint(Graphics g)
{
g.setColor(Color.black);
g.drawRect(left,top, width, height);
g.setColor(Color.red);
g.fillOval(left-width/2, top+height-width/3,width*2, width*2);
g.setColor(Color.black);
g.drawOval(left-width/2, top+height-width/3,width*2, width*2);
g.setColor(Color.white);
g.fillRect(left+1,top+1, width-1, height-1);
g.setColor(Color.red);
long redtop = height*(_farenheit.get()-_farenheit.getMax())/(_farenheit.getMin()-_farenheit.getMax());
g.fillRect(left+1, top + (int)redtop, width-1, height-(int)redtop);
}
}