// PaintDemo.java
// Simple GUI with a panel demonstrating the paint method.
//
// Intended to be used with PaintDemoPanel.java
import java.awt.BorderLayout;
import java.awt.Container;
import javax.swing.JFrame;
import javax.swing.JTextField;
/**
* Window with a custom panel that talks to
* text fields which will display unique ID
* numbers of both the panel itself and the
* panel's current Graphics object.
*
* The window itself will display its own
* unique ID on the title bar.
*
* @author D. Nixon
*/
public class PaintDemo extends JFrame
{
/**
* Creates this window at the specified
* location on the screen.
*
* @param pixelsFromLeft distance between left side
* of this window and left side of screen
* @param pixelsFromTop distance between top of this
* window and top of screen
*/
public PaintDemo(int pixelsFromLeft,
int pixelsFromTop)
{
// Size of this window in pixels:
setSize(330, 250);
// Set this window's distance from
// left and top of screen:
setLocation(pixelsFromLeft, pixelsFromTop);
// Set title bar to display a unique ID
// for this window object:
setTitle("#" + hashCode());
// Prepare to add text fields and panel:
Container contentPane = getContentPane();
// Create and add text field at top:
JTextField topField = new JTextField();
topField.setEditable(false);
contentPane.add(topField, BorderLayout.NORTH);
// Create and add text field at bottom:
JTextField bottomField = new JTextField();
bottomField.setEditable(false);
contentPane.add(bottomField, BorderLayout.SOUTH);
// Create and add our custom panel:
PaintDemoPanel panel = new PaintDemoPanel(topField,
bottomField);
contentPane.add(panel, BorderLayout.CENTER);
// Enable program to quit when window closes:
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Make window appear on screen:
setVisible(true);
} // constructor
/**
* Main method
*
* @param args command-line arguments - none needed
*/
public static void main(String[] args)
{
// Create 3 windows:
new PaintDemo(50, 50);
new PaintDemo(350, 250);
new PaintDemo(650, 450);
} // method main
} // class PaintDemo