import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Welcome extends JApplet {
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	String message;  // The message to be displayed.  This can be set in
    // an applet param with name "message".  If no
    // value is provided in the applet tag, then 
    // the string "Java!" is used as the default.
    
    Display drawingSurface;  // This is the component on which the
    // drawing will actually be done.  It
    // is defined by a nested class that
    // can be found below.
    
    public void init() {
        // Called by the system to initialize the applet.

    message = getParameter("message");
    if (message == null)
       message = "Welcome!";

    drawingSurface = new Display();  // Create the drawing surface.
    setContentPane(drawingSurface);  // Since drawingSurface will fill
                                     // the entire applet, we simply
                                     // replace the applet's content 
                                     // pane with drawingSurface.
    } // end init()

    class Display extends JPanel implements MouseListener {
        // This nested class defines a JPanel that is used
        // for displaying the content of the applet.  An
        // object of this class is used as the content pane
        // of the applet.  Note that since this is a nested
        // class, it has access to the instance
        // variables of the main class such as message.
    	
        Display() {
            // This constructor simply sets the background color
            // of the panel to be black and sets the panel to
            // listen for mouse events on itself.
         setBackground(Color.black);
         addMouseListener(this);
     }
        
        
        /* (non-Javadoc)
         * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
         */
        public void mousePressed(MouseEvent evt) {
        	// Since this panel has been set to listen for mouse
        	// events on itself, this method will be called when the
        	// user clicks the mouse on the panel.  (Since the panel
        	// fills the whole applet, that means clicking anywhere
        	// on the applet.)
        	
        	if ( evt.isShiftDown() ) {
        		// The user was holding down the Shift key.  Just
        		// repaint the panel.  Since this class does not
        		// define a paintComponent() method, the method
        		// from the superclass, JPanel, is called.  That 
        		// method simply fills the panel with its background 
        		// color, which is black.  This has the effect of
        		// erasing the contents of the applet.
        		repaint();
        		return;
        	}
        	
        	int x = evt.getX();  // x-coordinate where user clicked.
        	int y = evt.getY();  // y-coordinate where user clicked.
        	
        	Graphics g = getGraphics();  // Graphics context for drawing
        	// directly on this JPanel.
        	
//        	if (evt.isAltDown()) {
//        		g.setColor(Color.CYAN);
//        		g.drawString(message,x,y);
//        	} else if (evt.isControlDown()){
//        		g.setColor(Color.MAGENTA);
//        		g.drawString(message,x,y);
//        	}else { //evt.isMetaDown()
//        		g.setColor(Color.PINK);
//        		g.drawString(message,x,y);
//        	}
        	
        	int red = (int) (Math.random()*256);
        	int green = (int) (Math.random()*256);
        	int blue = (int) (Math.random()*256);
        	g.setColor(new Color(red,green,blue));
        	g.drawString(message,x,y);
        	g.dispose();  // We are finished with the graphics context,
        	//   so dispose of it.
        	
        } // end of mousePressed()
        
        // The next four empty routines are required by the 
        // MouseListener interface.
        
        public void mouseEntered(MouseEvent evt) {return; }
        public void mouseExited(MouseEvent evt) {return; }
        public void mouseClicked(MouseEvent evt) {return; }
        public void mouseReleased(MouseEvent evt) {return; }
        
    }// end of class Display
}


	

