when i try to input data into my reservation using the AddReservation option and press save i dont see the data being outputted on a table on my gui please fix here is the code, and i want the random id to be in the table too import java.awt.*; import javax.swing.*; import javax.swing.table.DefaultTableModel; import java.awt.event.ActionListener; import java.util.Random; import java.awt.event.ActionEvent; public class EntryScreen extends JFrame { 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 JButton MakeOrder; // private JButton MakeReservation; private JCheckBox checkBox; // variable that was stated to be added for checkbox private Driver reservationlist1; // Variable for PersonListing so we can create the instance // private Driver orderlist1; private JPanel pnlCommand; private JPanel pnlDisplay; private EntryScreen ReservationEntry1; // needed to set visibility for false public EntryScreen(Driver reservationlist1) //
when i try to input data into my reservation using the AddReservation option and press save i dont see the data being outputted on a table on my gui please fix here is the code, and i want the random id to be in the table too import java.awt.*; import javax.swing.*; import javax.swing.table.DefaultTableModel; import java.awt.event.ActionListener; import java.util.Random; import java.awt.event.ActionEvent; public class EntryScreen extends JFrame { 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 JButton MakeOrder; // private JButton MakeReservation; private JCheckBox checkBox; // variable that was stated to be added for checkbox private Driver reservationlist1; // Variable for PersonListing so we can create the instance // private Driver orderlist1; private JPanel pnlCommand; private JPanel pnlDisplay; private EntryScreen ReservationEntry1; // needed to set visibility for false public EntryScreen(Driver reservationlist1) //
Chapter6: Managing Multiple Worksheets And Workbooks
Section: Chapter Questions
Problem 1.14CP
Related questions
Question
100%
when i try to input data into my reservation using the AddReservation option and press save i dont see the data being outputted on a table on my gui please fix here is the code, and i want the random id to be in the table too
import java.awt.*;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.event.ActionListener;
import java.util.Random;
import java.awt.event.ActionEvent;
public class EntryScreen extends JFrame {
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 JButton MakeOrder;
// private JButton MakeReservation;
private JCheckBox checkBox; // variable that was stated to be added for checkbox
private Driver reservationlist1; // Variable for PersonListing so we can create the instance
// private Driver orderlist1;
private JPanel pnlCommand;
private JPanel pnlDisplay;
private EntryScreen ReservationEntry1; // needed to set visibility for false
public EntryScreen(Driver reservationlist1) // <Argument here// call it from now so it can be
// used
// later
// on
{
this.reservationlist1 = reservationlist1;
txttableNumber = new JTextField(20);
setTitle("Make a Reservation");
pnlCommand = new JPanel();
pnlDisplay = new JPanel();
// create the table model with column names
String[] columnNames = {"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);
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 Jlabel and will publish text with the checkbox object
pnlCommand = new JPanel();
pnlDisplay.setLayout(new GridLayout(4, 2));//
SaveCommand = new JButton("Save");
commandCloser = new JButton("Close");
pnlCommand.add(SaveCommand);
pnlCommand.add(commandCloser);
add(pnlDisplay, BorderLayout.CENTER);
add(pnlCommand, BorderLayout.SOUTH);
pack();
setVisible(true);
commandCloser.addActionListener(new commandCloser());
SaveCommand.addActionListener(new SaveCommand());
ReservationEntry1 = this;
}
private class commandCloser implements ActionListener {
public void actionPerformed(ActionEvent d) {
ReservationEntry1.setVisible(false);
System.out.println("Close button clicked");
}
}
private class SaveCommand implements ActionListener {
public void actionPerformed(ActionEvent e) {
Random random = new Random();
int id = random.nextInt(10000) + 1; // generate random ID between 1 and 10000
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) {
// Handle invalid input here, e.g. show an error message
}
}
String Capacity = txtcapacity.getText();
int capacity = 0;
if (!Capacity.isEmpty()) {
try {
capacity = Integer.parseInt(Capacity);
} catch (NumberFormatException ex) {
System.out.println(" Error");
// Handle invalid input here, e.g. show an error message
}
}
String date = txtDate.getText();
String time = txtTime.getText();
DefaultTableModel model = (DefaultTableModel)table.getModel();
model.addRow(new Object[]{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
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps
Knowledge Booster
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.Recommended textbooks for you
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage