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

PROGRAM9

The document contains a Java program that creates a JFrame which responds to various mouse events such as clicks, presses, releases, and movements. Each event updates a JLabel with the corresponding message and the mouse coordinates. The program demonstrates the use of MouseListener and MouseMotionListener interfaces to handle mouse interactions in a graphical user interface.

Uploaded by

joyalprincess
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)
6 views

PROGRAM9

The document contains a Java program that creates a JFrame which responds to various mouse events such as clicks, presses, releases, and movements. Each event updates a JLabel with the corresponding message and the mouse coordinates. The program demonstrates the use of MouseListener and MouseMotionListener interfaces to handle mouse interactions in a graphical user interface.

Uploaded by

joyalprincess
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/ 3

PROGRAM-9

Write a Java Program to create a frame which responds to the mouse clicks. For
each events with mouse such as mouse up, mouse down, etc, the corresponding
message to be displayed
SOURCE CODE
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class mouse implements MouseListener,MouseMotionListener
{
JFrame j;
JLabel l1;
public mouse()
{
j=new JFrame("Mouse Events");
l1=new JLabel("Mouse on the Frame");
l1.addMouseListener(this);
j.add(l1);
j.setSize(300,400);
j.show();
}
public void mouseClicked(MouseEvent me)
{ l1.setText("Mouse Clicked at"+me.getX()+","+me.getY());
}
public void mousePressed(MouseEvent me)
{ l1.setText("Mouse Pressed at"+me.getX()+","+me.getY());
}
public void mouseReleased(MouseEvent me)
{ l1.setText("Mouse Released at"+me.getX()+","+me.getY());
}
public void mouseEntered(MouseEvent me)
{ l1.setText("Mouse Entered at"+me.getX()+","+me.getY());
}
public void mouseExited(MouseEvent me)
{ l1.setText("Mouse Exited at"+me.getX()+","+me.getY());
}
public void mouseMoved(MouseEvent me)
{ l1.setText("Mouse Moving at"+me.getX()+","+me.getY());
}
public void mouseDragged(MouseEvent me)
{ l1.setText("Mouse Dragged at"+me.getX()+","+me.getY());
}}
class PL9
{
public static void main(String args[])
{
mouse m=new mouse();
}
}
PROGRAM-9-OUTPUT

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