• Post Reply Bookmark Topic Watch Topic
  • New Topic

Frame & Applet

 
Thiru Thangavelu
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why "hello world" is not printed when the constructor is present?

[ June 12, 2002: Message edited by: Thiru Thangavelu ]
[ June 12, 2002: Message edited by: Thiru Thangavelu ]
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shouldn't that be text=s;
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The default constructor is needed. Otherwise, how the browser is going to pass the parameter?
 
Thiru Thangavelu
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it is text = s
Why do we need the default constructor since we have the string "hello world" as parameter text. I think I am missing some concept here.
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not needed for setting the value of text, but in case the applet is going to be executed by a browser.
 
Brusk Baran
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Applet vs Application??
I converted the applet so that it can be run as an application too.
is this allowed???
import java.awt.*;
import java.applet.Applet;
public class TestAppletMain extends Applet {
private String text = "Hello World";
public void init() {
add(new Label(text));
}
/*
public TestAppletMain (String s) {
text = s;
}
*/
public static void main(String args []){
TestAppletMain ss = new TestAppletMain ();
ss.init();
}
}
 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!