aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Add Component (Label ...) dynamically at runtime to an applet ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Add Component (Label ...) dynamically at runtime to an applet ?" Watch "Add Component (Label ...) dynamically at runtime to an applet ?" New topic
Author

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

felicitas
Greenhorn

Joined: Sep 05, 2000
Posts: 3
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

Joined: May 06, 2000
Posts: 396
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
 
 
subject: Add Component (Label ...) dynamically at runtime to an applet ?