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 the use of operator (&lt;&lt;) Shift Left filling with zero from the right

  2. Program to determine the sum of the following harmonic series for a given value of n

  3. Program to show the use of Nested If-Else Statements

  4. Program to read the table elements into a two-dimensional array temperature

  5. 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.

  6. Word list program that reads a text file and makes an alphabetical list of all the words in that file. The list of words is output to another file

  7. Program which calls the method sort(int []a) which throws the Exception ArithmeticException, NullPointerException, ArrayIndexOutOfBoundsException

  8. Program to show the use of Increment and Decrement Operators

  9. An applet program to display text

  10. Program to show the use of If-Else Statement

  11. Corba program of game

  12. Corba program of date operations

  13. An applet program to display alternate filled and empty circle that to in row and column format

  14. Program to check the start and end of a String

  15. Program to show the use of While Loop

  16. GUI application in java, which enter the details of a student and on the submit display the details of the student

  17. RMI based application for login validation based on data saved in text file stored on the server and will display appropriate message to the client..

  18. RMI program of count server and client

  19. Program to find a factorial of a given number

  20. Program that accepts a shopping list of five items from the command line and stores them in vector

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