/* CloseFrame.java

	This is a really simple graphics program.
	It opens a frame on the screen with a single
	line drawn across it.

	We're starting to add a little bit of polish
	here--we make the program close nicely when
	the close box is clicked, rather than just
	sort of hanging around half-dead.

	mag-28Apr2008
*/

// Import the basic graphics classes.
import java.awt.*;
import javax.swing.*;

public class CloseFrame extends JFrame{

	// Create a constructor method
	public CloseFrame(){
		super();			// All we do is call JFrame's constructor.
							// We don't need anything special for this.
	}

	// The following methods are instance methods.

	/*	Create a paint() method to override the one in JFrame.
		This is where the drawing happens.
		We don't have to call it in our program, it gets called
		automatically whenever the frame needs to be redrawn,
		like when it it made visible or moved or whatever.
	*/
	public void paint(Graphics g){
		g.drawLine(10,10,150,150); // Draw a line from (10,10) to (150,150)
	}

	public static void main(String arg[]){
		BasicFrame frame = new BasicFrame();	// create an identifier named 'window' and
												// apply it to a new BasicFrame object
												// created using our constructor, above.

		// This uses a constant EXIT_ON_CLOSE that's a member of JFrame.
		// The constant is passed to the setDefaultCloseOperation method of our frame object,
		// which is a CloseFrame object, which inherits the method from its parent JFrame,
		// to make it so that the program exits (closes completely) when we click the close
		// button.
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		frame.setSize(200,200);				// Use the setSize method that our BasicFrame
												// object inherited to make the frame
												// 200 pixels wide and high.

		frame.setVisible(true);					// Make the window show on the screen.
	}
}
	
