package DMS.SYSTEM; import DMS.GetConnection; import DMS.Users; import javax.swing.*; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableRowSorter; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.*; /**学生缺寝 * @author LQ * @create */ public class CooBuilding extends JPanel implements ActionListener { Connection connection = new GetConnection().GetConnection(); int type; Users user; JTable table = new JTable(); //JButton button = new JButton(""); String[] col = {"楼名", "层数", "管理人","容纳人数"}; DefaultTableModel mm = new DefaultTableModel(col, 0); // 定义一个表的模板 JLabel Bname,Bfloor,Bmager,Bcap,SP; JTextField BnameText,BfloorText,BmagerText,BcapText; JButton seek, add, delete, edit; JPanel student; public CooBuilding(int type, Users user) { this.user = user; this.type = type; setLayout(new FlowLayout());//整个采用流动式布局 很好的适应了表格带来的影响 table.setModel(mm); table.setRowSorter(new TableRowSorter<>(mm)); JScrollPane js = new JScrollPane(table); add(js); search(); }
时间: 2024-03-14 10:49:42 浏览: 145
这段代码是一个 Java 类,名为 CooBuilding,继承自 JPanel 类,并且实现了 ActionListener 接口。这个类主要是用来显示一个包含建筑物信息的表格,并且可以对这个表格进行增删改查的操作。其中,变量 type 表示用户的类型,变量 user 表示当前用户的信息,变量 table 表示显示建筑物信息的表格实例,变量 mm 表示表格的数据模型,变量 col 表示表格的列名,变量 connection 表示数据库连接对象。这个类的构造函数接受两个参数,分别表示用户类型和用户信息,并且在构造函数中调用了 search() 方法来初始化表格的数据。这个类还包含了若干个标签、文本框和按钮,用于对表格进行增删改查的操作。
阅读全文