import java.applet.*; import java.awt.*; /* Moving Radar Beam by Carman Neustaedter August 14, 2001 */ public class RadarBeam extends Applet implements Runnable { Thread t; // create a field that will be used for an instance of a thread // (a thread object) private int width, height; private int startAngle; private Image bufferImage; private Graphics buffer; public void init() { setBackground(Color.black); setForeground(Color.green); width=size().width; height=size().height; startAngle = 90; // start at the top of the circle t = new Thread(this); // create a new thread object t.start(); // start the thread running bufferImage=createImage(width, height); // create a buffer image the size of our applet buffer=bufferImage.getGraphics(); // place our buffer image inside the buffer } public void run() { while(true) { repaint(); try{ t.sleep(5); }catch(InterruptedException e) { ; } startAngle++; } } public void paint(Graphics g) { buffer.setColor(Color.black); buffer.fillRect(0,0, width, height); // my radar lines buffer.setColor(Color.green); buffer.drawOval(0, 0, width-1, height-1); for( int i=10; i < 120; i+=20) buffer.drawOval(i, i, width-i*2, height-i*2); buffer.fillArc(0,0, width, height, startAngle, 10); // enemy attack buffer.setColor(Color.black); buffer.fillOval(30,60, 10, 10); buffer.fillOval(150,120, 5, 5); buffer.fillOval(90,200, 7, 7); buffer.setColor(Color.green); if ((startAngle % 100) == 0) buffer.fillOval(120, 70, 10, 10); g.drawImage(bufferImage, 0, 0, this); // copy buffer image to the applet // "this" means the current object will be the one that is copied } public void update(Graphics g) { paint(g); } }