Adblock breaks this site

Mouse Listeners?

Discussion in 'Programming General' started by Jimmy, Mar 27, 2009.

  1. Jimmy

    Jimmy Ghost
    Retired Sectional Moderator $5 USD Donor

    Joined:
    Jun 24, 2008
    Posts:
    2,421
    Referrals:
    10
    Sythe Gold:
    25
    Mouse Listeners?

    Alright..... I'm making a bot, and I've added a mouse listener to the jpanel that loads the rs applet. The problem is that the mouse listener only gets events from the panel, and not the applet, and I cannot add the mouse listener directly to the applet, because the mouse listener is what loads the jpanel and jframe of the bot.

    It's a bit confusing to explain. My code : http://uppit.com/H07PAU
     
  2. Nullware

    Nullware Guru

    Joined:
    Jan 30, 2007
    Posts:
    1,761
    Referrals:
    4
    Sythe Gold:
    0
    Mouse Listeners?

    Well the mouse listener is supposed to only work for each component that it is added to and since the applet is a component and you don't add it then I wouldn't think it's possible another way. I don't understand why you can't add it to the applet?
     
  3. Jimmy

    Jimmy Ghost
    Retired Sectional Moderator $5 USD Donor

    Joined:
    Jun 24, 2008
    Posts:
    2,421
    Referrals:
    10
    Sythe Gold:
    25
    Mouse Listeners?

    Because

    Code:
    Mouse listener = new Mouse();
    gui.create gui = new gui.create();
    gui.panel.addMouseListener(listener);
    gui.panel.addMouseMotionListener(listener);
    is how I load the GUI, and if I added it to the applet, how would I load that same applet in the gui?

    EDIT: I tried loading the MouseListener's to the applet and it still didn't work -.-
    Code:
    panel.setLayout(new BorderLayout());
    botStub.rs.addMouseListener(listener);
    botStub.rs.addMouseMotionListener(listener);
    panel.add(botStub.rs);
    EDIT:EDIT: I added the listener in the class that loads the Applet and it only works if I move the mouse on the black space surrounding the applet, but not the applet itself!

    Code:
        public botStub() {
    	try {
    		bot.Mouse listener = new bot.Mouse();
    		client = Class.forName("client");
    		rs = (Applet) client.newInstance();
    		params = new Properties();
    		rs.setStub(this);
    		rs.init();
    		rs.start();
    
    		rs.addMouseListener(listener);
    		rs.addMouseMotionListener(listener);
    	} catch (Exception e) {
    		System.out.println("Error!");
    	}
        }
     
  4. Nullware

    Nullware Guru

    Joined:
    Jan 30, 2007
    Posts:
    1,761
    Referrals:
    4
    Sythe Gold:
    0
    Mouse Listeners?

    What if you added the mouse listener before calling the applet's init() and start() methods. I don't think it really should matter but I don't know that much about applets so who knows.
     
  5. Jimmy

    Jimmy Ghost
    Retired Sectional Moderator $5 USD Donor

    Joined:
    Jun 24, 2008
    Posts:
    2,421
    Referrals:
    10
    Sythe Gold:
    25
    Mouse Listeners?

    I asked at Moparisthebest, and it seems that I needed to add the MouseListener to the Canvas by
    Code:
    rs.getComponentAt(1, 1).addMouseListener(listener);[code]
    however, rs.getComponentAt(1, 1) keeps returning null, so I need some help fixing this =|
     
  6. Nullware

    Nullware Guru

    Joined:
    Jan 30, 2007
    Posts:
    1,761
    Referrals:
    4
    Sythe Gold:
    0
    Mouse Listeners?

  7. Jimmy

    Jimmy Ghost
    Retired Sectional Moderator $5 USD Donor

    Joined:
    Jun 24, 2008
    Posts:
    2,421
    Referrals:
    10
    Sythe Gold:
    25
    Mouse Listeners?

    That fixed it :)

    Now I've gotta deal with getting the image from the graphic, adding my mouse to the image, and a whole lotta other shit. :confused:

    Hopefully it won't be too annoying xD
     
  8. slashshot007

    slashshot007 Active Member

    Joined:
    May 6, 2006
    Posts:
    164
    Referrals:
    0
    Sythe Gold:
    0
    Mouse Listeners?

    add the panel to the applet?
     
< What's the Best way to do this? | Need help. >


 
 
Adblock breaks this site