Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Can I add new AWT components to objects already visible on the screen?

0
10 Posted

Can I add new AWT components to objects already visible on the screen?

0
10

Ans : Yes, you can change your program’s interface as the program is running. Like other Java objects, AWT components can be created on the fly and connected to existing objects. To appear on screen, the component must be added to a container that is already on screen. You also need to invoke validate on the container so that it activates its layout manager to take the new component into account. The validate method lets you control when layouts are recalculated . Following is a code fragment that adds or removes a button from a panel named centerPanel: int buttonCount = 0; Panel centerPanel = new Panel(); void addButton() { ++buttonCount; centerPanel.add(new Button(“button ” + buttonCount)); centerPanel.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123