• Log in or sign up for an account here: https://www.sythe.org/login

Mouse Listeners?

Jimmy

Ghost

Retired Sectional Moderator
$5 USD Donor
Joined
Jun 24, 2008
Sythe Gold
25
Messages
2,421
Location
Psychocyberspace
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
 
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?
 
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!");
	}
    }
 
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.
 
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 =|
 
Well upon checking the API I don't see any getComponent() method in the Applet class that takes two arguments.

Applet API: http://java.sun.com/javase/6/docs/api/java/applet/Applet.html

It does however inherit a getComponent() method that takes one argument (link), perhaps try that instead.

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
 
Runescape Gamblingrunescape gambling
Back
Top