I need to get the BookID from the BookInfo table. When I press on the ADD Button, Reservation window should pop out and have the BookID, Issued Date and Return Date written in the Table. So I need to pass BookID as an Object to Reservation.
I tried creating a new instance of book info, or pass a string to reservation...
//for BookInfo:
public void addRow(Object[] objToAdd)
{
DefaultTableModel model = (DefaultTableModel) table.getModel();
model.addRow(objToAdd);
}
...
JButton btnAdd = new JButton("Add");
btnAdd.setBorder(new BevelBorder(BevelBorder.RAISED, null, null, new Color(0, 0, 0), new Color(0, 0, 0)));
btnAdd.setOpaque(true);
btnAdd.setFont(new Font("American Typewriter", Font.PLAIN, 18));
btnAdd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Reservation.reserve(/*Object bookID*/);
}
});
String[] columnNames = {" Book ID", " Title ", " Author", " Genre", " Date Published ", " Availability"}; // table layout
//for Reservation:
public void reserve(Object[] bookID)
{
String issuedDate = new SimpleDateFormat("yyyy.MM.dd").format(new Date());
Calendar c = Calendar.getInstance();
c.setTime(new Date());
c.add(Calendar.DATE, 30);
String returnDate = new SimpleDateFormat("yyyy.MM.dd").format(c);
String[]resInfo = {"Book ID" , issuedDate, returnDate};
DefaultTableModel model = (DefaultTableModel) table.getModel();
model.addRow(resInfo);
}