by Dinesh Thakur Category: AWT and Applets

In order to add a component to a container, first create an instance of the desired component and then call the add () method of the Container class to add it to a window. The add () method has many forms and one of these is.

Component add (Component c)

This method adds an instance of component (i.e. c) to the container. The component added is automatically visible whenever its parent window is displayed.

import java.awt.*;

class AddComponent
    public static void main(String args[])
       Frame frame = new Frame("Add Components to a Container");
       Button button = new Button("OK");

Add Components to a Container in Java Example

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles