Consider the following Java program. Describe what it does in response to specific operations of the mouse, and how it does it. (You are encouraged to run the program for yourself to test its behavior. Then read through the program carefully to understand how that behavior arises.)
import java.awt.event.*;
import javax.swing.*;
public class MouseWhisperer extends JFrame implements MouseListener
{
MouseWhisperer() {
super("COME
CLOSER");
setSize(300,100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
addMouseListener(this);
setVisible(true);
}
public void mouseClicked(MouseEvent e) {
setTitle("OUCH"); }
public void mousePressed(MouseEvent e) {
setTitle("LET GO"); }
public void mouseReleased(MouseEvent e) {
setTitle("WHEW"); }
public void mouseEntered(MouseEvent e) {
setTitle("I SEE YOU"); }
public void mouseExited(MouseEvent e) {
setTitle("COME CLOSER"); }
public static void main(String[] args) { new
MouseWhisperer(); }
}
Your Discussion should be at least 250 words in length, but not more than 750 words.
In this program we are showcasing the mouse events.
here we implemented the all mouse related events like
mouseClicked,
mousePresses,mouseReleased,mouseEntered,mouseExited
Here we are chaning the title of the window every an event
happends
when mouseClicked event happend we are changing the title to
OUCH
when mousePressed event happend we are changing the title to LET
GO
when mouseReleased event happend we are changing the title to
WHEW
when mouseEntered event happend we are changing the title to I SEE
YOU
when mouseExited event happend we are changing the title to COME
CLOSE
We have done all of the above tasking by creating JFrame and implementing a MouseListener interface which has all of these methods
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME
Get Answers For Free
Most questions answered within 1 hours.