Computer Science 523
Advanced Programming
Summer 2014, The College of Saint Rose
ManyJLabelsContentPane Demo
A working demo of ManyJLabelsContentPane will appear below. Click inside the applet to interact with it.
ManyJLabelsContentPane BlueJ Project
Click here to download a BlueJ project for ManyJLabelsContentPane.
ManyJLabelsContentPane Source Code
The Java source code for ManyJLabelsContentPane is below. Click on a file name to download it.
/*
* Example ManyJLabelsContentPane
*
* Jim Teresco, The College of Saint Rose, CSC 523, Summer 2014
*
* $Id: ManyJLabelsContentPane.java 2379 2014-06-17 03:52:55Z terescoj $
*/
import java.awt.BorderLayout;
import java.awt.Container;
import javax.swing.JApplet;
import javax.swing.JLabel;
public class ManyJLabelsContentPane extends JApplet {
public void init() {
// When we create a JApplet, we automatically get a "container" for the
// items within it, called the "content pane". We can get our hands on
// it from the getContentPane method.
Container contentPane = getContentPane();
// We now add our components to the content pane. By default, the
// content pane gives us 5 places where we can add items: to the
// north, west, center, east, and south parts of the window. We
// specify these as follows, with the BorderLayout's constants.
contentPane.add(new JLabel("1) I know Java is fun."), BorderLayout.NORTH);
contentPane.add(new JLabel("2) I'm gettting good at applications."), BorderLayout.WEST);
contentPane.add(new JLabel("3) I expect GUIs will be good too."), BorderLayout.EAST);
contentPane.add(new JLabel("4) I wish they had buttons and stuff, though."), BorderLayout.SOUTH);
}
}