Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] Using the Mouse

Started by capn_midnight May 2, 2001 at 7:48 PM 2 replies 350+ views
Original Post
capn_midnight
capn_midnight
Okay, I''ve pieced this code together, just barely, but it doesn''t work right. It compiles, just doesn''t work.
  
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.applet.*;

public class App2 extends Applet implements MouseListener
{
	int x=0,y=0;
	Image img;
	public void init()
	{
		addMouseListener(this);
		img=getImage(getCodeBase(),"knight.gif");
	}
	public void destroy()
	{
		removeMouseListener(this);
	}
	public void paint(Graphics g)
	{
		g.drawImage(img,x,y,this);
	}
	public void mouseReleased(MouseEvent e)
	{
		x=e.getX();
		y=e.getY();
		repaint();
	}
}
		
  
Why won''t it work? AOL, so easy to use, no wonder it''s nothing but a bunch of retards Spyder''s Web Games
c_wraith
c_wraith
That compiles? Really? Huh, It shouldn''t, unless that isn''t complete code. You need to implement ALL of the methods of an interface for it to compile correctly.

You should have these methods in there as well, for it to compile properly.

  
void mouseClicked(MouseEvent e) {}
void mouseEntered(MouseEvent e) {}
void mouseExited(MouseEvent e) {}
void mousePressed(MouseEvent e) {}


capn_midnight
capn_midnight
I figured out the problem. I forgot to move my picture when I moved the applet. Sorry. Actually, I do have that other code in there, I just took it out for the post.
It works, now just need to do some other stuff.

Man, it stinks in this lab today.

AOL, so easy to use, no wonder it''s nothing but a bunch of retards

Spyder''s Web Games

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.