/*
 * RandomLot.java
 * copyright (c) since 2004 "Kimmy" all right reserved.
 */

/*
<applet code="RandomLot.class" width=400 height=300>
</applet>
*/

import java.applet.*;
import java.awt.*; 
import java.awt.event.*;
  
public class RandomLot extends Applet implements MouseListener, MouseMotionListener{
 
    public boolean sq[][];
    public int length, num;
    public String lot[];

    public Font f;
 
    public Dimension d;
    public Image bi;
    public Graphics bg;
 
    public void init(){
	this.setBackground(Color.white);
	d = this.getSize();
	bi = createImage(d.width, d.height);
	bg = bi.getGraphics();

	length = 10;
	sq = new boolean[d.width/length][d.height/length];
	for(int i=0; i<sq.length; i++){
	    for(int j=0; j<sq[i].length; j++){
		sq[i][j] = true;
	    }
	}

	String dummy[] = {"    BEST!!!", "   LUCKY!!", "     NICE", 
			  " UNLUCKY", "   WORST"};
	lot = dummy;
	num = (int)(lot.length*Math.random());

	f = new Font("TimesRoman", Font.PLAIN, 72);
 
        this.addMouseListener(this);
        this.addMouseMotionListener(this);
    }
                                                                
    public void paint(Graphics g){
	bg.clearRect(0, 0, d.width, d.height);
	bg.setFont(f);
	bg.setColor(Color.red);
	bg.drawString(lot[num], 0, 200);
	bg.setColor(Color.gray);
	for(int i=0; i<sq.length; i++){
	    for(int j=0; j<sq[i].length; j++){
		if(sq[i][j]){
		    bg.fillRect(i*length, j*length, length, length);
		}
	    }
	}
	g.drawImage(bi, 0, 0, this);
    }

    public void update(Graphics g){
	paint(g);
    }

    public void mouseClicked(MouseEvent e){
	int x = e.getX()/length;
	int y = e.getY()/length;
	sq[x][y] = false;
	repaint();
    }
    public void mouseEntered(MouseEvent e){}
    public void mouseExited(MouseEvent e){}
    public void mousePressed(MouseEvent e){
	//mouse = true;
    }
    public void mouseReleased(MouseEvent e){
	//mouse = false;
    }
    public void mouseDragged(MouseEvent e){
	int x = e.getX()/length;
	int y = e.getY()/length;
	sq[x][y] = false;
	repaint();
    }
    public void mouseMoved(MouseEvent e){}

}







