Practical No.11 (AJP)
Practical No.11 (AJP)
Practical No.11 (AJP)
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();
}}