package b;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;
public class Main extends JFrame implements ActionListener {
static JPanel jp = new JPanel();
static JLabel jl = new JLabel("请输入姓名", SwingUtilities.RIGHT);
static JTextField jtf = new JTextField(10);
static JButton[] jb = new JButton[3];
static String[] s = {"按姓名查找", "显示全部", "增加患者"};
static JTable jt = new JTable(new Vector<>(), columnNames());
static JScrollPane jsp = new JScrollPane(jt);
public Main() {
jp.setLayout(new FlowLayout());
jp.add(jl);
jp.add(jtf);
for (int i = 0; i < jb.length; i++) {
jb[i] = new JButton(s[i]);
jb[i].addActionListener(this);
jp.add(jb[i]);
}
this.add(jp, BorderLayout.NORTH);
DefaultTableModel dtm = new DefaultTableModel(tableDataAll(), columnNames());
jt.setModel(dtm);
this.add(jsp, BorderLayout.CENTER);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(1900, 1000);
}
public static void main(String[] args) {
Main m = new Main();
m.setExtendedState(JFrame.MAXIMIZED_BOTH);
m.setVisible(true);
}
public static Vector<String> columnNames() {
Vector<String> vs = new Vector<String>();
vs.add("编号");
vs.add("姓名");
vs.add("生日");
vs.add("手机");
vs.add("身份证号");
vs.add("备注");
return vs;
}
public static Vector<Vector<Object>> tableDataUsername(String username) {
Vector<Vector<Object>> vvo = new Vector<Vector<Object>>();
try {
Class.forName("org.sqlite.JDBC");
try (Connection conn = DriverManager.getConnection("jdbc:sqlite:mydata.sqlite3")) {
try (PreparedStatement ps = conn.prepareStatement("select rowid, * from t_user where username = ?")) {
ps.setString(1, username);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
Vector<Object> vo = new Vector<>();
vo.add(rs.getString("rowid"));
vo.add(rs.getString("username"));
vo.add(rs.getString("birthday"));
vo.add(rs.getString("mobile"));
vo.add(rs.getString("idcard"));
vo.add(rs.getString("beizhu"));
vvo.add(vo);
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return vvo;
}
public static Vector<Vector<Object>> tableDataAll() {
Vector<Vector<Object>> vvo = new Vector<Vector<Object>>();
try {
Class.forName("org.sqlite.JDBC");
try (Connection conn = DriverManager.getConnection("jdbc:sqlite:mydata.sqlite3")) {
try (PreparedStatement ps = conn.prepareStatement("select rowid, * from t_user order by rowid desc")) {
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
Vector<Object> vo = new Vector<>();
vo.add(rs.getString("rowid"));
vo.add(rs.getString("username"));
vo.add(rs.getString("birthday"));
vo.add(rs.getString("mobile"));
vo.add(rs.getString("idcard"));
vo.add(rs.getString("beizhu"));
vvo.add(vo);
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return vvo;
}
public void actionPerformed(ActionEvent e) {
String s = e.getActionCommand();
if (s.equals("按姓名查找")) {
System.out.println(1);
String username = this.jtf.getText();
DefaultTableModel dtm = new DefaultTableModel(tableDataUsername(username), columnNames());
jt.setModel(dtm);
} else if (s.equals("显示全部")) {
System.out.println(2);
DefaultTableModel dtm = new DefaultTableModel(tableDataAll(), columnNames());
jt.setModel(dtm);
} else if (s.equals("增加患者")) {
UserInsert ui = new UserInsert(true);
ui.setVisible(true);
}
}
}
牙医软件主界面
最新推荐文章于 2025-11-25 11:44:22 发布
1万+

被折叠的 条评论
为什么被折叠?



