📄 web158_com_server_stulist.java
字号:
package web158.com;
/**
* @param 李建东
*
* 联系电话:0898-62925341
*
* 联系QQ:813751 657597 8912740
*
* 网 址:
* http://www.web156.com
* http://www.web158.com
*/
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.Vector;
import java.sql.*;
class Web158_Com_Server_Stulist extends JPanel implements ActionListener
{
//查询相关PANEL
JPanel top_panel=new JPanel();
JTextField txtinfo=new JTextField();
JButton bSearch=new JButton("查询考生");
JButton bInfo=new JButton("详细及操作");
JButton bAdd=new JButton("添加考生");
//查询列表
JPanel main_panel=new JPanel();
//滚动面板
JScrollPane jScrollPane=new JScrollPane();
//列表
JTable jTable=new JTable();
//列名内容
Vector vcol=new Vector();
Vector vrow=new Vector();
//临时用向量
Vector vtemp=new Vector();
//添加考生面板
stuAdd addStu=new stuAdd();
//更改删除考生信息
stuOperate stuChange=new stuOperate();
//数据库连接
Web158_Com_Server_DBConn db=new Web158_Com_Server_DBConn();
ResultSet rs=null;
String sql="";
//板面字体
Font font = new Font("宋体",0,12);
//程序入口
Web158_Com_Server_Stulist()
{
//加载字体
initFont();
//面板总局方式
this.setLayout(new FlowLayout());
//面板大小
this.setPreferredSize(new Dimension(520,500));
//设置透明
this.setOpaque(false);
//添加上面需要添加查询等按钮PANEL
//查询表单
txtinfo.setPreferredSize(new Dimension(120,18));
txtinfo.setBorder(BorderFactory.createLineBorder(new Color(200,125,140)));
txtinfo.setToolTipText("可根据本关键字查找下表中任意字段考生信息");
top_panel.add(new JLabel("关键字:"));
top_panel.add(txtinfo);
//添加查找按钮
bSearch.setPreferredSize(new Dimension(80,18));
bSearch.setBorder(null);
bSearch.setBackground(new Color(207,207,157));
bSearch.setCursor(new Cursor(Cursor.HAND_CURSOR));
bSearch.setFont(font);
bSearch.setToolTipText("可根据本关键字查找下表中任意字段考生信息");
bSearch.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
String key=txtinfo.getText();
key=key.replaceAll("'","''");
sql="select * from stu_list where stuname like '%"+key+"%' or stuid like '%"+key+"%' or stuscore like '%"+key+"%' or stuoperate like '%"+key+"%' or examed like '%"+key+"%' or submited like '%"+key+"%' order by stuscore desc";
//调用查询方法
getStulist(sql);
}
});
top_panel.add(bSearch);
//详细信息按钮
bInfo.setPreferredSize(new Dimension(80,18));
bInfo.setBorder(null);
bInfo.setBackground(new Color(207,207,157));
bInfo.setCursor(new Cursor(Cursor.HAND_CURSOR));
bInfo.setFont(font);
bInfo.setToolTipText("此操作只支持关键字为考生的准考证号码");
bInfo.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
//取得关键字
String key=txtinfo.getText();
key=key.replaceAll("'","''");
//没有填写准考证号码进行考生信息操作不可操作
if(key.equals(""))
{
JOptionPane.showMessageDialog(null, "请填写要操作的考生准考证号码!");
return;
}
getStuinfo(key);
}
});
top_panel.add(bInfo);
//添加考生
bAdd.setPreferredSize(new Dimension(80,18));
bAdd.setBorder(null);
bAdd.setBackground(new Color(207,207,157));
bAdd.setCursor(new Cursor(Cursor.HAND_CURSOR));
bAdd.setFont(font);
bAdd.setToolTipText("添加考生");
bAdd.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
//添加考生
addStuinfo();
}
});
top_panel.add(bAdd);
//把本面板添加到主区
top_panel.setPreferredSize(new Dimension(520,30));
top_panel.setOpaque(false);
add(top_panel);
//主要列表面板
main_panel.setPreferredSize(new Dimension(520,500));
main_panel.setOpaque(false);
//初始化查询所有考生信息表
sql="select * from stu_list order by stuscore desc ";
//调用查询方法
getStulist(sql);
//添加表面板
add(main_panel);
}
//处理事件
public void actionPerformed(ActionEvent e)
{
}
//查询学生信息表
public void getStulist(String sql)
{
//先清空面板
vrow.removeAllElements();
vcol.removeAllElements();
main_panel.removeAll();
//添加列名
//初始化向量
vcol.addElement("考生姓名");
vcol.addElement("准考证号");
vcol.addElement("选择分数");
vcol.addElement("操作成绩");
vcol.addElement("是否取卷");
vcol.addElement("是否交卷");
//数据库中查询考生信息
try
{
rs=db.getResult(sql);
//开始行循环
while(rs.next())
{
//每次都需要把临时向量创建新实例,否刚表中内容会变成一样的
vtemp=new Vector();
//列循环
for(int k=1;k<=6;k++)
{
vtemp.addElement(rs.getString(k));
}
//添加入行
vrow.addElement(vtemp);
}//行循环结束
}
catch(Exception ef)
{
System.out.println("查询考生信息失败"+ef.getMessage());
}
//创建表
jTable=new JTable(vrow,vcol);
//设置滚动条
jTable.setAutoResizeMode(1);
jTable.setBackground(Color.white);
//添加到滚动面板
jScrollPane.getViewport().add(jTable, null);
jScrollPane.setPreferredSize(new Dimension(520,455));
jScrollPane.setBackground(Color.white);
main_panel.setLayout(new FlowLayout());
main_panel.add(jScrollPane,null);
//重新加载页面
main_panel.repaint();
main_panel.validate();
}//end of 查询考生信息类
//查询考生详细信息更改等操作
public void getStuinfo(String stuid)
{
//JOptionPane.showMessageDialog(null, "现在执行更改考生信息操作");
main_panel.removeAll();
//初始化参数
stuChange.setID(stuid);
//初始化详细信息
stuChange.initStuinfo();
//添加
main_panel.add(stuChange);
//更新使其有效
main_panel.repaint();
main_panel.validate();
}
//添加考生信息
public void addStuinfo()
{
//初始化标题文字
//刷新板块
main_panel.removeAll();
main_panel.add(addStu);
main_panel.repaint();
main_panel.validate();
}
//初始字体
void initFont()
{
UIManager.put("Label.font", font);
UIManager.put("Button.font", font);
UIManager.put("OptionPane.font", font);
UIManager.put("OptionPane.messageFont", font);
UIManager.put("OptionPane.buttonFont", font);
}
}
//添加考生面板
class stuAdd extends JPanel implements ActionListener
{
//////////////////////////////////////////////////////////////////////
//操作提示栏
JPanel title_panel=new JPanel();
//说明文字
JLabel title_label=new JLabel("添加考生信息");
//考生姓名板面/////////////////////////////////////////////////////////
JPanel stuname_panel=new JPanel();
//文字
JLabel stuname_txt=new JLabel();
//文本框
JTextField stuname_input=new JTextField();
//准考证号板面/////////////////////////////////////////////////////////
JPanel stuid_panel=new JPanel();
//文字
JLabel stuid_txt=new JLabel();
//文本框
JTextField stuid_input=new JTextField();
//选择题分数/////////////////////////////////////////////////////////
JPanel stuchoose_panel=new JPanel();
//文字
JLabel stuchoose_txt=new JLabel();
//文本框
JTextField stuchoose_input=new JTextField();
//操作题目分数/////////////////////////////////////////////////////////
JPanel stuoperate_panel=new JPanel();
//文字
JLabel stuoperate_txt=new JLabel();
//文本框
JTextField stuoperate_input=new JTextField();
//操作按钮/////////////////////////////////////////////////////////
JPanel stusubmit_panel=new JPanel();
//提交
JButton submit=new JButton("添加考生信息");
//板面字体
Font font = new Font("宋体",0,12);
//数据库连接
Web158_Com_Server_DBConn db=new Web158_Com_Server_DBConn();
ResultSet rs=null;
String sql="";
//程序入口
stuAdd()
{
this.setPreferredSize(new Dimension(520,445));
this.setOpaque(false);
title_label.setPreferredSize(new Dimension(510,30));
title_label.setText("添加考生信息(需加照片请把120*150的gif格试照片以考号命名放到系统/web158_com_stupic/中)");
title_label.setFont(font);
title_panel.add(title_label);
title_panel.setPreferredSize(new Dimension(520,60));
title_panel.setOpaque(false);
add(title_panel);
//考生姓名文字
stuname_txt.setPreferredSize(new Dimension(90,18));
stuname_txt.setText("考生姓名:");
stuname_txt.setFont(font);
stuname_panel.add(stuname_txt);
//考生姓名面板
stuname_input.setPreferredSize(new Dimension(120,18));
stuname_input.setBorder(BorderFactory.createLineBorder(new Color(200,125,140)));
stuname_input.setToolTipText("请填写考生姓名");
stuname_panel.add(stuname_input);
stuname_panel.setPreferredSize(new Dimension(520,60));
stuname_panel.setOpaque(false);
add(stuname_panel);
//准考证号文字
stuid_txt.setPreferredSize(new Dimension(90,18));
stuid_txt.setText("准考证号:");
stuid_txt.setFont(font);
stuid_panel.add(stuid_txt);
//准考证号面板
stuid_input.setPreferredSize(new Dimension(120,18));
stuid_input.setBorder(BorderFactory.createLineBorder(new Color(200,125,140)));
stuid_input.setToolTipText("请填写准考证号码");
stuid_panel.add(stuid_input);
stuid_panel.setPreferredSize(new Dimension(520,60));
stuid_panel.setOpaque(false);
add(stuid_panel);
//选择题文字
stuchoose_txt.setPreferredSize(new Dimension(90,18));
stuchoose_txt.setText("选择题分数:");
stuchoose_txt.setFont(font);
stuchoose_panel.add(stuchoose_txt);
//选择题面板
stuchoose_input.setPreferredSize(new Dimension(120,18));
stuchoose_input.setBorder(BorderFactory.createLineBorder(new Color(200,125,140)));
stuchoose_input.setToolTipText("此处您不可更改");
stuchoose_input.setText("您不可操作");
stuchoose_input.setEnabled(false);
stuchoose_panel.add(stuchoose_input);
stuchoose_panel.setPreferredSize(new Dimension(520,60));
stuchoose_panel.setOpaque(false);
add(stuchoose_panel);
//操作题文字
stuoperate_txt.setPreferredSize(new Dimension(90,18));
stuoperate_txt.setText("操作题分数:");
stuoperate_txt.setFont(font);
stuoperate_panel.add(stuoperate_txt);
//操作题面板
stuoperate_input.setPreferredSize(new Dimension(120,18));
stuoperate_input.setBorder(BorderFactory.createLineBorder(new Color(200,125,140)));
stuoperate_input.setToolTipText("此处您不可更改");
stuoperate_input.setText("您不可操作");
stuoperate_input.setEnabled(false);
stuoperate_panel.add(stuoperate_input);
stuoperate_panel.setPreferredSize(new Dimension(520,60));
stuoperate_panel.setOpaque(false);
add(stuoperate_panel);
//添加按钮
submit.setPreferredSize(new Dimension(80,18));
submit.setBorder(null);
submit.setBackground(new Color(207,207,157));
submit.setCursor(new Cursor(Cursor.HAND_CURSOR));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -