我正在使用Swing开发酒店预订应用程序。
我有一个JTable
行的房间列表。如果我点击任何一行,那么如果用户为特定日期预订了该房间,则所选房间将进入预订。之后如果有人试图为相同的日期预订同一个房间,它必须显示警告信息或如何从表中隐藏该行?
import javax.swing.*;
/**
*
* @author ssn
*/
public class Reservation extends javax.swing.JFrame {
/**
* Creates new form Reservation
*/
public Reservation() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel2 = new javax.swing.JPanel();
jPanel1 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
RentPerDay = new javax.swing.JTextField();
BedType = new javax.swing.JTextField();
RoomNo = new javax.swing.JTextField();
RoomType = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
jLabel11 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jLabel12 = new javax.swing.JLabel();
jLabel13 = new javax.swing.JLabel();
jLabel14 = new javax.swing.JLabel();
jLabel15 = new javax.swing.JLabel();
jLabel16 = new javax.swing.JLabel();
jLabel17 = new javax.swing.JLabel();
jButton2 = new javax.swing.JButton();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jTextField3 = new javax.swing.JTextField();
jTextField7 = new javax.swing.JTextField();
jTextField8 = new javax.swing.JTextField();
jTextField9 = new javax.swing.JTextField();
NoOfdays = new javax.swing.JTextField();
jTextField11 = new javax.swing.JTextField();
jComboBox1 = new javax.swing.JComboBox<>();
jComboBox2 = new javax.swing.JComboBox<>();
jComboBox3 = new javax.swing.JComboBox<>();
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
jLabel2.setText("RESERVATION OF ROOM");
jPanel1.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 800, 20));
你不关心编码,只是分享我是怎么做的
答案 0 :(得分:2)
在JTable
使用中为行选择创建侦听器:
yourJTable.getSelectionModel().addListSelectionListener(e -> {
public void valueChanged(ListSelectionEvent e) {
ListSelectionModel lsm = (ListSelectionModel) e.getSource();
}
});
在此听众中,您可以检查是否已预订选定的房间并将其发送至预订。
要隐藏JTable
行,您应按照in the tutorial所述使用过滤。