• Post Reply Bookmark Topic Watch Topic
  • New Topic

Which thread Constructor is called?

 
Malli Murugan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
This is the code i wrote:
public class Bounce extends JApplet
implements Runnable {
int x,y;
public void init() {
x = 10 + (int)Math.random();
y = x - 1;
addMouseListener(
new MouseAdapter(){
public void mousePressed(MouseEvent e) {
//start bouncing
Thread t = new Thread(this);
t.start();
}
}
);
}
public void run() {
while( true )
setCoordinates(x,y);
}
//paint method and setCoordinates method follow
Compiler complains :
Incompatible type for constructor. Can't convert Bounce.1 to java.lang.String
Thread t = new Thread(this);

what's wrong here?
 
Paul Keohan
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it might be because you're trying to pass 'this' into the Thread constructor when 'this' at that point represents the anonymous inner class. The inner class does not implement Runnable.
Paul
 
Malli Murugan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I realised it.
Thanks Paul.
Malli
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!