Go back to JList on the EyeView, JComboBox will be used somewhere else.
[Persons_Comparator.git] / src / MainWindowsView.java
1 import javax.swing.*;
2 import java.awt.*;
3 import java.awt.event.ActionEvent;
4 import java.awt.event.ActionListener;
5 import java.util.ArrayList;
6
7 public class MainWindowsView extends JFrame {
8
9 MainWindowsView(String title, JPanel panel) {
10 //Create and set up the window.
11 setTitle(title);
12 setSize(300, 300);
13 setLocationRelativeTo(null);
14 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
15
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
29 //Get all Swing/AWT JPanel in the views and add them to the main panel.
30 ArrayList<Component> components = new ArrayList<>();
31 for (int i = 0; i < panel.getComponentCount(); i++) {
32 components.add(panel.getComponent(i));
33 }
34 for (Component component : components) {
35 panel.add(component);
36 }
37
38 setContentPane(panel);
39 }
40
41 /**
42 * Show the GUI. For thread safety,
43 * this method should be invoked from the
44 * event-dispatching thread.
45 */
46 public void showGUI() {
47
48 //Display the window.
49 //this.pack();
50 this.setVisible(true);
51 }
52 }