Clock - import import import import i import java.awt.*;...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.awt.*; import java.util.*; import java.text.*; import java.applet.*; import javax.swing.*; i // An applet that displays a clock with the time // at which the instance was created and the time // whenever it is repainted public class Clock extends JApplet { private int xMid; // (xMid, yMid) is the center of the private int yMid; // panel private int radius; // The radius of the clock // Paint the clock using g public void paint(Graphics g) { setBackground(new Color(255, 235, 222)); g.setColor(Color.black); // Set the clock parameters based on the size of this // JApplet xMid= 75; yMid= 75; radius= 60; // Store in cal the current date and time GregorianCalendar cal= new GregorianCalendar(Locale.getDefault()); drawCircle(g); // Draw the second hand int sec= cal.get(GregorianCalendar.SECOND); drawHand(radius*0.95, sec*2*Math.PI/60.0, 1, g); // Draw the minute hand int min= cal.get(GregorianCalendar.MINUTE); drawHand(radius*0.7, min*2*Math.PI/60.0, 2, g); // Draw the hour hand int hr= cal.get(GregorianCalendar.HOUR);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 02/24/2010.

Page1 / 2

Clock - import import import import i import java.awt.*;...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online