Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package icecream;
- import java.awt.BorderLayout;
- import java.awt.GridLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.sql.Connection;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import javax.swing.BorderFactory;
- import javax.swing.JButton;
- import javax.swing.JComboBox;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JScrollPane;
- import javax.swing.JTable;
- import javax.swing.JTextField;
- import javax.swing.SwingConstants;
- import javax.swing.SwingUtilities;
- public class GUI implements ActionListener {
- JFrame menu = new JFrame("Ice Cream Parlor");
- JFrame orders = new JFrame("Orders");
- JFrame orderEntry = new JFrame("Order Entry");
- JTextField fname = new JTextField();
- JTextField lname = new JTextField();
- Connection con = null;
- Statement st = null;
- Database db = null;
- public GUI() throws SQLException {
- con = DBConnectionManager.getInstance().getConnection();
- db = new Database(con);
- try
- {
- db.makeTables();
- } catch( SQLException e)
- {
- System.err.println("ERROR: COULD NOT INITIALIZE TABLES [" + e.getMessage() + "]");
- }
- menu.setLayout(new GridLayout(2, 1, 10, 10));
- menu.setBounds(100, 100, 500, 500);
- JButton b1 = new JButton("See Orders");
- b1.addActionListener(this);
- b1.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
- JButton b2 = new JButton("Enter Order");
- b2.addActionListener(this);
- menu.add(b1);
- menu.add(b2);
- menu.setVisible(true);
- menu.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- //orderEntry.getContentPane().removeAll();
- orderEntry.setLayout(new GridLayout(3,3));
- orderEntry.setBounds(100, 100, 600, 600);
- orderEntry.add(fname);
- orderEntry.add(lname);
- JComboBox flavors = new JComboBox(new String[]{"Vanilla"});
- orderEntry.add(flavors);
- JComboBox toppings = new JComboBox(new String[]{"Chocolate Syrup"});
- orderEntry.add(toppings);
- JComboBox container = new JComboBox(new String[]{"Cup", "Cone"});
- orderEntry.add(container);
- }
- public void showOrders() {
- orders.getContentPane().removeAll();
- orders.setLayout(new BorderLayout());
- orders.setBounds(100, 100, 600, 600);
- ResultSet rs;
- int rows = 0;
- String[][] arr = null;
- try {
- arr = db.getorders();
- } catch (SQLException e) {
- orders.add(new JLabel("ERROR: COULD NOT ACCESS ORDERS", SwingConstants.CENTER));
- System.err.println("ERROR: COULD NOT ACCESS ORDERS [" + e.getMessage() + "]");
- return;
- }
- if (arr == null) {
- orders.add(new JLabel("NO ORDERS YET", SwingConstants.CENTER));
- } else {
- JTable table = new JTable(arr, db.cols) {
- @Override
- public boolean isCellEditable(int row, int col) {
- return false;
- }
- };
- orders.add(new JScrollPane(table), BorderLayout.CENTER);
- }
- orders.setVisible(true);
- }
- public void enterOrder()
- {
- orderEntry.setVisible(true);
- }
- public static void main(String[] args) {
- SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- try {
- GUI gui = new GUI();
- } catch (SQLException e) {
- System.out.println("ERROR: COULD NOT ESTABLISH CONNECTION [" + e.getMessage() + "]");
- }
- }
- });
- }
- @Override
- public void actionPerformed(ActionEvent ae) {
- if (ae.getActionCommand().equals("See Orders")) {
- showOrders();
- } else if (ae.getActionCommand().equals("Enter Order")) {
- enterOrder();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement