Site hosted by Angelfire.com: Build your free website today!
 

PaintApplet

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

public class PaintApplet extends JApplet
    implements MouseListener {
    int count;
    public void init() {
        addMouseListener(this);
        count = 0;
    }

    public void paint(Graphics g) {
        g.drawRect(0, 0, getSize().width - 1,
           getSize().height - 1);
        g.setColor(Color.red);
        g.fillRect(10, 10, getSize().width - 20,
           getSize().height - 20);
        Font font = new Font ("SansSerif", Font.BOLD, 26);
        g.setFont(font);
        g.setColor(Color.blue);
        g.drawString("Count = " + count, 15, 40);
    }
    public void mouseEntered(MouseEvent event) { }
    public void mouseExited(MouseEvent event) { }
    public void mousePressed(MouseEvent event) { }
    public void mouseReleased(MouseEvent event) { }
    public void mouseClicked(MouseEvent event) {
        count++;
        if (count > 10) 
            jumpToUrl();
        else
            repaint();
    }
    private void jumpToUrl() {
        URL u = null;
        try {
            u = new URL("http://www.google.com");
        } catch (Exception _ex) {
        }
        getAppletContext().showDocument(u);
    }
}

/* Create a web page with the following content
This is the PaintApplet Applet
<br>
<applet code="PaintApplet.class"
        width="300" height="300">
        <param name="fontColor" value="006080">
</applet>

*/