Weird Problem in using MouseListener

From: Minti (mintiSPAMBLOCK_at_yahoo.com)
Date: 02/03/04

  • Next message: mali_djuro: "Re: JDOM and &qout;"
    Date: 2 Feb 2004 18:02:13 -0800
    
    

    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.
    

  • Next message: mali_djuro: "Re: JDOM and &qout;"

    Relevant Pages

    • Weird Problem in using MouseListener
      ... public class MouseInputTester extends java.applet.Applet { ... private int mouseX; ... public void mousePressed{ ... paint, ...
      (comp.lang.java.programmer)
    • Re: Multi-Threading problem
      ... private int seconds=0; ... private void secondsThread() { ... final MyClock myClock=new MyClock; ... public void run ...
      (comp.lang.java.programmer)
    • Cant compile (text to graphic window)
      ... I get the following error message when I try to compile the code below: ... {private int width; ... public void paintComponent ...
      (comp.lang.java.help)
    • Re: Problems adding a timer
      ... > private Button PushButton1; ... > public void paint{ ... > private int x; ...
      (comp.lang.java.gui)
    • Re: Problems adding a timer
      ... > private Button PushButton1; ... > public void paint{ ... > private int x; ...
      (comp.lang.java.programmer)