473,406 Members | 2,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Problem in mouselistener and windowllistener event handling

hello all,

Just for learning purpose I am making a gui in which wherever a user click on window a text " mouse clicked" will appear at current position of mouse pointer.

I have used listener interfaces.

Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import java.applet.*;
  4.  
  5. public class MouseEvents extends Frame implements MouseListener,WindowListener{
  6.  
  7.      String ss = "mouse clicked";
  8.     int mousex,mousey;
  9.  
  10.     public void windowClosed(WindowEvent e) {
  11.         throw new UnsupportedOperationException("Not supported yet.");
  12.     }
  13.  
  14.     public void windowDeiconified(WindowEvent e) {
  15.        throw new UnsupportedOperationException("Not supported yet.");
  16.     }
  17.  
  18.     public void windowIconified(WindowEvent e) {
  19.         throw new UnsupportedOperationException("Not supported yet.");
  20.     }
  21.  
  22.     public void windowOpened(WindowEvent e) {
  23.         throw new UnsupportedOperationException("Not supported yet.");
  24.     }
  25.  
  26.     public void windowDeactivated(WindowEvent e) {
  27.         throw new UnsupportedOperationException("Not supported yet.");
  28.     }
  29.  
  30.     public void windowActivated(WindowEvent e) {
  31.         throw new UnsupportedOperationException("Not supported yet.");
  32.     }
  33.  
  34.     public void windowClosing(WindowEvent e) {
  35.         System.exit(0);
  36.     }
  37.  
  38.     public void mouseExited(MouseEvent e) {
  39.         throw new UnsupportedOperationException("Not supported yet.");
  40.     }
  41.  
  42.     public void mousePressed(MouseEvent e) {
  43.         throw new UnsupportedOperationException("Not supported yet.");
  44.     }
  45.  
  46.  
  47.     public void mouseClicked(MouseEvent e) {
  48.     mousex = e.getX();
  49.     mousey = e.getY();
  50.         repaint();
  51.     }
  52.     @override
  53.     public void paint(Graphics g){
  54.         g.drawString(ss, mousex, mousey);
  55.     }
  56.     public void mouseEntered(MouseEvent e) {
  57.         throw new UnsupportedOperationException("Not supported yet.");
  58.     }
  59.  
  60.     public void mouseReleased(MouseEvent e) {
  61.         throw new UnsupportedOperationException("Not supported yet.");
  62.     }
  63.  
  64.     public void MouseEvents(){
  65.         addMouseListener(this);
  66.         addWindowListener(this);
  67.     }
  68. public static void main(String args[]){
  69.     MouseEvents ee = new MouseEvents();
  70.     ee.setSize(500, 500);
  71.     ee.setVisible(true);
  72.  
  73. }
  74.  
  75. }

But this code is not working according to expectations. I am not getting "mouse clicked" text and window doesn't get closed. I think my listener is not getting registered in my program. Also I have to use @Override at line 52 other wise netbeans is showing message here "multiple annotation here[2] - click to cycle."
Oct 27 '09 #1
0 1524

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Covad | last post by:
Hi all, For some reason my change() function is only called when the page loads. I'd much rather it gets called when the select changes. Here's the code: window.onload = init; function...
2
by: Tim Gallivan | last post by:
Hi group, I'm having a strange problem with event handling. My project has a form with a textbox that creates 25 instances of class A when a button is clicked. Class A raises the event without...
3
by: Ashok Kumar K | last post by:
Hi all, Where can I get some insight on using the __hook, __unhook, event_source and event_receiver for specifically COM events. The documentation given in MSDN is very minimal. I have the...
0
by: luca | last post by:
Hi all. My problem is that I can't handle events raised from child components within a composite server control when the control is created dynamically. Everything works fine if the same control...
9
by: Sridhar | last post by:
Hi, I have created a web page which includes a place holder. I also have a dropdown list in that webpage. when I select one of the choices in that dropdown list, It will load a user control...
2
by: Paul E. Orman | last post by:
I have a piece of VB code (.NET 1.1 - VB 2003) that loads data from a database through a timer. So the timer is setup and from it I call the procedure that loads the latest records from the...
3
by: johncee | last post by:
Greetings, I created a base class that has a datagrid. I've made it generic as possible so that any derived classes pass some info to the base constructor (including a SQL select stmt) &...
4
by: StepanM | last post by:
Problem with event handling in FireFox. I have two controls on HTML page: ListBox and TextBox (<selectand <input>). Both controls have event "onchange" and functions for this event (e.g....
5
by: Klaudiusz Bryja | last post by:
Hi, This is for NetCF 2.0. I need to create event handling code which using reflection. I have some parameters in XML which describe how event should be handled. I have code to create...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.