473,503 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Weird Problem in using MouseListener

Hi there all, I am having a weird problem in the following Applet
code,

<begin code>

public class MouseInputTester extends java.applet.Applet {
private String msg = "";
private int mouseX ;
private int mouseY;
static int i = 0;

public MouseInputTester() {
this.addMouseListener(new MouseInput());
}
private class MouseInput implements java.awt.event.MouseListener{
private void setMousecoords(java.awt.event.MouseEvent me){
mouseX = me.getX();
mouseY = me.getY();
}
public void mousePressed(java.awt.event.MouseEvent me ){
msg += "Mouse Pressed";
setMousecoords(me);
repaint();
}
public void mouseClicked(java.awt.event.MouseEvent me){
// msg="";
msg += "Mouse Clicked ";
setMousecoords(me);
repaint();
}
public void mouseEntered(java.awt.event.MouseEvent me){}
public void mouseExited(java.awt.event.MouseEvent me){}
public void mouseReleased(java.awt.event.MouseEvent me){
msg = "Mouse Released";
setMousecoords(me);
repaint();
System.out.println(msg); // msg should have been set to "" in
paint, but that is justnot happening
}
}
public void paint(java.awt.Graphics g){
g.drawString(msg, mouseX, mouseY);
msg = "";
System.out.println("IN paint" + ++i );
}
}

<end code>

The calls to System.out.println() are for debugging purposes only.

The problem is that when the applet is running, whenever mouse is
clicked the applet shows MouseRelasedMouseClicked, even though I set
the msg to "" whenever paint is called, the line with
System.out.println(msg) in mouseReleased() shows that somehow the call
to repaint() just did not occur, Am I missing any point on how the
paint method works.
I belive it is possibly because of the paint queue, that might be
maintained and from which only the most recent call to paint is
executed.

--
Imanpreet Singh Arora

Even if you are on the right track you are going to get run over, if
you just keep sitting there.
Jul 17 '05 #1
1 2581
mi************@yahoo.com (Minti) wrote in news:e87fc4b0.0402021802.7f5fcc26
@posting.google.com:
Hi there all, I am having a weird problem in the following Applet
code,

<begin code> <snip> <end code>

The calls to System.out.println() are for debugging purposes only.

The problem is that when the applet is running, whenever mouse is
clicked the applet shows MouseRelasedMouseClicked, even though I set
the msg to "" whenever paint is called, the line with
System.out.println(msg) in mouseReleased() shows that somehow the call
to repaint() just did not occur, Am I missing any point on how the
paint method works.
I belive it is possibly because of the paint queue, that might be
maintained and from which only the most recent call to paint is
executed.

Calls to repaint queue up a request for paint to happen.
The paint does not happen immediately, so your listeners cannot depend upon
paint to clear out msg. The paint will occur sometime in the future.
However, multiple requests in the paint queue can be collected together, so
there is not neceesarily a one-to-one correspondence between calls to
repaint and executions of paint.

It is time to come up with a new plan of how to arrange your program.

Good Luck!
--
Ian Shef 805/F6 * These are my personal opinions
Raytheon Company * and not those of my employer.
PO Box 11337 *
Tucson, AZ 85734-1337 *
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2068
by: redneck_kiwi | last post by:
Hi all: I have a really weird problem. I am developing a customer catalog system for my company and as such have delved into sessions for authentication and access levels. So far, I have managed...
3
6944
by: Doug van Vianen | last post by:
I am fairly new to Java but have written an applet that uses 'implements Runnable' to do some timing eg public class Puzzle extends Applet implements Runnable { etc. and also an applet which...
1
2076
by: Kaneda | last post by:
Hello everyone! I have some weird(?) problems, and I am not quite sure if there are due to my errors or maybe a limitation in the .Net framework. I have a ComboBox I need to fill with the...
82
5284
by: nobody | last post by:
Howdy, Mike! mikecoxlinux@yahoo.com (Mike Cox) wrote in message news:<3d6111f1.0402271647.c20aea3@posting.google.com>... > I'm a C++ programmer, and have to use lisp because I want to use >...
1
1516
by: Jeffrey Melloy | last post by:
I recently noticed that in my web app, a \n wasn't getting converted to a <br />. (The problem turned out to be that for this particular record, it was a \r). When I checked out the record in...
13
1944
by: Dmitry Tkach | last post by:
Hi, everybody! Here is a weird problem, I ran into... I have two huge (80 million rows each) tables (a and b), with id as a PK on both of them and also an FK from b referencing a. When I try to...
2
2523
by: Kathy Houtami | last post by:
Hi there I've been encountered with weird compile error using Access 97. The error message is "Member or data member is not found" and it highlighted a line of code that has not be changed and...
10
1831
by: Bonj | last post by:
Hello. I hope somebody can help me on this, because I'm running out of options to turn to. I have almost solved my regular expression function. Basically it works OK if unicode is defined. It...
0
1530
by: vipin sharma | last post by:
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...
0
7192
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
7064
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7261
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,...
1
6974
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5559
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,...
1
4991
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...
0
3158
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3147
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.