In this tutorial, we will illustrate how to handle mouse click event in the awt application.Here in the example below,we implements the left click event of the mouse. When we click "Click Me" button then the text of the label will change from "Mouse click Event" to the text of the generated event source and vice versa.The MouseClick() constructor of MouseClick class is used.The setText(String) method has been used to set the text of the event source to the label.

Java Code: Program to handle mouse click event
import java.awt.*;
import java.awt.event.*;

public class MouseClick {

    Label lbl;

    public static void main(String[] args) {
        MouseClick MC = new MouseClick();

    public MouseClick() {
        Frame f = new Frame("Checking the mouse click");
        Panel p = new Panel();
        Button button = new Button("Click Me");
        button.addMouseListener(new MyMouseListener());
        p.add(button, BorderLayout.NORTH);
        f.add(p, BorderLayout.NORTH);
        lbl = new Label("Mouse click Event");
        f.add(lbl, BorderLayout.CENTER);
        f.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent we) {
        f.setSize(400, 400);

    public class MyMouseListener extends MouseAdapter {

        public void mouseClicked(MouseEvent me) {
            String str = lbl.getText();
            if (str.equals("Mouse click Event")) {
                lbl.setText("You have click the button.");
            } else if (str.equals("You have click the button.")) {
                lbl.setText("Mouse click Event");