Advertisement

[java] Using the Mouse

Started by May 02, 2001 07:48 PM
2 comments, last by capn_midnight 23 years, 9 months ago
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

[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]

hmm seems ok to me but I don''t really know applets that well. What exactly is the problem? Do you ever see your image?? Maybe it isn''t loading, or maybe it is loading but you give up and quit before it loads up. Or is it displaying but not moving when you click?
Advertisement
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) {}  


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

[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]

This topic is closed to new replies.

Advertisement