?? web158_com_server_stulist.java
字號:
package web158.com;
/**
* @param 李建東
*
* 聯(lián)系電話:0898-62925341
*
* 聯(lián)系QQ:813751 657597 8912740
*
* 網(wǎng) 址:
* 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
{
//查詢相關(guān)PANEL
JPanel top_panel=new JPanel();
JTextField txtinfo=new JTextField();
JButton bSearch=new JButton("查詢考生");
JButton bInfo=new JButton("詳細(xì)及操作");
JButton bAdd=new JButton("添加考生");
//查詢列表
JPanel main_panel=new JPanel();
//滾動面板
JScrollPane jScrollPane=new JScrollPane();
//列表
JTable jTable=new JTable();
//列名內(nèi)容
Vector vcol=new Vector();
Vector vrow=new Vector();
//臨時(shí)用向量
Vector vtemp=new Vector();
//添加考生面板
stuAdd addStu=new stuAdd();
//更改刪除考生信息
stuOperate stuChange=new stuOperate();
//數(shù)據(jù)庫連接
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));
//設(shè)置透明
this.setOpaque(false);
//添加上面需要添加查詢等按鈕PANEL
//查詢表單
txtinfo.setPreferredSize(new Dimension(120,18));
txtinfo.setBorder(BorderFactory.createLineBorder(new Color(200,125,140)));
txtinfo.setToolTipText("可根據(jù)本關(guān)鍵字查找下表中任意字段考生信息");
top_panel.add(new JLabel("關(guān)鍵字:"));
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("可根據(jù)本關(guān)鍵字查找下表中任意字段考生信息");
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";
//調(diào)用查詢方法
getStulist(sql);
}
});
top_panel.add(bSearch);
//詳細(xì)信息按鈕
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("此操作只支持關(guān)鍵字為考生的準(zhǔn)考證號碼");
bInfo.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
//取得關(guān)鍵字
String key=txtinfo.getText();
key=key.replaceAll("'","''");
//沒有填寫準(zhǔn)考證號碼進(jìn)行考生信息操作不可操作
if(key.equals(""))
{
JOptionPane.showMessageDialog(null, "請?zhí)顚懸僮鞯目忌鷾?zhǔn)考證號碼!");
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);
//把本面板添加到主區(qū)
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 ";
//調(diào)用查詢方法
getStulist(sql);
//添加表面板
add(main_panel);
}
//處理事件
public void actionPerformed(ActionEvent e)
{
}
//查詢學(xué)生信息表
public void getStulist(String sql)
{
//先清空面板
vrow.removeAllElements();
vcol.removeAllElements();
main_panel.removeAll();
//添加列名
//初始化向量
vcol.addElement("考生姓名");
vcol.addElement("準(zhǔn)考證號");
vcol.addElement("操作成績");
vcol.addElement("是否取卷");
vcol.addElement("是否交卷");
//數(shù)據(jù)庫中查詢考生信息
try
{
rs=db.getResult(sql);
//開始行循環(huán)
while(rs.next())
{
//每次都需要把臨時(shí)向量創(chuàng)建新實(shí)例,否剛表中內(nèi)容會變成一樣的
vtemp=new Vector();
//列循環(huán)
for(int k=1;k<=6;k++)
{
vtemp.addElement(rs.getString(k));
}
//添加入行
vrow.addElement(vtemp);
}//行循環(huán)結(jié)束
}
catch(Exception ef)
{
System.out.println("查詢考生信息失敗"+ef.getMessage());
}
//創(chuàng)建表
jTable=new JTable(vrow,vcol);
//設(shè)置滾動條
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 查詢考生信息類
//查詢考生詳細(xì)信息更改等操作
public void getStuinfo(String stuid)
{
//JOptionPane.showMessageDialog(null, "現(xiàn)在執(zhí)行更改考生信息操作");
main_panel.removeAll();
//初始化參數(shù)
stuChange.setID(stuid);
//初始化詳細(xì)信息
stuChange.initStuinfo();
//添加
main_panel.add(stuChange);
//更新使其有效
main_panel.repaint();
main_panel.validate();
}
//添加考生信息
public void addStuinfo()
{
//初始化標(biāo)題文字
//刷新板塊
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();
//準(zhǔn)考證號板面/////////////////////////////////////////////////////////
JPanel stuid_panel=new JPanel();
//文字
JLabel stuid_txt=new JLabel();
//文本框
JTextField stuid_input=new JTextField();
//選擇題分?jǐn)?shù)/////////////////////////////////////////////////////////
JPanel stuchoose_panel=new JPanel();
//文字
JLabel stuchoose_txt=new JLabel();
//文本框
JTextField stuchoose_input=new JTextField();
//操作題目分?jǐn)?shù)/////////////////////////////////////////////////////////
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);
//數(shù)據(jù)庫連接
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格試照片以考號命名放到系統(tǒng)/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("請?zhí)顚懣忌彰?quot;);
stuname_panel.add(stuname_input);
stuname_panel.setPreferredSize(new Dimension(520,60));
stuname_panel.setOpaque(false);
add(stuname_panel);
//準(zhǔn)考證號文字
stuid_txt.setPreferredSize(new Dimension(90,18));
stuid_txt.setText("準(zhǔn)考證號:");
stuid_txt.setFont(font);
stuid_panel.add(stuid_txt);
//準(zhǔn)考證號面板
stuid_input.setPreferredSize(new Dimension(120,18));
stuid_input.setBorder(BorderFactory.createLineBorder(new Color(200,125,140)));
stuid_input.setToolTipText("請?zhí)顚憸?zhǔn)考證號碼");
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("選擇題分?jǐn)?shù):");
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("操作題分?jǐn)?shù):");
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));
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -