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