3 import java
.awt
.event
.ActionEvent
;
4 import java
.awt
.event
.ActionListener
;
5 import java
.util
.ArrayList
;
7 public class MainWindowsView
extends JFrame
{
8 MainWindowsView(String title
) {
9 //Create and set up the window.
12 setLocationRelativeTo(null);
13 setDefaultCloseOperation(JFrame
.EXIT_ON_CLOSE
);
16 JMenuBar menuBar
= new JMenuBar();
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
) {
29 JPanel panel
= new PersonView();
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
));
41 for (Component component
: components
) {
45 setContentPane(panel
);
49 * Show the GUI. For thread safety,
50 * this method should be invoked from the
51 * event-dispatching thread.
53 public void showGUI() {
57 this.setVisible(true);