H:\CSC120\Java\lec03\src\MUPanel.java
 1 /* CSC 120 Lecture # 3
 2  * Blase B. Cindric
 3  *
 4  *
 5  * Project Description:
 6       Several fascinating examples of using the Flag class
 7  *
 8  */
 9 import java.awt.*;
10 import javax.swing.*;
11 
12 public class MUPanel extends JPanel {
13 
14     // 1. Declare private objects here:
15     
16     private Flag myFlag, anotherFlag, flag3;
17     
18 
19     // constructor method
20     public MUPanel() {
21         setLayout(null);
22         setPreferredSize(new Dimension(800, 600)); // this is the size of the output window
23         setName("Mount Union Java Program");
24         setUp();
25         setBackground(Color.WHITE);
26 
27         // 2. Instantiate objects here by calling "new":
28         
29         myFlag = new Flag(50, 100, Color.RED, Color.WHITE);
30         anotherFlag = new Flag(50, 275, Color.CYAN, Color.WHITE);
31         flag3 = new Flag(50, 450, Color.RED, Color.BLUE);
32         
33     } // end of constructor
34     
35     @Override
36     public void paintComponent(Graphics g) {
37         super.paintComponent(g); // This line must be first in this method!
38 
39         // 3. Call methods of objects here:
40 
41         g.drawString("Here are some flags from countries of the world", 50, 40);
42         
43         myFlag.draw(g);
44         anotherFlag.draw(g);
45         flag3.draw(g);
46         
47         g.drawString("Flag of Peru", 300, 160);
48         g.drawString("Flag of Guatemala", 300, 335);
49         g.drawString("Flag of Mongolia", 300, 510);
50                 
51     } // end of paintComponent()
52     
53     
54     
55        
56     
57     
58     
59     /***********************************************
60      * Do NOT change or delete anything below here!
61      ***********************************************/
62     public void setUp() {
63         for (Component c: getComponents())
64             c.setSize(c.getPreferredSize());
65         JFrame f = new JFrame(getName());
66         f.setContentPane(this);
67         f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
68         f.pack();
69         f.setVisible(true);    
70     }
71 
72     public static void main(String args[]){new MUPanel();}
73 
74 } // end of class MUPanel
75