import java.applet.*; import java.awt.*; public class Mouse extends Applet implements Runnable { Thread t; private Image bufferImage; private Graphics buffer; // create a graphics buffer and off screen image private int width; private int height; private String message; public void init() { setBackground(Color.black); t=new Thread(this); t.start(); width=size().width; height=size().height; message = "Focus Lost"; 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){ ; } } } 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.drawString(message, 100, 100); g.drawImage(bufferImage, 0, 0, this); // draw our buffer image to the applet } public void update(Graphics g) { paint(g); } public boolean mouseEnter(Event e, int mouse_x, int mouse_y) { message = "Mouse has entered applet"; return true; } public boolean mouseExit(Event e, int mouse_x, int mouse_y) { message = "Mouse has left applet"; return true; } public boolean mouseDown(Event e, int mouse_x, int mouse_y) { message = "Mouse has been pressed down and x=" + mouse_x + " and y=" + mouse_y; return true; } public boolean mouseUp(Event e, int mouse_x, int mouse_y) { message = "Mouse has been released and x=" + mouse_x + " and y=" + mouse_y; return true; } public boolean mouseMove(Event e, int mouse_x, int mouse_y) { message = "Mouse has been moved and x=" + mouse_x + " and y=" + mouse_y; return true; } public boolean mouseDrag(Event e, int mouse_x, int mouse_y) { message = "Mouse has been dragged and x=" + mouse_x + " and y=" + mouse_y; return true; } }