0% found this document useful (0 votes)
45 views

Practical No.11 (AJP)

Advance java programming practical

Uploaded by

sangramsurwase47
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Practical No.11 (AJP)

Advance java programming practical

Uploaded by

sangramsurwase47
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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