Sorry for my bad english....
This applet adds the label each time you restart, because it is rerun the start method.
import javax.swing.JApplet; import javax.swing.JLabel; import javax.swing.BorderFactory; import java.awt.GridLayout; import java.awt.Color; import java.awt.Font; public class Example extends JApplet { private JLabel label1; private JLabel label2; private JLabel label3; class Etichetta extends JLabel { Etichetta (String nomeFont, int dim, Color fg, Color bc) { super("Ehiiiii!"); setHorizontalAlignment(JLabel.CENTER); setForeground(fg); setFont(new Font(nomeFont, Font.BOLD, dim)); setBorder(BorderFactory.createMatteBorder(1, 1, 2, 2, bc)); } } public void init() { label1 = new Etichetta("Courier", 48, Color.blue, Color.yellow); label2 = new Etichetta("Verdana", 36, Color.yellow, Color.red); label3 = new Etichetta("Times New Roman", 60, Color.red, Color.blue); } public void start() { getContentPane().setLayout(new GridLayout(3, 1, 5, 5)); getContentPane().setBackground(Color.green); getContentPane().add(label1); getContentPane().add(label2); getContentPane().add(label3); } }
The method should be changed to "inform" to add them only when you first start.
But I can not find the way ....