X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2FMainWindowsView.java;h=bc7951152f608bfdd4f8633efc2a9b99120cc8f1;hb=416e35f7e06f4689cccfd220bf1b4a20ffac54ec;hp=f4f837f6bbea7f512696dc7f5e1df9daa356caee;hpb=609718730ad9bc6d18491cf164360b4a44db5f52;p=Persons_Comparator.git diff --git a/src/MainWindowsView.java b/src/MainWindowsView.java index f4f837f..bc79511 100644 --- a/src/MainWindowsView.java +++ b/src/MainWindowsView.java @@ -1,18 +1,48 @@ 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) { //Create and set up the window. setTitle(title); + setSize(300, 300); + setLocationRelativeTo(null); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + //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); + + //Main pane JPanel panel = new PersonView(); - //TODO: Add content to the panel - //JLabel label = new JLabel("Hello World"); - //panel.add(label); + //Get all Swing/AWT primitive components in the views and add them to the panel. + ArrayList 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)); + } + } + } + for (Component component : components) { + panel.add(component); + } - getContentPane().add(panel); + setContentPane(panel); } /** @@ -23,8 +53,8 @@ public class MainWindowsView extends JFrame { public void showGUI() { //Display the window. - this.pack(); + //this.pack(); this.setVisible(true); } -} +} \ No newline at end of file