• Post Reply Bookmark Topic Watch Topic
  • New Topic

what will happen if i run it ?  RSS feed

 
Raveendran Karunakaran
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.applet.*;
import java.awt.event.*;
import java.awt.*;
public class Test extends Applet implements Runnable, ActionListener {
public int x = 1;
Thread t1;
public int value =1;
public void init() {
Button button = new Button("ravi");
add(button);
button.addActionListener(this);
//printer();
}
public void start() {
t1 = new Thread(this);
t1.start();
}
public void printer() {
while(true) {
System.out.println("ravi");
}
}
public void run() {
while(true){
x++;
repaint();
printer();
try {
// Thread.sleep(1000);
t1.sleep (1000);
} catch (InterruptedException e){
// the VM doesn't want us to sleep anymore,
// so get back to work
}
}
}
public void actionPerformed(ActionEvent event){
if(event.getActionCommand() == "ravi"){
if (value==1){
t1.suspend();
value=0;
}else{
t1.resume();
value=1;
}
}
}
public void paint(Graphics g) {
g.drawString(String.valueOf(x),10,10);
g.drawLine(10,100,100,x);
g.drawLine(x,10,20,100);
}
}
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At one glance, it looks like printer() will run indefinitely on the t1 Thread. There's no reason for it to return.
------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!