Commit | Line | Data |
---|---|---|
60971873 | 1 | import javax.swing.*; |
089fcbfc | 2 | import java.awt.*; |
416e35f7 JB |
3 | import java.awt.event.ActionEvent; |
4 | import java.awt.event.ActionListener; | |
089fcbfc | 5 | import java.util.ArrayList; |
60971873 JB |
6 | |
7 | public class MainWindowsView extends JFrame { | |
8 | MainWindowsView(String title) { | |
9 | //Create and set up the window. | |
10 | setTitle(title); | |
089fcbfc JB |
11 | setSize(300, 300); |
12 | setLocationRelativeTo(null); | |
60971873 JB |
13 | setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
14 | ||
416e35f7 JB |
15 | //Create menu |
16 | JMenuBar menuBar = new JMenuBar(); | |
17 | setJMenuBar(menuBar); | |
18 | JMenu fileMenu = new JMenu("File"); | |
19 | menuBar.add(fileMenu); | |
20 | JMenuItem exit = new JMenuItem("Exit"); | |
21 | exit.addActionListener(new ActionListener() { | |
22 | public void actionPerformed(ActionEvent e) { | |
23 | System.exit(0); | |
24 | } | |
25 | }); | |
26 | fileMenu.add(exit); | |
27 | ||
883508ca | 28 | //Main pane |
60971873 JB |
29 | JPanel panel = new PersonView(); |
30 | ||
089fcbfc JB |
31 | //Get all Swing/AWT primitive components in the views and add them to the panel. |
32 | ArrayList<Component> components = new ArrayList<>(); | |
33 | for (int i = 0; i < panel.getComponentCount(); i++) { | |
34 | if ((panel.getComponent(i) instanceof Container)) { | |
35 | Container subContainer = (Container) panel.getComponent(i); | |
36 | for (int j = 0; j < subContainer.getComponentCount(); j++) { | |
37 | components.add(subContainer.getComponent(j)); | |
38 | } | |
39 | } | |
40 | } | |
41 | for (Component component : components) { | |
42 | panel.add(component); | |
43 | } | |
60971873 | 44 | |
089fcbfc | 45 | setContentPane(panel); |
60971873 JB |
46 | } |
47 | ||
48 | /** | |
49 | * Show the GUI. For thread safety, | |
50 | * this method should be invoked from the | |
51 | * event-dispatching thread. | |
52 | */ | |
53 | public void showGUI() { | |
54 | ||
55 | //Display the window. | |
089fcbfc | 56 | //this.pack(); |
60971873 JB |
57 | this.setVisible(true); |
58 | } | |
59 | ||
416e35f7 | 60 | } |