import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import java.awt.Dimension;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class GUIPattern1 {
	
	// these must be declared here to be seen in any Action classes
	Graphics2D thePen;
	int width;
	int height;
	
	public GUIPattern1() {
		
		// The (window) frame
		JFrame frame = new JFrame("Generic Frame");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		int xPosition = 200;
		int yPosition = 200;
		frame.setLocation(xPosition,yPosition);
		
		// The main panel
		JPanel thePanel = new JPanel();
		width = 500;
		height = 300;
		thePanel.setPreferredSize(new Dimension(width,height));
		thePanel.setBackground(Color.YELLOW);
		
		// Other componenets are added to the panel here
		
		// The ButtonAction class will have the action statements
		JButton aButton = new JButton("a button");
		aButton.addActionListener( new ButtonAction() );
		thePanel.add(aButton);
		
		// To see the panel it must be "added" to the frame
		// and set visible
		frame.getContentPane().add(thePanel);
		frame.pack();
		frame.setVisible(true);
		
		// This line gets the "pen" (Graphics2D object) to draw 
		// on the draw panel. It must be 'gotten" after the frame
		// is set visible
		thePen = (Graphics2D)thePanel.getGraphics();		
		thePen.setFont(new Font("monospaced",Font.BOLD,20));
		
	} // end constructor
	
	class ButtonAction implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			// these are the statments that are executed when aButton is clicked
		} // end actionPerformed
	} // end ButtonAction
	
	public static void main(String[] args) {
		new GUIPattern1();		
	} // end main
	
} // end GUIPattern1
