This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Which thread Constructor is called?  RSS feed

 
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!