import java.applet.*; import java.awt.*; /* Moving Radar Beam with Double Buffering (this will remove any flicker) */ public class RadarBeamDB extends Applet implements Runnable { // notice the "implements runnable", this is needed for using threads Thread t; // create a field that will be used for an instance of a thread private int startAngle; private Image bufferImage; private Graphics buffer; // create a graphics buffer and off screen image private int width; private int height; public void init() { setBackground(Color.black); t=new Thread(this); // instantiate a new thread object t.start(); // start our thread running startAngle=90; // start at the top of the screen width=size().width; height=size().height; bufferImage=createImage(width, height); buffer = bufferImage.getGraphics(); // create off screen buffer image and place it in the buffer } public void run() { while(true) { repaint(); try{ t.sleep(5); }catch(InterruptedException e){ ; } startAngle++; } } public void paint(Graphics g) { if (buffer == null) { // make sure the buffer was setup correctly bufferImage = createImage(width, height); buffer = bufferImage.getGraphics(); } buffer.setColor(Color.black); buffer.fillRect(0,0, width, height); // draw our background square to the buffer buffer.setColor(Color.red); buffer.fillArc(0,0, size().width, size().height, startAngle, 30); // fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) g.drawImage(bufferImage, 0, 0, this); // draw our buffer image to the applet } public void update(Graphics g) { // the update method will be called automatically to redraw the applet paint(g); } }