Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Add Component (Label ...) dynamically at runtime to an applet ?

 
felicitas
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
how to add a Component (Label ...) dynamically at runtime to an applet ? I've tried various possibilities, but I haven't had any success.
Thanks, Felicitas
 
deekasha gunwant
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi felicitas,
after adding the component at run time u need to invalidate() and validate() the applet.
here is a working code which u can run and see
------------------------------------------------------------
java file
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class DynApplet extends Applet
{
Button b = new Button("Label Generater");
public DynApplet()
{
add(b);
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae)
{
DynApplet.this.add(new Label("Nascent Label"));
System.out.println("label Added");
DynApplet.this.invalidate();
DynApplet.this.validate();

}
});
}

}
html file
html
applet
code = DynApplet.class
width = 300
height = 200
applet
/html
------------------------------------------------------------
regards
deekasha
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic