H:\CSC120\Java\lec03\src\MUPanel.java |
1
2
3
4
5
6
7
8
9 import java.awt.*;
10 import javax.swing.*;
11
12 public class MUPanel extends JPanel {
13
14
15
16 private Flag myFlag, anotherFlag, flag3;
17
18
19
20 public MUPanel() {
21 setLayout(null);
22 setPreferredSize(new Dimension(800, 600));
23 setName("Mount Union Java Program");
24 setUp();
25 setBackground(Color.WHITE);
26
27
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 }
34
35 @Override
36 public void paintComponent(Graphics g) {
37 super.paintComponent(g);
38
39
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 }
52
53
54
55
56
57
58
59
60
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 }
75