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

/*
 * When this program is run, it opens a window that
 * displays a simple drawing.  The picture that is
 * drawn can be changed by modifying the list of
 * instructions in the paintComponent() method.
 */
public class FirstGraphics extends JPanel {
	
	/*
	 * Main program creates and shows the window.  There is
	 * no need to change the main routine!
	 */
	public static void main(String[] args) {
		JFrame window = new JFrame("My First Graphics");
		FirstGraphics canvas = new FirstGraphics();
		canvas.setPreferredSize(new Dimension(800,600));
		window.setContentPane(canvas);
		window.pack();
		window.setResizable(false);
		window.setLocation(150,80);
		window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		window.setVisible(true);
	}
	
	/*
	 * This paintComponent() method draws the content of the
	 * 800-by-600 drawing area that is displayed in the window.
	 */
	protected void paintComponent(Graphics g) {
		g.setColor(Color.GRAY); // Set color to be used for SUBSEQUENT drawing.
		g.fillRect(0, 0, 800, 600);  // Fill the drawing area with gray.
		g.setColor(Color.RED);
		g.drawRect(10, 10, 300, 150); // Draw the outline of a rectangle.
		g.fillRect(15, 15, 290, 140); // A filled-in rectangle inside the outline.
		g.setColor(Color.BLUE);
		g.drawOval(350, 10, 300, 150); // Draw the outline of an oval.
		g.fillOval(355, 15, 290, 140); // A filled-in oval inside the outline.
		g.setColor(Color.CYAN);
		g.drawLine(20, 200, 780, 580); // Draw two lines to make a big "X".
		g.drawLine(20, 580, 780, 200);
		g.setColor(Color.BLACK);
		g.drawString("Hello World!", 350, 300);  // Draw a string in default font.
		g.setFont(new Font("Serif", Font.PLAIN, 36));
		g.drawString("Goodbye!", 350, 500);  // Draw a string using a bigger font.
	}

}
