This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes label(why is it not added?) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "label(why is it not added?)" Watch "label(why is it not added?)" New topic

label(why is it not added?)


Joined: Apr 11, 2002
Posts: 4
why doesn't the following code add a label?
public class LabelTester implements Runnable{
Label l=new Label("asdfd");
Thread t;
public void init()
t=new Thread(this);
public void run()
for(int i=0;;i++)
what should it do according to u?
Rajendar Goud
Ranch Hand

Joined: Mar 06, 2002
Posts: 220
Hi ,
To add any component in AWT or swing ,u need to place them on a u need to extend the Frame class to see the the
code should be as follows,
//public class LabelTester implements Runnable
public class LabelTester extends Frame implements Runnable
and also
to make the Frame visible.
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121


Please re-register with a name that follows the JavaRanch User Name Guidelines... your user name is required to be in the format "First Name" + space + "Last Name" and should not look obviously fake.

Since you are using "init()" it looks like you were trying to make an applet... you have to make your class extend Applet in orfer to do this. And you have to add your label to the applet to have it show up.

Here's some test code to show you how to do it... you can ignore the main method if you just want to run the applet from a web page...


Write once, run anywhere, because there's nowhere to hide! - /. A.C.
I agree. Here's the link:
subject: label(why is it not added?)
It's not a secret anymore!