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