When i press save for AddReservation i do not see the data on the gui i want a table visible when the gui is loaded and when the data is inputted i want to see the output

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
When i press save for AddReservation i do not see the data on the gui i want a table visible when the gui is loaded and when the data is inputted i want to see the output
 
import java.awt.*;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;

import java.awt.event.ActionListener;
import java.util.Random;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;

public class EntryScreen extends JFrame {
    // Declare all necessary components as instance variables
    private JTextField txtName;
    private JTextField txttableNumber;
    private JTextField txtcapacity;
    private JTable table;
    private JTextField txtID;
    private JTextField txtDate;
    private JTextField txtTime;
    private JButton SaveCommand;
    private JButton commandCloser;
    private JButton ClearAll;
    private JCheckBox checkBox;
    private Driver reservationlist1;
    private JPanel pnlCommand;
    private JPanel pnlDisplay;
    private EntryScreen ReservationEntry1;

    // Constructor that takes a Driver object as input
    public EntryScreen(Driver reservationlist1) {
        this.reservationlist1 = reservationlist1;

        // Initialize the necessary components
        txttableNumber = new JTextField(20);
        setTitle("Make a Reservation");
        pnlCommand = new JPanel();
        pnlDisplay = new JPanel();

        // create the table model with column names
        String[] columnNames = {"ID", "Name", "Date", "Time", "Capacity"};
        DefaultTableModel model = new DefaultTableModel(columnNames, 0);

        // create the table and set the model
        table = new JTable(model);

        // add the table to a scroll pane and add it to the GUI
        JScrollPane scrollPane = new JScrollPane(table);
        add(scrollPane, BorderLayout.CENTER);

        // add labels and text fields to the display panel
        pnlDisplay.add(new JLabel("Name:"));
        txtName = new JTextField(20);
        pnlDisplay.add(txtName);

        pnlDisplay.add(new JLabel("Date:"));
        txtDate = new JTextField(5);
        pnlDisplay.add(txtDate);

        pnlDisplay.add(new JLabel("Time:"));
        txtTime = new JTextField(5);
        pnlDisplay.add(txtTime);

        pnlDisplay.add(new JLabel("Capacity:"));
        txtcapacity = new JTextField(20);
        pnlDisplay.add(txtcapacity);

        // add the save and close buttons to the command panel
        pnlCommand.setLayout(new GridLayout(1, 2));
        SaveCommand = new JButton("Save");
        commandCloser = new JButton("Close");
        pnlCommand.add(SaveCommand);
        pnlCommand.add(commandCloser);

        // add the display and command panels to the GUI
        add(pnlDisplay, BorderLayout.CENTER);
        add(pnlCommand, BorderLayout.SOUTH);

        // finalize the GUI and make it visible
        pack();
        setVisible(true);

        // add action listeners to the buttons
        commandCloser.addActionListener(new commandCloser());
        SaveCommand.addActionListener(new SaveCommand());

        // set this object to be the current instance of EntryScreen
        ReservationEntry1 = this;
    }

    // ActionListener class for the close button
    private class commandCloser implements ActionListener {
        public void actionPerformed(ActionEvent d) {
            ReservationEntry1.setVisible(false);
            System.out.println("Close button clicked");
        }
    }

    // ActionListener class for the save button
    private class SaveCommand implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            // generate a random ID
            Random random = new Random();
            int id = random.nextInt(10000) + 1;

            // extract information from the text fields
            String name = txtName.getText();
            String[] Name = name.split(", ");
            String tableNumberst = txttableNumber.getText();
            int tableNumber = 0;
            if (!tableNumberst.isEmpty()) {
                try {
                    tableNumber = Integer.parseInt(tableNumberst);
                } catch

(NumberFormatException ex) {
                }
            }
            String Capacity = txtcapacity.getText();
            int capacity = 0;
            if (!Capacity.isEmpty()) {
                try {
                    capacity = Integer.parseInt(Capacity);
                } catch (NumberFormatException ex) {

                    System.out.println(" Error");
                }
            }
            String date = txtDate.getText();
            String time = txtTime.getText();

            DefaultTableModel model = (DefaultTableModel) table
.getModel();
model.addRow(new Object[]{id, name, date, time, capacity});
table.repaint();
        Reservation reservation = new Reservation(id, name, tableNumber, capacity, date, time);
        reservationlist1.addReservation(reservation);
        ReservationEntry1.setVisible(false);

        // display ID in a dialog box
        JOptionPane.showMessageDialog(null, "Reservation ID: " + id);
    }
}
}

 
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Database connectivity
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education