package examples; import java.awt.*; import javax.swing.*; /** * CS401 Example 33 * * Simple example to show a label in a window. * * @author Dr. Ramirez, PJ Dillon */ public class ex33 { public static void main(String[] args) { /* * Create a JFrame object for the window. The String argument is used as the * title in the title bar of the window. */ JFrame theWindow = new JFrame("Example 33"); // Set it to terminate the program when the window closes theWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Create a JLabel object for the message. Set the font and the // color of the JLabel to make it more interesting JLabel theMessage = new JLabel("This is Example 33"); theMessage.setFont(new Font("Serif", Font.ITALIC + Font.BOLD, 40)); theMessage.setForeground(Color.RED); // The content pane of a JFrame is the "part" of the JFrame that // is used to store other components. First we access the // content pane, then we add the JLabel to it Container thePane = theWindow.getContentPane(); thePane.add(theMessage); // Size the window to be 300 pixels wide by 200 pixels high // Then show it so it is actually displayed theWindow.setSize(400, 200); theWindow.setVisible(true); } }