0% found this document useful (0 votes)
31 views4 pages

Practical 11

Uploaded by

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

Practical 11

Uploaded by

Madhur Bhoskar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Advanced Java Programming

Name :Krishna Raut CO5I Roll No. : 25

Q. Write a program to demonstrate various mouse events


CODE:
import javax.swing.*;
import java.awt.event.*;

public class practical11A extends JFrame implements MouseListener


{ private JLabel label;

public practical11A()
{ setTitle("Mouse Demo");
setSize(300, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(null);
label = new JLabel("Hello Mouse");
label.setBounds(50, 150, 200,
100); add(label);
addMouseListener(this);`
}

public void mousePressed(MouseEvent e) {


label.setText("Mouse Pressed; # of clicks: " + e.getClickCount() +
" at position " + e.getX() + ", " + e.getY());
}

public void mouseReleased(MouseEvent e) {


label.setText("Mouse Released; # of clicks: " + e.getClickCount());
}
Advanced Java Programming

public void mouseEntered(MouseEvent e)


{ label.setText("Mouse Entered");

public void mouseExited(MouseEvent e)


{ label.setText("Mouse Exited");
}

public void mouseClicked(MouseEvent e) {


label.setText("Mouse Clicked; # of clicks: " + e.getClickCount());
}

public static void main(String[] args)


{ practical11A frame = new
practical11A(); frame.setVisible(true);
}
}
OUTPUT:
Advanced Java Programming

Q.Program to count the number of clicks performed by the user in a frame


window.
CODE:
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class practical11B extends Frame implements MouseListener


{ int flag = 0;
Label l;
practical11B() {
l = new Label();
add(l);
addMouseListener(this);
setVisible(true);
setSize(400, 400);
setLayout(new FlowLayout());
}

public void mousePressed(MouseEvent e) {


}

public void mouseReleased(MouseEvent e) {


}

public void mouseEntered(MouseEvent e) {


}
Advanced Java Programming

public void mouseExited(MouseEvent e) {


}

public void mouseClicked(MouseEvent e) {


setBackground(Color.ORANGE);
flag++;
l.setText("NO. OF CLICKS:) = " + flag);
}

public static void main(String[] args) {


new practical11B();
}
}
OUTPUT:

You might also like