/////// TimerFace.java /////// import java.awt.Canvas; import java.awt.Font; import java.awt.Color; import java.awt.Graphics; /** a face display for a timer */ public class TimerFace extends Canvas { public TimerFace(Color c) { bg = c; } protected TimerFace() { } public void set(int min, int sec) { m = min; s = sec; repaint(); } public void paint(Graphics g) { drawInit(g); g.fillRect(20, 0, Math.min(120,w), h); g.setFont(f); g.setColor(Color.black); String time = ""+ m1 + m2 + " : " + s1 + s2; g.drawString(time, 35, h-4); } protected void drawInit(Graphics g) { w = getSize().width-1; h = getSize().height-1; m1 = m/10; m2 = m % 10; s1 = s/10; s2 = s % 10; g.setColor(bg); } protected Font f = new Font("TimesRoman", Font.BOLD, 36); protected int m=0, s=0; // time displayed protected int w, h, m1, m2, s1, s2; // width, height, digits protected Color bg; // background color }