Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Abdullah Al- Mamun
mouse event
1 Answer(s)      4 years and 9 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();
}

}

Advertisement
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
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
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
'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
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
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
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
event handling
event handling  diff btwn event handling in ASP.net and in HTML
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 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
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
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
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
Flex event
Flex event  Hi.... Please tell me about How to create your own event in flex? Thanks
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 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
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
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
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
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>
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
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
 

 

 

DMCA.com