You almost had it. Comments:
1 - in BorderLayout when you use the
add method without a constraint, eg, BorderLayout.EAST, the default behavior is to add the component to the center section as if you had specified the constraint
BorderLayout.CENTER. If you add a component (JLabel
top) to the center section and then add another component(
bottom) to the center section the first component is discarded and the second component is shown. See the
BorderLayout api and also the lesson
Laying Out Components Within a Container in the
java tutorial.
2 - In JComponent it is the preferred practice to override the
paintComponent method for custom painting. The
paint method is more general and calls
paintComponent and other methods. See these methods in the
Method Detail section of the
JComponent api for specifics. Also, see the lesson
Performing Custom Painting in the tutorial for basics in custom component painting.
Responses to your questions:
1 - the code below demonstrates one technique for drawing a label. The TextLayout class is another way to do this and its api has sample code.
2 - top–level containers have content panes — see the tutorial lesson
Using Top–Level Containers for more information.
3 - the
Using Layout Managers page in the
Laying Out Components Within a Container lesson (mentioned above) has the answer to this.
In the code below I changed the class names so you can run it without name clashing problems.
[ August 27, 2004: Message edited by: Craig Wood ]