Abdullah Al- Mamun
mouse event
1 Answer(s)      3 years and 2 months ago
Posted in : Java Beginners

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 Pages:
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
Mouse Listeners
the mouse listeners.   They are usually added to a graphics panel... implement the mouse listener interfaces in your non-panel class and write all... If you only want to listen for one kind of event, it's easy to use
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 Buttons, Modifier Keys
when the event occurred. Mouse scroll controls were first supported in Java 2... Java NotesMouse Buttons, Modifier Keys Mouse Buttons. Java supports up to three mouse buttons. Even if your mouse doesn't have three separate
Event in flex
Event in flex  Hi..... I want to know about What does calling preventDefault() on an event do? How is this enforced? please give me an example for that Thanks   Ans: The methods of the Event class can be used
'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
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
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
Mouse Listener
Mouse Listener  how to move any object with help of mouse but not drag it in an applet
The Mouse
Java NotesThe Mouse The mouse is handled automatically by most components... (and shouldn't care) whether this was from a mouse click on the button, or from..., in a JPanel) and need to know where the user clicks, then you need to know about mouse
Using the jQuery event object
code display event type on mouse click on 'a href 'link : $("... Using the jQuery event object       Using the jQuery event object JQuery
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
Understanding the jQuery event handling mechanism
? An event is an action or occurrence detected by a program. It may be mouse... Understanding the jQuery event handling mechanism       Understanding the jQuery event
Flex terminating event flow example
events on the flex controls and containers. A mouse click event on button... Flex terminating event flow example       In the example below, how to terminate an event flow
jQuery blur event
jQuery blur event In this tutorial , we will discuss how to handle blur event... on any other elements in the page ,it shows an alert box .The blur event is sent... commands, such as the Tab key, or by mouse clicks elsewhere on the page
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...("An event occurred.");   }   ]]></mx:Script>
Flex dispatch event example
dispatchEvent() method. Method works like a driver that drives the event... an event. Method, to dispatch any event on the component can be applied... the method component's id.dispatchEvent(event_ type, boolean value, boolean
jQuery 'select' form event
jQuery 'select' form event In this tutorial, we will discuss about 'select ' form event to display message when we select something inside... was selected" . This is due to the "select" event . selectFormEvent.html
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
MouseListener
the following MouseEvent methods to get x and y coordinates of where the mouse event... Java NotesMouseListener This type of mouse listener is for events which typically don't happen very often -- a mouse button is pressed, released
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
Mouse Drag and Drop
Mouse Drag and Drop       This section illustrates you how to drag and move mouse to draw.... The class MouseEvent provides different methods for mouse actions and all the actions
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
Chart Item Event in Flex4
Chart Item Event in Flex4: Chart uses the ChartItemEvent when you perform the operation click on the chart Item. This event is the part of chart package. ChartItemEvent is used by the mx.charts.events package. If your mouse
Flex Add Event Listener example
in flex components. Here in the example only mouse event is added in the components, so whenever a mouse click occurs on the components in which the events... on it. Event listeners are the methods or functions in which events are added
SWT "Enter" key event - Swing AWT
the enter key event? My requirement is , I want some SWT button action...) { switch (keyCode) { /* Keyboard and Mouse Masks */ case SWT.ALT... listener = new Listener() { public void handleEvent(Event e
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
event handling
event handling  diff btwn event handling in ASP.net and in HTML
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... mouse pointer then select Direct selection tool (A key) and adjust the points
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 in flex
Event in flex  Hi..... can you tell me about that How do you make component participate in event mechanism? Thanks   Ans: Extend EventDispatcher or any subclass of it or implement IEventDispatcher
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
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
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
jQuery bind event
'bind' function. When any of the event occurs , the action associated with that event will fire. When mouse enter into it's area , it will change...jQuery bind event In this tutorial, we will discuss about how to bind multiple
Event helpers
Event helpers       Event helpers As we all know events are actions or occurrences detected by a program. And event handlers are methods which handles
Chart Event in Flex4
Chart Event in Flex4: Chart uses the chartEvent when you perform the operation click and doubleclick on the chart. This event is the part of chart package. ChartEvent is used by the mx.charts.events package. If your mouse sensitivity
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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.