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.
public static void main(String args)
Frame frame = new Frame("Add Components to a Container");
Button button = new Button("OK");