import java.util.*; import java.awt.*; import java.awt.geom.*; import javax.swing.*; public class Clock03 { private JFrame frame = new JFrame("•`‰æ"); private JPanel pane = (JPanel)frame.getContentPane(); private Canvas canvas = new Canvas(){ @Override public void update(Graphics g){ paint(g); } @Override public void paint(Graphics g){ Image img = createImage(400, 400); Graphics2D g2 = (Graphics2D)img.getGraphics(); AffineTransform af = new AffineTransform(); for(int i = 0; i < 12; i++){ af.setToRotation(Math.PI / 6 * i, 200, 200); g2.setTransform(af); g2.fillOval(198, 0, 4, 20); } Calendar cal = Calendar.getInstance(); double sec = Math.PI / 30 * cal.get(Calendar.SECOND); af.setToRotation(sec, 200, 200); g2.setTransform(af); g2.setColor(Color.BLUE); g2.fillOval(198, 0, 4, 200); double min = Math.PI / 30 * cal.get(Calendar.MINUTE); af.setToRotation(min, 200, 200); g2.setTransform(af); g2.setColor(Color.GREEN); g2.fillOval(195, 24, 10, 176); double hour = Math.PI / 6 * cal.get(Calendar.HOUR) + min / 12; af.setToRotation(hour, 200, 200); g2.setTransform(af); g2.setColor(Color.RED); g2.fillOval(192, 100, 16, 100); g.drawImage(img, 0, 0, this); try{Thread.sleep(50);}catch(Exception ex){} repaint(); } }; public Clock03(){ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); canvas.setBackground(Color.LIGHT_GRAY); canvas.setSize(400, 400); pane.add(canvas); frame.pack(); frame.setVisible(true); } public static void main(String[] args) { new Clock03(); } }