• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Answer :Run time error / why?

 
tian Lau
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.applet.Applet;
import java.awt.*;

public class Sample extends Applet {
private String text = "Hello World";
public void init() {
add(new Label(text));
}
public Sample (String string) {
text = string;
}
}

It is accessed form the following HTML page:

<html>
<title>Sample Applet</title>
<body>
<applet code="Sample.class" width=200 height=200></applet>
</body>
</html>

 
kevin jia
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Applet can't hava constructor with arguments. It can have constructor no arguments.
 
kevin jia
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try the code below, maybe you can find answer.
import java.applet.Applet;
import java.awt.*;
public class Sample extends Applet {
String text;
public void init() {
add(new Label(text));
}
public Sample() {
text = "Hello cruel world!";
}
<html>
<body>
<applet code="Sample.class" width=200 height=200>
</applet>
</body>
</html>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic