import java.applet.Applet; import java.awt.*; import com.braju.applet.*; import com.braju.format.*; public class MouseApplet extends Applet implements DoneListener { private LoaderPanel loaderPnl; private Panel mainPnl; String theMessage; Button theButton; int messageX, messageY; int colorIndex = -1; static Color[] someColors = { Color.black, Color.red, Color.green, Color.blue, Color.magenta }; public void init() { setBackground(Color.white); // The loader that is shown initially... loaderPnl = new LoaderPanel(); loaderPnl.addDoneListener(this); add(loaderPnl); // The main panel that will be shown after loading... mainPnl = new Panel(); mainPnl.hide(); mainPnl.setBackground(Color.white); theButton = new Button("Change Color"); mainPnl.add(theButton); add(mainPnl); } public void done(DoneEvent e) { loaderPnl.hide(); mainPnl.show(); messageX = size().width/2; messageY = size().height/2; colorIndex = 0; validate(); repaint(); } public void paint(Graphics graphics) { if (colorIndex == -1) return; // Set the text color. graphics.setColor(currentColor()); theMessage = Format.sprintf("[%03d,%03d] [%#02.2x,%#02x]", new Parameters(messageX).add(messageY) .add((short)messageX).add((short)messageY)); graphics.drawString(theMessage, messageX,messageY); } // paint public boolean mouseDrag(Event e, int x, int y) { messageX = x; messageY = y; // Repaing everything in the window. repaint(); return true; } // mouseDrag public boolean action(Event e, Object arg) { // If the button was clicked, change color... if (e.target == theButton) { changeColor(); return true; } return false; } // mouseMoved synchronized private void changeColor() { if (++colorIndex == someColors.length) colorIndex = 0; theButton.setForeground(currentColor()); repaint(); } // changeColor synchronized private Color currentColor() { return someColors[colorIndex]; } // currentColor }