FileDocCategorySizeDatePackage
SwingClass.javaAPI DocExample1207Tue Mar 02 12:13:30 GMT 2004org.cookbook.ch08

SwingClass.java

/*
 * Created on Mar 2, 2004
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package org.cookbook.ch08;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

/**
 * @author Steven Holzner
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public class SwingClass extends JFrame {

	Panel p;

	public SwingClass() 
	{
		super("Swing Example");

		Container contentPane = getContentPane();
		p = new Panel();
		contentPane.add(p);
	}

	public static void main(String args[]) 
	{
		final JFrame f = new SwingClass();

		f.setBounds(100, 100, 280, 250);
		f.setVisible(true);
		f.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		
		f.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
	}
}

class Panel extends JPanel 
{
	Panel()
	{
		setBackground(Color.white);
	}
	
	public void paintComponent (Graphics g)
	{
		super.paintComponent(g);
		g.drawString("Greetings from Swing", 70, 100);
	}
}