package javaphone;

import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.util.HashMap;

public class MainWindowGUI extends JPanel {

    private LpPhoneMain controller;

    public MainWindowGUI() {
        super(new GridLayout());

        controller = new LpPhoneMain();
        while(!controller.login(login()));

        //Creates and adds the tabbed pane to this panel.
        add(createTabbedPane());
    }

    private JTabbedPane createTabbedPane() {
        JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.LEFT) {
            @Override //Modified so that choosing the last tab exits the program.
            public void setSelectedIndex(int index) {
                if (index != 0 && index == this.getTabCount() - 1) {
                    System.exit(0);
                }
                super.setSelectedIndex(index);
            }
        };
        tabbedPane.setPreferredSize(new Dimension(800, 600));

        //Sets all tabs.
        tabbedPane.addTab("Startsida", new NewStartPageGUI(this));
        tabbedPane.addTab("Lägg till ny kund", new NewNewCustomer());
        tabbedPane.addTab("Kunder", makeTextPanel("Kundlista"));
        tabbedPane.addTab("Handläggare", new UserListGUI(this));
        tabbedPane.addTab("Abonnemang", makeTextPanel("Abonnemang"));
        tabbedPane.addTab("Logga ut", null);

        tabbedPane.setUI(new javax.swing.plaf.metal.MetalTabbedPaneUI() {
            @Override //Overrides calculateTabHeight to modify tab height.
            protected int calculateTabHeight(int tabPlacement, int tabIndex, int fontHeight) {
                return super.calculateTabHeight(tabPlacement, tabIndex, fontHeight) + 30;
            }
        });

        //Enables the use of scrolling tabs.
        tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);

        return tabbedPane;
    }

    private JComponent makeTextPanel(String text) {
        JPanel panel = new JPanel(false);
        JLabel filler = new JLabel(text);
        filler.setHorizontalAlignment(JLabel.CENTER);
        //panel.setLayout(new GridLayout(1, 1));
        panel.add(filler);
        return panel;
    }

    /**
     * Creates the main program window and shows it.
     */
    public static void createMainWindow() {
        //Creates and sets up the window.
        JFrame frame = new JFrame("JavaPhone");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //Maximizes the window.
        frame.setExtendedState(JFrame.MAXIMIZED_BOTH);

        //Adds content to the window.
        frame.add(new MainWindowGUI());

        //Displays the window.
        frame.pack();
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        createMainWindow();
    }

    /**
     * @return the controller
     */
    public LpPhoneMain getController() {
        return controller;
    }

    /**
     * @param controller the controller to set
     */
    public void setController(LpPhoneMain controller) {
        this.controller = controller;
    }
    
    public HashMap login() {
        final JTextField username = new JTextField();
        final JTextField password = new JPasswordField();
        Object[] message = {"Användarnamn:", username, "Lösenord:", password};
        HashMap loginData = new HashMap();

        UIManager.put("OptionPane.okButtonText", "Logga in");
        UIManager.put("OptionPane.cancelButtonText", "Avbryt");
        final JOptionPane optionPane = new JOptionPane();
        int option = optionPane.showConfirmDialog(null, message, "Logga in", JOptionPane.CANCEL_OPTION);

        if (option == JOptionPane.OK_OPTION) {
            loginData.put("userName", username.getText());
            loginData.put("password", password.getText());
            return loginData;
        }
        return null;
    }
}

@@ -39,38 +39,8 @@
 .*;%0A
-import java.awt.BorderLayout;%0A
 impo
@@ -174,38 +174,245 @@
 private 
-LpPhoneMain controller
+Controller controller;%0A    private StartPageGUI startPageGUI; // RENAME!%0A    private NewCustomer newCustomerGUI; // RENAME!%0A    private CustomersGUI customersGUI;%0A    private UsersGUI usersGUI;%0A    private ServicesGUI servicesGUI
 ;%0A%0A    p
@@ -494,27 +494,26 @@
 r = new 
-LpPhoneMain
+Controller
 ();%0A    
@@ -521,16 +521,17 @@
    while
+ 
 (!contro
@@ -548,24 +548,267 @@
 (login()));%0A
+        %0A        startPageGUI = new StartPageGUI(this);%0A        newCustomerGUI = new NewCustomer(this);%0A        customersGUI = new CustomersGUI(this);%0A        usersGUI = new UsersGUI(this);%0A        servicesGUI = new ServicesGUI(this);%0A        
 %0A        //C
@@ -1032,16 +1032,17 @@
 rride //
+ 
 Modified
@@ -1471,16 +1471,9 @@
 a%22, 
-new NewS
+s
 tart
@@ -1479,22 +1479,16 @@
 tPageGUI
-(this)
 );%0A     
@@ -1536,23 +1536,16 @@
  new
- NewNew
 Customer
 ());
@@ -1540,18 +1540,19 @@
 Customer
-()
+GUI
 );%0A     
@@ -1586,34 +1586,20 @@
 r%22, 
-makeTextPanel(%22Kundlista%22)
+customersGUI
 );%0A 
@@ -1642,29 +1642,16 @@
 e%22, 
-new UserListGUI(this)
+usersGUI
 );%0A 
@@ -1693,35 +1693,19 @@
 g%22, 
-makeTextPanel(%22Abonnemang%22)
+servicesGUI
 );%0A 
@@ -3217,27 +3217,26 @@
  public 
-LpPhoneMain
+Controller
  getCont
@@ -3377,19 +3377,18 @@
 ler(
-LpPhoneMain
+Controller
  con
@@ -3442,20 +3442,16 @@
 ;%0A    %7D%0A
-    
 %0A    pub
@@ -3707,32 +3707,34 @@
 Map();%0A%0A        
+//
 UIManager.put(%22O
@@ -3982,16 +3982,19 @@
 ionPane.
+OK_
 CANCEL_O
@@ -4210,28 +4210,358 @@
    %7D
-%0A        return null
+ else if (option == JOptionPane.CANCEL_OPTION) %7B%0A            System.exit(0);%0A        %7D%0A        return null;%0A    %7D%0A%0A    public void updateServicesGUI() %7B%0A        servicesGUI.fillTable();%0A    %7D%0A    %0A     public void updateCustomersGUI() %7B%0A        customersGUI.fillTable();%0A     %7D%0A        %0A    public void updateUsersGUI() %7B%0A        usersGUI.fillTable()
 ;%0A  

Update MainWindowGUI.java