Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
909 B
2
Indexable
Never
import java.awt.*;
import java.awt.event.*;

class MouseEventDemo extends Frame implements MouseListener {
    private Label label;

    MouseEventDemo() {
        addMouseListener(this);

        label = new Label();
        label.setBounds(20, 50, 200, 30);
        add(label);

        setSize(300, 300);
        setLayout(null);
        setVisible(true);
    }

    public void mouseClicked(MouseEvent e) {
        label.setText("Mouse Clicked");
    }

    public void mouseEntered(MouseEvent e) {
        label.setText("Mouse Entered");
    }

    public void mouseExited(MouseEvent e) {
        label.setText("Mouse Exited");
    }

    public void mousePressed(MouseEvent e) {
        label.setText("Mouse Pressed");
    }

    public void mouseReleased(MouseEvent e) {
        label.setText("Mouse Released");
    }

    public static void main(String[] args) {
        new MouseEventDemo();
    }
}
Leave a Comment