HELP: How to add one more BUTTON dynamically?

Hi Friends,

I wanna add a new button once if I click the other button, say called ADD, in my applet. So I wrote the following code,

Panel create()

{

Button b = null;

b = new Button("button_" + listOfButtons.size());

b.addActionListener(listener);

add("North", b);

listOfButtons.add(b);

doLayout();

System.out.println("No of Buttons: " + listOfButtons.size() + "\n");

return this;

}

The function create() will be called when I clicked the button 'ADD'. There is no error here.

But the display did not change yet. There is only one button created in init. But it shows that the Vector listOfButtons can store buttons.

What should I do to have a screen of dynamic array of buttons?

Law. T.

[806 byte] By [diffservhk] at [2007-9-26 1:38:12]
# 1
You must validate() and repaint() container where you add the new button.Hope this helps
R2D2 at 2007-6-29 2:25:53 > top of Java-index,Desktop,Core GUI APIs...
# 2
How do I add those 2 things in my codes?
diffservhk at 2007-6-29 2:25:53 > top of Java-index,Desktop,Core GUI APIs...
# 3
create() return a panel... what do you do with it?... you add a applet or a frame.... then you call applet.revalidate; applet.repaint or frame.revalidate.....Hope this help
R2D2 at 2007-6-29 2:25:53 > top of Java-index,Desktop,Core GUI APIs...