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{

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

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



        frame.setSize(500, 500);
        //frame.setLayout(new FlowLayout());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setBackground(Color.WHITE);

        panel.add(descriptionLabel);
        panel.add(dropdown);
        panel.add(goButton);
        panel.add(new JScrollPane(table));
        frame.add(panel);

        frame.setVisible(true);
    }

    private void createDropdown() {
        String[] options = {"Show All Games","User Page","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;
                    }

                }
            }
        });
    }
}

@@ -230,16 +230,24 @@
 e%7B%0A%0A    
+private 
 JFrame f
@@ -256,16 +256,24 @@
 me;%0A    
+private 
 JLabel d
@@ -293,16 +293,24 @@
 el;%0A    
+private 
 JPanel p
@@ -319,16 +319,24 @@
 el;%0A    
+private 
 JButton 
@@ -349,16 +349,24 @@
 on;%0A    
+private 
 JTable t
@@ -375,16 +375,24 @@
 le;%0A    
+private 
 DefaultT
@@ -417,16 +417,24 @@
 el;%0A    
+private 
 JComboBo
@@ -444,16 +444,103 @@
 ropdown;
+%0A    private JTabbedPane tabPane;%0A%0A    private final static int extraWindowWidth = 100;
 %0A%0A    pu
@@ -697,16 +697,56 @@
 he DB%22);
+%0A%0A        // Various creation operations
 %0A       
@@ -815,19 +815,16 @@
 ();%0A
-%0A%0A%0A
         
 fram
@@ -823,75 +823,81 @@
     
-frame.setSize(500, 500);%0A        //frame.setLayout(new FlowLayout()
+createTabPane();%0A%0A%0A        // Setup JFrame%0A        frame.setSize(500, 525
 );%0A 
@@ -1000,32 +1000,65 @@
 HITE);%0A%0A        
+// Add things to panel%0A        //
 panel.add(descri
@@ -1070,32 +1070,34 @@
 Label);%0A        
+//
 panel.add(dropdo
@@ -1101,32 +1101,34 @@
 pdown);%0A        
+//
 panel.add(goButt
@@ -1136,24 +1136,26 @@
 n);%0A        
+//
 panel.add(ne
@@ -1189,56 +1189,779 @@
     
-frame.add(panel);%0A%0A        frame.setVisible(true
+panel.add(tabPane);%0A%0A        // Add panel to frame%0A        frame.add(panel);%0A%0A        // Set the frame visible%0A        frame.setVisible(true);%0A    %7D%0A%0A    private void createTabPane() %7B%0A        tabPane = new JTabbedPane();%0A        JPanel card1 = new JPanel();%0A%0A        JPanel optionPanel = new JPanel();%0A        optionPanel.add(descriptionLabel);%0A        optionPanel.add(dropdown);%0A        optionPanel.add(goButton);%0A        optionPanel.setLayout(new FlowLayout());%0A%0A        card1.add(optionPanel);%0A        card1.add(new JScrollPane(table));%0A%0A        card1.setLayout(new BoxLayout(card1, BoxLayout.Y_AXIS));%0A%0A        JPanel card2 = new JPanel();%0A        card2.add(new JLabel(%22User Page%22));%0A%0A        tabPane.addTab(%22Store%22, card1);%0A        tabPane.addTab(%22User Page%22, card2
 );%0A 
@@ -2047,28 +2047,17 @@
  Games%22,
-%22User Page%22,
+ 
 %22Show Al

add tabbed view to the interface