Java Blog

 
 
 
/* <applet code=\"SimpleClick\" height=100 width=400> </applet> */

import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.applet.Applet;
import java.awt.Graphics;

public class SimpleClick extends Applet implements MouseListener {

    StringBuffer buffer;

    public void init() {
    addMouseListener(this);
    buffer = new StringBuffer();
        addItem(\"initializing... \");
    }

    public void start() {
        addItem(\"starting... \");
    }

    public void stop() {
        addItem(\"stopping... \");
    }

    public void destroy() {
        addItem(\"preparing for unloading...\");
    }

    void addItem(String newWord) {
        System.out.println(newWord);
        buffer.append(newWord);
        repaint();
    }

    public void paint(Graphics g) {
    //Draw a Rectangle around the applet\'s display area.
        g.drawRect(0, 0, 
           getSize().width - 1,
           getSize().height - 1);

    //Draw the current string inside the rectangle.
        g.drawString(buffer.toString(), 5, 15);
    }

    //The following empty methods can be removed
    //by implementing a MouseAdapter (usually done
    //using an inner class).
    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) {
    addItem(\"click!... \");
    }
}

    Related Post:
  1. Program to show an example of using constructors in a class to initialize its data members

  2. Program to show an example of using Abstract Class and Abstract Method

  3. Program of reading and writing primitive data

  4. Program of linear search

  5. CORBA based application for addition of two mathematical expressions of the form (ax + by) and displaying the result on client side

  6. Program to show the use of operator (&gt;&gt;) Shift Right, propagating the sign bit from the left

  7. Program of inventory management and demonstrating interactive input and output

  8. File handling program to count number of characters in a file

  9. Corba program of Count Client Applet, IDL,Server, Client

  10. Program to show the use of some Math Methods

  11. Program to display following things on the client machine a)date and time of the server machine b)date and time of the client machine and difference

  12. Program to show the use of Switch Statement for the same statement for several different case labels

  13. Corba program to encrypt the text that you want to send on the client side. The server side decrypts it after receiving. Append server time.

  14. Program to represent a bank account

  15. Program to show the use of Conditional OR Operator (||) in If Statements

  16. Program sets up a String variable containing a paragraph of text of your choice. Extract the words from the text and sort them into alphabetical order

  17. An applet program to draw concentric circle in center of the canvas

  18. Program to show an example of getting at characters in a String

  19. Program to show an example of using a Static Nested Class outside the Top-Level Class

  20. Program to show the use of Conditional (Ternary) Operator

 
 
Didn't find what you were looking for? Find more on An applet program showing Clicked Event on canvas