This week's giveaway is in the Testing forum.
We're giving away four copies of TDD for a Shopping Website LiveProject and have Steven Solomon on-line!
See this thread for details.
Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

[applet]....

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import java.applet.Applet;
import java.awt.*;
public class Test extends Applet {
private String text = "Hello World";
public void init() {add(new Label(text));}
public Test (String string) {text = string;}
}
The code complie without error but runtime exception.
Why?What's wrong?
-------------------------
thanks in advance
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It does compile. You must run the applet in a Browser or appletviewer. After compiling it make an html page.
This applet won't display anything. Probably because the applet starts in init and you have a constructor. The applet is confused. I'm not exacly sure about this. But if you remove the constructor the applet will print hello world when it runs!
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The prooblem is not even defining a constructor in an applet. The problem is, the constructor is expecting a parameter which of course is not provided. Thats why its showing runtime error.
If you change it to a no parameter constructor it will work fine. Like this
import java.applet.Applet;
import java.awt.*;
public class Test extends Applet {
private String text = "Hello World";
public void init() {add(new Label(text));}
public Test () {text = "Hello world, constructor";}
}
[This message has been edited by Asma Zafar (edited August 18, 2001).]
[This message has been edited by Asma Zafar (edited August 19, 2001).]
 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic