package cn.yun.web;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.border.EmptyBorder;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableModel;
import cn.yun.dao.LoginDao;
import java.awt.Component;
import javax.swing.JButton;
import java.awt.Font;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JTextPane;
public class Admin extends JFrame {
private JPanel contentPane;
private static JTable table;
private static JFrame frame;
private DefaultTableModel model = null;
private static JScrollPane jScrollPane;
private JTable table_1;
private JPanel panel ;
private ResultSet res0;
private int index;
ResultSet rs ;
Object id;
int row;
LoginDao dao = new LoginDao();
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
frame = new Admin();
//frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Admin() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 908, 727);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
JButton insert = new JButton("\u6DFB\u52A0");
insert.setFont(new Font("宋体", Font.PLAIN, 35));
insert.setBounds(723, 13, 144, 71);
contentPane.add(insert);
insert.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
insert in = new insert();
in.show();
in.closeJf(in);
}
});
JButton del = new JButton("\u5220\u9664");
del.setFont(new Font("宋体", Font.PLAIN, 35));
del.setBounds(723, 83, 144, 71);
contentPane.add(del);
JButton update = new JButton("\u4FEE\u6539");
update.setFont(new Font("宋体", Font.PLAIN, 35));
update.setBounds(723, 151, 144, 71);
contentPane.add(update);
JButton select = new JButton("\u67E5\u8BE2");
select.setFont(new Font("宋体", Font.PLAIN, 35));
select.setBounds(723, 221, 144, 71);
contentPane.add(select);
JButton gengxin = new JButton("\u66F4\u65B0");
gengxin.setFont(new Font("宋体", Font.PLAIN, 35));
gengxin.setBounds(723, 289, 144, 71);
contentPane.add(gengxin);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(14, 13, 695, 654);
contentPane.add(scrollPane);
table_1 = new JTable();
scrollPane.setViewportView(table_1);
String[] titles = {"编号", "用户名", "密码", "级别", "联系邮箱"};
//table_1.setModel(new DefaultTableModel(new Object[][] {},titles));
DefaultTableModel dtm = new DefaultTableModel(new Object[][] {},titles);
//获取用户选中表格的索引
//鼠标事件
table_1.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e){
row = table_1.getSelectedRow(); //获得选中行索引
// System.out.println("鼠标的索引:"+row);
id = dtm.getValueAt(row, 0);//获得选中行的第一列
// System.out.println("数据库id:"+id);
}
});
//删除数据
del.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
if(dao.delete(id.toString())>0) {
DelSuccess del = new DelSuccess();
del.show();
del.closeJf(del);
}
} catch (Exception e1) {
e1.printStackTrace();
}
}
});
//获取数据库中所有文件
table_1.setModel(dtm);
panel = new JPanel();
panel.setBounds(723, 373, 153, 294);
contentPane.add(panel);
panel.setLayout(null);
JTextPane txt = new JTextPane();
txt.setBounds(21, 42, 122, 30);
panel.add(txt);
JComboBox<String> comboBox = new JComboBox();
comboBox.setBounds(21, 5, 122, 24);
comboBox.setModel(new DefaultComboBoxModel(new String[] {"===请选择===","编号","用户名","密码","级别","联系邮箱"}));
comboBox.setSelectedIndex(0);
panel.add(comboBox);
JButton star = new JButton("\u5F00\u59CB\u67E5\u8BE2");
star.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
star.setBounds(21, 101, 122, 27);
panel.add(star);
JButton end = new JButton("\u7ED3\u675F\u67E5\u8BE2");
end.setBounds(21, 152, 122, 27);
panel.add(end);
panel.setVisible(false);
comboBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
LoginDao dao = new LoginDao();
// 只处理选中的状态
if (e.getStateChange() == ItemEvent.SELECTED) {
System.out.println("选中: " + comboBox.getSelectedIndex() + " = " + comboBox.getSelectedItem());
index = comboBox.getSelectedIndex();
}
}
});
try {
rs = dao.query();
} catch (Exception e) {
e.printStackTrace();
}
try {
while(rs.next()) {
dtm.addRow(new String[] {rs.getString("id"),rs.getString("username"),rs.getString("password"),rs.getString("grade"),rs.getString("email")});
}
} catch (SQLException e) {
e.printStackTrace();
}
//修改数据
update.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String jid = dtm.getValueAt(row, 0).toString();
String jusername = dtm.getValueAt(row, 1).toString();
String jpassword = dtm.getValueAt(row, 2).toString();
String jdengji = dtm.getValueAt(row, 3).toString();
String jemail = dtm.getValueAt(row, 4).toString();
UpdateUser updateUser = new UpdateUser(jid, jusername, jpassword, jdengji, jemail);
updateUser.show();
updateUser.closeJf(updateUser);
}
});
//更新数据
gengxin.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dtm.setRowCount(0);
try {
table_1.setModel(dtm);
try {
rs = dao.query();
while(rs.next()) {
dtm.addRow(new String[] {rs.getString("id"),rs.getString("username"),rs.getString("password"),rs.getString("grade"),rs.getString("email")});
}
} catch (Exception e1) {
e1.printStackTrace();
}
} catch (Exception e1) {
e1.printStackTrace();
}
}
});
//查询
select.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
panel.setVisible(true);
}
});
//开始查询
star.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
switch (index) {
case 1:{
try {
res0 = dao.select(txt.getText());
try {
table_1.setModel(dtm);
dtm.setRowCount(0);
try {
while(res0.next()) {
dtm.addRow(new String[] {res0.getString(
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
代码.rar (58个子文件)
代码
GuiTest
.project 383B
bin
cn
yun
utils
SqlConnUtil.class 1KB
QueryUtil.class 278B
dao
LoginDao.class 3KB
web
login$2.class 1KB
InsertSuccess$1.class 715B
InsertSuccess.class 2KB
zs$1.class 701B
UpdateUser.class 4KB
InsertSuccess$2.class 837B
Admin$7.class 1KB
Admin$10.class 4KB
Admin$1.class 687B
Admin$6.class 1KB
Admin.class 6KB
DelSuccess$3.class 819B
DelSuccess.class 2KB
login$1.class 720B
Admin$9.class 752B
UpdateSuccess$1.class 756B
QueryUser$1.class 736B
zs.class 2KB
Admin$4.class 1KB
UpdateSuccess$2.class 837B
Admin$2.class 775B
Admin$8.class 2KB
Admin$11.class 754B
insert$2.class 696B
DelSuccess$1.class 745B
DelSuccess$2.class 649B
UpdateUser$2.class 2KB
insert$1.class 1KB
QueryUser.class 4KB
insert.class 3KB
Admin$5.class 619B
login.class 2KB
QueryUser$4.class 2KB
UpdateUser$3.class 819B
UpdateSuccess.class 2KB
QueryUser$3.class 2KB
QueryUser$2.class 643B
Admin$3.class 1011B
UpdateUser$1.class 497B
.settings
org.eclipse.jdt.core.prefs 598B
src
cn
yun
utils
QueryUtil.java 2KB
SqlConnUtil.java 652B
dao
LoginDao.java 3KB
web
insert.java 3KB
login.java 2KB
DelSuccess.java 2KB
UpdateSuccess.java 2KB
QueryUser.java 5KB
Admin.java 12KB
zs.java 1KB
UpdateUser.java 4KB
InsertSuccess.java 1KB
.classpath 456B
lib
mysql-connector-java-5.0.8-bin.jar 528KB
共 58 条
- 1
(ಡωಡ)hiahiahia.
- 粉丝: 75
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论5