import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.io.*;
import java.sql.*;
import javax.swing.table.*;
public class PaperSystem extends JFrame implements ActionListener,ItemListener,TableModelListener,ListSelectionListener,CaretListener
{
private JDialog dialog_connect,dialog_insert,dialog_select,dialog_new;
private JButton button_connect,button_cancel,button_insert,button_select,button_new;
private JTextField text_user,text_QTno1,text_Qno1,text_QTno2,text_Qno2,text_question,text_difficulty,text_answer,
text_itemA,text_itemB,text_itemC,text_itemD,text_Qinclude,text_Darrange1,text_Darrange2,text_Pno,
text_dif1,text_dif2;
private JPasswordField text_password;
private JComboBox combo_Qtype1,combo_Qtype2,combo_operator1,combo_logic,combo_operator2;
private JCheckBox check_question,check_difficulty;
private JRadioButton radio_all,radio_Qno,radio_require;
private JMenuItem menuitem_connect,menuitem_close,menuitem_exit,menuitem_insert,menuitem_select,menuitem_refresh,menuitem_delete,
menuitem_new,menuitem_open,menuitem_remove,menuitem_save,menuitem_theme,menuitem_about;
private JTable table_show;
private JPanel[] panel;
private JTextField []text_quantity,text_score;
private JLabel []label_score;
private JLabel label_total;
private JTextArea text_paper;
private JScrollPane scrollpane_table,scrollpane_text;
private DefaultTableModel dtm;
private int currentTable;
private Object []obj_editRow;
private Object []obj={"选择题","填空题","判断题","名词解释","简答题","应用题"};
private String []table={"Selection","Blank","Judge","Explain","Brief","Application"};
private String []chineseNum={"一","二","三","四","五","六"};
private String lastSelectSQL,paperNo;
private ConnectDB con;
public PaperSystem()
{
super("试题库系统");
this.setSize(800,600);
this.setLocation(200,100);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
dtm=new DefaultTableModel();
table_show=new JTable();
scrollpane_table=new JScrollPane(table_show);
table_show.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
table_show.getModel().addTableModelListener(this);
table_show.getSelectionModel().addListSelectionListener(this);
table_show.getTableHeader().setReorderingAllowed(false);
text_paper=new JTextArea();
text_paper.setFont(new Font("宋体",Font.PLAIN,16));
text_paper.setLineWrap(true);
scrollpane_text=new JScrollPane(text_paper);
this.createMenu();
this.createDialogInsert();
this.createDialogSelect();
this.createDialogNew();
this.setVisible(true);
this.createDialogConnect();
}
private void createDialogConnect()
{
dialog_connect=new JDialog(this,"连接到试题库",true);
dialog_connect.setSize(220,120);
dialog_connect.setDefaultCloseOperation(HIDE_ON_CLOSE);
dialog_connect.setResizable(false);
dialog_connect.setLayout(new FlowLayout());
dialog_connect.add(new JLabel("用户名: "));
text_user=new JTextField("sa",12);
dialog_connect.add(text_user);
dialog_connect.add(new JLabel("密 码: "));
text_password=new JPasswordField(12);
dialog_connect.add(text_password);
button_connect=new JButton("连 接");
button_cancel=new JButton("取 消");
button_connect.addActionListener(this);
button_cancel.addActionListener(this);
dialog_connect.add(button_connect);
dialog_connect.add(button_cancel);
dialog_connect.setLocation(this.getX()+this.getWidth()/2-110,this.getY()+this.getHeight()/2-60);
dialog_connect.setVisible(true);
}
private void createDialogInsert()
{
dialog_insert=new JDialog(this,"插入试题",true);
dialog_insert.setSize(400,260);
dialog_insert.setDefaultCloseOperation(HIDE_ON_CLOSE);
dialog_insert.setResizable(false);
dialog_insert.setLayout(new FlowLayout());
dialog_insert.add(new JLabel("题 型: "));
combo_Qtype1=new JComboBox(obj);
combo_Qtype1.addItemListener(this);
dialog_insert.add(combo_Qtype1);
dialog_insert.add(new JLabel(" 题 号: "));
text_QTno1=new JTextField("1");
text_QTno1.setEditable(false);
dialog_insert.add(text_QTno1);
text_Qno1=new JTextField(6);
dialog_insert.add(text_Qno1);
dialog_insert.add(new JLabel(" 难 度: "));
text_difficulty=new JTextField("3",4);
dialog_insert.add(text_difficulty);
dialog_insert.add(new JLabel("题 目: "));
text_question=new JTextField(30);
dialog_insert.add(text_question);
dialog_insert.add(new JLabel("A选项: "));
text_itemA=new JTextField(30);
dialog_insert.add(text_itemA);
dialog_insert.add(new JLabel("B选项: "));
text_itemB=new JTextField(30);
dialog_insert.add(text_itemB);
dialog_insert.add(new JLabel("C选项: "));
text_itemC=new JTextField(30);
dialog_insert.add(text_itemC);
dialog_insert.add(new JLabel("D选项: "));
text_itemD=new JTextField(30);
dialog_insert.add(text_itemD);
dialog_insert.add(new JLabel("答 案: "));
text_answer=new JTextField(30);
dialog_insert.add(text_answer);
button_insert=new JButton("添 加");
button_insert.addActionListener(this);
dialog_insert.add(button_insert);
}
private void createDialogSelect()
{
dialog_select=new JDialog(this,"查询试题",true);
dialog_select.setSize(280,260);
dialog_select.setDefaultCloseOperation(HIDE_ON_CLOSE);
dialog_select.setResizable(false);
dialog_select.setLayout(new FlowLayout(FlowLayout.LEFT));
dialog_select.add(new JLabel("请选择要查询的题型: "));
combo_Qtype2=new JComboBox(obj);
combo_Qtype2.addItemListener(this);
dialog_select.add(combo_Qtype2);
radio_all=new JRadioButton("查询全部",true);
dialog_select.add(radio_all);
dialog_select.add(new JLabel(" "));
radio_Qno=new JRadioButton("按题号");
text_QTno2=new JTextField("1");
text_QTno2.setEditable(false);
text_Qno2=new JTextField(6);
dialog_select.add(radio_Qno);
dialog_select.add(text_QTno2);
dialog_select.add(text_Qno2);
dialog_select.add(new JLabel(" "));
radio_require=new JRadioButton("按条件查询");
dialog_select.add(radio_require);
dialog_select.add(new JLabel(" "));
ButtonGroup bg_select=new ButtonGroup();
bg_select.add(radio_all);
bg_select.add(radio_Qno);
bg_select.add(radio_require);
check_question=new JCheckBox("题目包含",true);
dialog_select.add(check_question);
text_Qinclude=new JTextField(16);
dialog_select.add(text_Qinclude);
check_difficulty=new JCheckBox("难度",true);
dialog_select.add(check_difficulty);
Object []obj_operator={">=",">","=","<","<="};
Object []obj_logic={"AND","OR"};
combo_operator1=new JComboBox(obj_operator);
combo_operator2=new JComboBox(obj_operator);
combo_operator2.setSelectedIndex(4);
combo_logic=new JComboBox(obj_logic);
text_Darrange1=new JTextField(2);
text_Darrange2=new JTextField(2);
dialog_select.add(combo_operator1);
dialog_select.add(text_Darrange1);
dialog_select.add(combo_logic);
dialog_select.add(combo_operator2);
dialog_select.add(text_Darrange2);
button_select=new JButton("查 询");
button_select.addActionListener(this);
dialog_select.add(new JLabel(" "));
dialog_select.add(button_select);
}
private void createDialogNew()
{
int i,n=obj.length;
dialog_new=new JDialog(this,"新建试卷",true);
dialog_new.setSize(280,(n+2)*30+45);
dialog_new.setDefaultCloseOperation(HIDE_ON_CLOSE);
dialog_new.setResizable(false);
JPanel panel_main=new JPanel(new GridLayout(n+2,1)