..\CSC120\Java\lec05\src\MUPanel.java
  1 /*
  2     CSC 120 Lab 2
  3     Blase Cindric
  4 
  5     Description:
  6     This program creates a picture of a house, tree, and happy-face sun.
  7     The purpose is to practice using methods of the Graphics class.
  8 */
  9 
 10 import java.awt.*;
 11 import javax.swing.*;
 12 
 13 public class MUPanel extends JPanel {
 14 
 15     // Declare private data here
 16     
 17     private LollipopTree aTree, tree2, lastTree, iLiedThisIsTheRealLastOne;
 18     private SmileySun theSun, tatooineSun, sol;
 19     
 20     public MUPanel() {
 21         setLayout(null);
 22         setPreferredSize(new Dimension(900, 400));
 23         setName("CSC 120 Lab 2");
 24         setBackground(Color.WHITE); 
 25 
 26         // Instantiate objects and initialize data here
 27         aTree = new LollipopTree(480, 80);
 28         tree2 = new LollipopTree(650, 120);
 29         lastTree = new LollipopTree(750, 40);
 30         iLiedThisIsTheRealLastOne = new LollipopTree(420, 150);
 31         
 32         theSun = new SmileySun(60, 60, Color.BLUE);
 33         tatooineSun = new SmileySun(150, 20, Color.GREEN);
 34         sol = new SmileySun(30, 160, Color.RED);
 35         
 36     } // end of MUPanel constructor
 37     
 38 
 39     public void paintComponent(Graphics g) {
 40         super.paintComponent(g);
 41         
 42         // The house
 43         g.setColor(Color.BLACK);
 44         g.drawRect(200, 150, 200, 100);
 45                 
 46         // The roof
 47         g.drawLine(200, 150, 300, 90);
 48         g.drawLine(300, 90, 400, 150);
 49 
 50         // The window
 51         g.setColor(Color.YELLOW);
 52         g.fillRect(225, 180, 90, 40);
 53         g.setColor(Color.BLACK);
 54         g.drawRect(225, 180, 90, 40);
 55         g.drawLine(225, 200, 315, 200);
 56         g.drawLine(270, 180, 270, 220);
 57                 
 58                 
 59         // The door and doorknob
 60         g.setColor(Color.BLUE);
 61         g.fillRect(350, 190, 30, 60);
 62         g.setColor(Color.ORANGE);
 63         g.fillOval(365, 220, 10, 10);
 64 
 65 
 66         // The tree
 67         aTree.draw(g);
 68         tree2.draw(g);
 69         lastTree.draw(g);
 70         iLiedThisIsTheRealLastOne.draw(g);
 71         
 72         
 73         // The sun
 74         theSun.draw(g);
 75         tatooineSun.draw(g);
 76         sol.draw(g);
 77         
 78     } // end of paintComponent()
 79 
 80     
 81     
 82     /***********************************************
 83      * Do NOT change or delete anything below here!
 84      ***********************************************/
 85     public void frame()
 86     {
 87         for (Component c: getComponents())
 88             c.setSize(c.getPreferredSize());
 89         JFrame f = new JFrame(getName());
 90         f.setContentPane(this);
 91         f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 92         f.pack();
 93         f.setVisible(true);   
 94         
 95     } // end of frame()
 96 
 97     public static void main(String args[]){new MUPanel().frame();}
 98 
 99 }
100