import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Created by loomisdf on 4/10/2016.
 */
public class DatabaseFrame{

    private JFrame frame;
    private JLabel descriptionLabel;
    private JPanel panel;
    private JButton goButton;
    private JTable table;
    private DefaultTableModel tableModel;
    private JComboBox dropdown;
    private JTabbedPane tabPane;

    private final static int extraWindowWidth = 100;

    public DatabaseFrame() {
        frame = new JFrame("Database Frame");
        panel = new JPanel();
        descriptionLabel = new JLabel("Welcome to the DB");

        // Various creation operations
        createDropdown();
        createButtons();
        creteTable();
        createTabPane();


        // Setup JFrame
        frame.setSize(500, 525);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setBackground(Color.WHITE);

        // Add things to panel
        //panel.add(descriptionLabel);
        //panel.add(dropdown);
        //panel.add(goButton);
        //panel.add(new JScrollPane(table));
        panel.add(tabPane);

        // Add panel to frame
        frame.add(panel);

        // Set the frame visible
        frame.setVisible(true);
    }

    private void createTabPane() {
        tabPane = new JTabbedPane();
        JPanel card1 = new JPanel();

        JPanel optionPanel = new JPanel();
        optionPanel.add(descriptionLabel);
        optionPanel.add(dropdown);
        optionPanel.add(goButton);
        optionPanel.setLayout(new FlowLayout());

        card1.add(optionPanel);
        card1.add(new JScrollPane(table));

        card1.setLayout(new BoxLayout(card1, BoxLayout.Y_AXIS));

        JPanel card2 = new JPanel();
        card2.add(new JLabel("User Page"));

        tabPane.addTab("Store", card1);
        tabPane.addTab("User Page", card2);
    }

    private void createDropdown() {
        String[] options = {"Show All Games", "Show All Categories"};
        dropdown = new JComboBox(options);
    }

    private void creteTable() {
        table = new JTable();
        tableModel = new DefaultTableModel(0, 0);
    }

    public void replaceTable(Object rowData[][], Object columns[]) {
        tableModel.setColumnIdentifiers(columns);
        table.setModel(tableModel);

        // Remove Rows
        if (tableModel.getRowCount() > 0) {
            for (int i = tableModel.getRowCount() - 1; i > -1; i--) {
                tableModel.removeRow(i);
            }
        }

        // Add new rows
        for(int r = 0; r < rowData.length; r++) {
            tableModel.addRow(rowData[r]);
        }
    }

    private void createButtons() {
        goButton = new JButton("Go!");
        goButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String operation = (String) dropdown.getSelectedItem();
                switch(operation) {
                    case("Show All Games"): {
                        TableInfo t = new TableInfo(Game.getAllGames());
                        replaceTable(t.rowData, t.columns);
                        break;
                    }
                    case("Show All Categories") : {
                        TableInfo t = new TableInfo(Category.getAllCategories());
                        replaceTable(t.rowData, t.columns);
                        break;
                    }

                }
            }
        });
    }
}

@@ -311,24 +311,56 @@
 anel panel;%0A
+    private JPanel loginScreen;%0A
     private 
@@ -501,23 +501,26 @@
 bedPane 
-tabPane
+userScreen
 ;%0A%0A    p
@@ -864,21 +864,52 @@
 eate
-TabPane
+UserScreen();%0A        createLoginScreen
 ();%0A%0A
-%0A
     
@@ -960,10 +960,10 @@
 0, 5
-2
 5
+0
 );%0A 
@@ -1261,23 +1261,58 @@
 nel.add(
-tabPane
+userScreen);%0A        panel.add(loginScreen
 );%0A%0A    
@@ -1463,35 +1463,921 @@
 eate
-TabPane() %7B%0A        tabPane
+LoginScreen() %7B%0A        loginScreen = new JPanel();%0A%0A        JLabel userLabel = new JLabel(%22Uesrname:%22);%0A        JLabel passLabel = new JLabel(%22Password:%22);%0A        JTextField userNameInput = new JTextField(15);%0A        JPasswordField passInput = new JPasswordField(15);%0A        JButton loginButton = new JButton(%22Login%22);%0A        loginButton.addActionListener(new ActionListener() %7B%0A            @Override%0A            public void actionPerformed(ActionEvent e) %7B%0A                loginScreen.setVisible(false);%0A                userScreen.setVisible(true);%0A            %7D%0A        %7D);%0A%0A        loginScreen.add(userLabel);%0A        loginScreen.add(userNameInput);%0A%0A        loginScreen.add(passLabel);%0A        loginScreen.add(passInput);%0A%0A        loginScreen.add(loginButton);%0A        loginScreen.setLayout(new BoxLayout(loginScreen, BoxLayout.PAGE_AXIS));%0A    %7D%0A%0A    private void createUserScreen() %7B%0A        userScreen
  = n
@@ -2862,39 +2862,42 @@
 ge%22));%0A%0A        
-tabPane
+userScreen
 .addTab(%22Store%22,
@@ -2917,15 +2917,18 @@
     
-tabPane
+userScreen
 .add
@@ -2951,16 +2951,55 @@
  card2);
+%0A%0A        userScreen.setVisible(false);
 %0A    %7D%0A%0A

add dummy login screen with no functionality, yet