Page 682 - Introduction to Programming with Java: A Problem Solving Approach
P. 682

                648 Chapter 16 GUI Programming Basics
 /*********************************************************
*
SimpleWindow.java
Dean & Dean
This program displays a label in a window.
*********************************************************/
*
*
*
import javax.swing.*; // for JFrame, JLabel
import java.awt.*;
// for FlowLayout
public class SimpleWindow extends JFrame
{
private static final int WIDTH = 250;
private static final int HEIGHT = 100;
//******************************************************
public SimpleWindow()
{
}
setTitle("Simple Window");
setSize(WIDTH, HEIGHT);
setLayout(new FlowLayout());
setDefaultCloseOperation(EXIT_ON_CLOSE);
createContents();
setVisible(true);
Apago PDF Enhancer
// end SimpleWindow constructor
//******************************************************
private void createContents()
{
JLabel label = new JLabel("Hi! I'm Larry the label!");
     }
add(label);
// end createContents
This adds the label to the window.
//******************************************************
public static void main(String[] args)
  }
// end class SimpleWindow
{
 new SimpleWindow();
} // end main
This instantiates an anonymous window object.
 Figure 16.4 SimpleWindow program and its output





















































   680   681   682   683   684