Using the program OneButton.java as a template, we can concentrate on the lines of code that add components to the frame. For example, suppose we try to add two buttons:
JButton button = new JButton("Do Nothing");
JButton button2 = new JButton("Do Nothing Too");
frame.add(button);
frame.add(button2);
This doesn't work. Only the second button appears. That's because every container has a layout manager which decides where to place the components that are added to the container. The default layout manager for a frame is always a border layout manager. As usual, you can read about all the various layout managers in the Java Tutorial. One of the more visual pages is:
The border layout manager is a rather restrictive one. It only allows five components to be added, and they have to be added in the middle, or to the north, south, east or west of middle.
...
JButton button = new JButton("Middle");
JButton buttonN = new JButton("North");
JButton buttonS = new JButton("South");
JButton buttonE = new JButton("East");
JButton buttonW = new JButton("West");
frame.add(button);
frame.add(buttonN, BorderLayout.NORTH);
frame.add(buttonS, BorderLayout.SOUTH);
frame.add(buttonE, BorderLayout.EAST);
frame.add(buttonW, BorderLayout.WEST);
...
When you run the program, see what happens when you resize the main window.