import java.applet.*; import java.awt.*; /* */ public class Abe extends Applet implements Runnable { int s = 0; Thread t; Image buffer; Graphics bufferg; public void init() { t = new Thread( this ); t.start(); Dimension d = getSize(); buffer = createImage( d.width, d.height ); } public void run() { try { while( true ) { repaint(); Thread.sleep( 1000 ); } } catch( Exception e ) { } } public void update( Graphics g ) { paint( g ); } public void paint( Graphics g ) { if( bufferg == null ) bufferg = buffer.getGraphics(); Dimension d = getSize(); //白で全面塗りつぶし bufferg.setColor( Color.white ); bufferg.fillRect( 0, 0, d.width, d.height ); //時計の描画 int xc = d.width / 2; int yc = d.height / 2; int radius = ( int )( ( d.width < d.height ) ? 0.4 * d.width : 0.4 * d.height ); bufferg.setColor( Color.black ); bufferg.drawOval( xc - radius, yc - radius, 2 * radius, 2 * radius ); //秒針の描画 double srad = 2 * Math.PI * s / 60.0; int sx = ( int )( xc + radius * 0.9 * Math.sin( srad ) ); int sy = ( int )( yc - radius * 0.9 * Math.cos( srad ) ); bufferg.drawLine( xc, yc, sx, sy ); g.drawImage( buffer, 0, 0, this ); //1秒経過させる s += 1; if( s > 59 ) s = 0; } }