import javax.swing.*;
import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
import java.util.ArrayList;
public class MainWindowsView extends JFrame {
- MainWindowsView(String title) {
+
+ MainWindowsView(String title, JPanel panel) {
//Create and set up the window.
setTitle(title);
setSize(300, 300);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- //Main pane
- JPanel panel = new PersonView();
+ //Create menu
+ JMenuBar menuBar = new JMenuBar();
+ setJMenuBar(menuBar);
+ JMenu fileMenu = new JMenu("File");
+ menuBar.add(fileMenu);
+ JMenuItem exit = new JMenuItem("Exit");
+ exit.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ System.exit(0);
+ }
+ });
+ fileMenu.add(exit);
- //Get all Swing/AWT primitive components in the views and add them to the panel.
+ //Get all Swing/AWT JPanel in the views and add them to the main panel.
ArrayList<Component> components = new ArrayList<>();
for (int i = 0; i < panel.getComponentCount(); i++) {
- if ((panel.getComponent(i) instanceof Container)) {
- Container subContainer = (Container) panel.getComponent(i);
- for (int j = 0; j < subContainer.getComponentCount(); j++) {
- components.add(subContainer.getComponent(j));
- }
- }
+ components.add(panel.getComponent(i));
}
for (Component component : components) {
panel.add(component);
//this.pack();
this.setVisible(true);
}
-
-}
+}
\ No newline at end of file