mouse event

mouse event

import javax.swing.*;
import java.awr.*;
import java.awt.event.*;


public class MouseEventt extends JFrame
{
JButton btnClose=new JButton("Close");


public MouseEventt()
{
Container c=getContentPane();
setLayout(new FlowLayout());
setTitle("Mouse Event");
setDefaultCloseOperation(JFFrame.EXIT_ON_CLOSE);
pack();
setVisible(true);


btnClose.addMouseMotionListener(new MouseMotionListener()
{
public void mousePressed(MouseEvent me)
{
x=e.getX();
y=e.getY();
repaint();
}

public void mouseClicked(MoueEvent me)
{
if(w.getClickCount()==2)
size=10;
else size=4;
repaint();
}

public void mouseEntered(MouseEvent me)
{
c.setBackground(Color.yellow);
}

public void mouseExited(MouseEvent me)
{
c.serBackground(Color,black);
}

public void mouseReleased(MouseEvent me)
{

}
});

}

public static void main(String args[])
{
MouseEventt mm=new MouseEventt();
}

}
View Answers

March 22, 2010 at 11:11 AM

Hi Friend,

Try the following code:

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


public class MouseEventt
{
JFrame f=new JFrame();
JButton btnClose=new JButton("Close");


public MouseEventt()
{
f.setLayout(new FlowLayout());
f.setTitle("Mouse Event");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(btnClose);
f.pack();
f.setVisible(true);



btnClose.addMouseListener(new MouseListener()
{
public void mousePressed(MouseEvent me)
{
int x=me.getX();
int y=me.getY();
f.repaint();
}

public void mouseClicked(MouseEvent me)
{
int size=0;
if(me.getClickCount()==2)
size=10;
else size=4;
f.repaint();
}

public void mouseEntered(MouseEvent me)
{
f.getContentPane().setBackground(Color.yellow);
}

public void mouseExited(MouseEvent me)
{
f.getContentPane().setBackground(Color.black);
}

public void mouseReleased(MouseEvent me)
{

}
});

}

public static void main(String args[])
{
MouseEventt mm=new MouseEventt();
}

}

Thanks









Related Tutorials/Questions & Answers:
mouse event - Java Beginners
=getContentPane(); setLayout(new FlowLayout()); setTitle("Mouse Event...mouse event  import javax.swing.*; import java.awr.*; import..."); public MouseEventt() { f.setLayout(new FlowLayout()); f.setTitle("Mouse
Auto select cell on mouse hover using 'hover' mouse event
Auto select cell on mouse hover using 'hover' mouse event In this tutorial, we will discuss about how to highlight Table's cell on mouse hover using jQuery 'hover' mouse event. In this example, a table is given
Advertisements
Change JPanel background color from mouse entered/exit event
Change JPanel background color from mouse entered/exit event  I have a JPanel with a grid layout and I populated it with anonymous JPanels to it be like tiles on a game board. I added a mouse entered event to all the added
Handling Mouse Clicks in Java
the mouse click event in the awt application. This program simply implements the left click event of the mouse. When you click "Click Me" button... Handling Mouse Clicks in Java     
jQuery '.live' & '.die' Mouse events
jQuery '.live'  & '.die' Mouse events In this tutorial ,we will discuss about how to  remove an event using 'die' mouse event of jQuery. In this Example, we removes the 'click' event
Mouse Listener
Mouse Listener  how to move any object with help of mouse but not drag it in an applet
Mouse Motion
Mouse Motion  Could you please send me the code of finding the (x,y) co-ordinates in a JFrame Compoenent..?? I need it urgently for my project
mouse events
mouse events  When i click a button i want to retrieve image and audio from database and play it. how can i do dis. I m using Netbeans IDE and mysql for database. pls do hel[p me
how to use mouse pressed
how to use mouse pressed   to action mouse clicked
Image swap on mouse over and mouse move
Image swap on mouse over and mouse move  i tried the code , sent form u...But if there are 50 images and..i want swap images on mousse over and mouse out, then the code becomes very lengthy...so please give the code for multiple
Image swap on mouse over and mouse move
Image swap on mouse over and mouse move  i tried the code , sent form u...But if there are 50 images and..i want swap images on mousse over and mouse out, then the code becomes very lengthy...so please give the code for multiple
ModuleNotFoundError: No module named 'mouse'
ModuleNotFoundError: No module named 'mouse'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'mouse' How to remove the ModuleNotFoundError: No module named 'mouse'
mouse over effects in css
mouse over effects in css  I have written a mouse over effect in CSS. But it is not working in HTML. Can any one suggest me? Thanks
Swap images oon mouse over and mouse out
Swap images oon mouse over and mouse out  I have multiple images...i want to swap each image on mouse out and mouse over..   <html> <script language="javascript" type="text/javascript"> if(document.images
ModuleNotFoundError: No module named 'mouse_droid'
ModuleNotFoundError: No module named 'mouse_droid'  Hi, My Python... 'mouse_droid' How to remove the ModuleNotFoundError: No module named 'mouse_droid' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'mouse_record'
ModuleNotFoundError: No module named 'mouse_record'  Hi, My Python... 'mouse_record' How to remove the ModuleNotFoundError: No module named 'mouse_record' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'remarkable-mouse'
ModuleNotFoundError: No module named 'remarkable-mouse'  Hi, My... named 'remarkable-mouse' How to remove the ModuleNotFoundError: No module named 'remarkable-mouse' error? Thanks   Hi, In your
4D Mouse
4D Mouse       Here... mouse is an advanced species of traditional 2D mouse that can move only horizontal no vertical, while 4D mouse can move all the direction ups & down and left
'key down' mouse event of the jQuery
'key down' mouse event of the jQuery In this tutorial ,we will display ASCII value using "key down" method of jQuery. In this example , a text box is given. When you type something or press any key it shows ASCII
How to design a mouse
How to design a mouse Follow this example to learn how to design a mouse. New File: First take a new file (Ctrl + N). Use Pen Tool (P..., point your mouse pointer then select Direct selection tool (A key) and adjust
ModuleNotFoundError: No module named 'mouse_joystick_interface'
ModuleNotFoundError: No module named 'mouse_joystick_interface'  Hi...: No module named 'mouse_joystick_interface' How to remove the ModuleNotFoundError: No module named 'mouse_joystick_interface' error? Thanks  
adding mouse listeners to drop target
adding mouse listeners to drop target  import java.awt.*; import... with adding mouse listeners to "table" which is drop target, to accept drop component wherever it drops from the mouse. in this code when component drops
Event in flex
the word under the mouse pointer at the time of the event. Your event listener can...Event in flex  Hi..... I want to know about What does calling preventDefault() on an event do? How is this enforced?ADS_TO_REPLACE_1 please give
Explore key & mouse with Flex
Explore key & mouse with Flex   ... to determine for a key is pressed or not when an event occurs. In the example... created. Also two MouseEvent class events click and mouse over are used
Program to draw rectangle on each mouse click and erase priviouse rectangles
Program to draw rectangle on each mouse click and erase priviouse rectangles  Program to draw rectangle on each mouse click and erase previous rectangle on next mouse click
Image swap on MouseOver ann Mouse out
Image swap on MouseOver ann Mouse out  I tried ur code for multiple images but didnt get the right answer...i dont want the hardcodded code...a code which is flexible with multiple images <html> <script language
Java Swing: Draw rectangle on mouse click
Java Swing: Draw rectangle on mouse click In this tutorial, you will learn how to draw a rectangle on mouse click. Sometimes, there is a need of mouse clicks in swing applications instead of buttons. To add this mouse interaction, Java
event handling
event handling  diff btwn event handling in ASP.net and in HTML
onmouseover event in jsf
onmouseover event in jsf  hello friends, I am in the middle... & mysql database. can u suggest a code for, If I place mouse on a component I want to dispaly the list of some documents by using onmouseover event in jsf
'append' & 'fade out/in' on mouse hover
'append' & 'fade out/in' on mouse hover In this tutorial...; on mouse hover using jQuery. In this Example, a list is given , if we hover on first two element, "<<<" is appended on it, to show mouse
Event.mxml
;   This tutorial will help you to learn event handling on mouse click. Events can be generated by the user's device like keyboard, mouse... myEventHandler():void {   Alert.show("An event occurred.");  
Change Mouse sensitivity in Chart in Flex4
Change Mouse Sensitivity in Chart in Flex4: You can change the mouse... a slider for changing the value of mouse sensitivity. Example: <...;/fx:Script> <s:Panel title="Change mouse sensitivity
Event Listeners
Event Listeners  I want to learn the Event Listeners in Java. Any... is the good tutorial and example of Event Listeners in Java. Please check the tutorial Java - Event Listeners Example in Java Applet. Thanks
Flex event
Flex event  Hi.... please tell me about How does Flex event system works? Thanks  Ans: When event are triggered there are three...: In the capturing phase, Flex examines an event target?s ancestors in the display list to see
Event management
Event management   Hi, I want event management application like maintaining email notifications while task creation and update in broader way using spring java
Flex event
Flex event  Hi... please give me the answer with example What is event Bubbling? Thanks in advance  Event Bubbling: In the bubbling phase, Flex examines an event?s ancestors for event listeners. Flex starts
Flex event
Flex event  hi...... How to capture and event if the component is disabled? please give an example..... Thanks in advance
Flex event
Flex event  Hi.... Please tell me about How to create your own event in flex? Thanks
Event in flex
Event in flex  Hi..... can you tell me about that How do you make component participate in event mechanism?ADS_TO_REPLACE_1 Thanks   Ans: Extend EventDispatcher or any subclass of it or implement IEventDispatcher
Version of d-haven-event>event dependency
List of Version of d-haven-event>event dependency
Version of excalibur-event>excalibur-event dependency
List of Version of excalibur-event>excalibur-event dependency
Click event
Click event  hi............ how to put a click event on a particular image, so that it can allow to open another form or allow to display result in tabular form????????/ can u tell me how to do that????????/ using java swings
SplitButton of dropdownbutton invisible when mouse clicking - Swing AWT
SplitButton of dropdownbutton invisible when mouse clicking  click the SplitButton of dropdownbutton, when dropdownmenu willbe displayed. but this is not disabled when mouevent performed on the jpanel how to disabled or hide
Java event handling
Java event handling  What event results from the clicking of a button
How to Handle Event Handlers?
How to Handle Event Handlers?  How to Handle Event Handlers
handling Button Event in iphone
handling Button Event in iphone  handling Button Event in iphone
Java event-listener
Java event-listener  What is the relationship between an event-listener interface and an event-adapter class
Java event delegation model
Java event delegation model  What is the highest-level event class of the event-delegation model
Version of excalibur-event>excalibur-event-api dependency
List of Version of excalibur-event>excalibur-event-api dependency
Version of excalibur-event>excalibur-event-impl dependency
List of Version of excalibur-event>excalibur-event-impl dependency

Ads