1. Post #1
    DanielPinoy's Avatar
    May 2009
    1,048 Posts
    Hey guys. I'm trying to make an applet where Main class gets input from Mouse clicks processed in another class called Mouse. The problem is, The number of clicks from the Mouse class doesn't update when I run it. I'm only running the Main applet. Only the number of clicks are updated inside the Main class. I'm new to Java programming, how do I make this work? Thanks.
    Main
    Code:
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    
    
    public class Main extends Applet
    {
    	private Image dbImage;//BUFFER ANTIFLICKER CODE
    	private Graphics dbg;//BUFFER ANTIFLICKER CODE
    
    
    	public void update (Graphics g)
    	{
    	}
    
    	public void init()
    	{
    	}
    	public void paint(Graphics g)
    	{
    		Keyboard keyIO = new Keyboard();
      		Mouse mouseIO = new Mouse();
     		Expo.drawString(g,"Implement out: " + mouseIO.numClick(),400,200);
     		Expo.drawString(g,"Local : " + numClick1(),400,300);
     		repaint();
    	}
    	//-----------MOUSE LISTENER-----------
    	int numClicks;
    	public int numClick1()
    	{
    		return numClicks;
    	}
    	public boolean mouseDown(Event e, int x, int y)
    	{
    		numClicks++;
    		return true;
    	}
    	public boolean mouseDrag(Event e, int x, int y)
    	{
    		return true;
    	}
    	//-----------MOUSE LISTENER-----------
    }
    Mouse
    Code:
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    
    
    public class Mouse extends Applet
    {
    	public void update (Graphics g)
    	{}
    	int numClicks;
    	public int numClick()
    	{
    		return numClicks;
    	}
    	public boolean mouseDown(Event e, int x, int y)
    	{
    		numClicks++;
    		repaint();
    		return true;
    	}
    	public boolean mouseDrag(Event e, int x, int y)
    	{
    		return true;
    	}
    
    
    }
    So basically if I run the applet and clicks on it a few times, only one updates, the one inside the Main class.

  2. Post #2

    April 2012
    56 Posts
    I'm not sure what you expect here.

    Java does not send mouse events to all Classes which extends Applet.
    You initialize but do not show the class "Mouse". You would not be able to click both different GUI's anyway. (with one click)

    What exactly do you wish to do?

    If it's adding a mouse listener to this applet, use one of these routines from the Applet class:
    - addMouseListener(MouseListener l)
    - addMouseMotionListener(MouseMotionListener l)
    - addMouseWheelListener(MouseWheelListener l)
    Reply With Quote Edit / Delete Reply Windows Vista Germany Show Events Agree Agree x 1 (list)

  3. Post #3

    May 2012
    1 Posts
    Sounds like a good idea! http://removed.com gagaghann

    (User was permabanned for this post ("Spambot" - Swebonny))
    Reply With Quote Edit / Delete Reply Windows XP United States Show Events Funny Funny x 2Dumb Dumb x 1 (list)