Practical No.11 (AJP)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Practical no.

11
import java.awt.*;
import java.awt.event.*;
public class ClickCounter extends Frame implements MouseListener {
private int clickCount = 0;
private Label label;
public ClickCounter() {
setTitle("Click Counter");
setSize(300, 200);
setLayout(new FlowLayout());
setVisible(true);
label = new Label("Number of clicks: 0");
add(label);
addMouseListener(this);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
}}); }
public void mouseClicked(MouseEvent e) {
clickCount++;
label.setText("Number of clicks: " + clickCount);
}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public static void main(String[] args) {
new ClickCounter();
}}

import java.awt.*;
import java.awt.event.*;
public class MouseMotionDemo extends Frame implements MouseMotionListener {
Label label;
public MouseMotionDemo() {
setTitle("Mouse Motion Demo");
setSize(400, 300);
setLayout(new FlowLayout());
setVisible(true);
label = new Label("Move or drag the mouse");
add(label);
addMouseMotionListener(this);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
} }); }
public void mouseDragged(MouseEvent e) {
label.setText("Mouse dragged at: (" + e.getX() + ", " + e.getY() + ")");
}
public void mouseMoved(MouseEvent e) {
label.setText("Mouse moved at: (" + e.getX() + ", " + e.getY() + ")");
}
public static void main(String[] args) {
new MouseMotionDemo();
}}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy