资源描述:
《JAVA程序设计源码注释》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、importjava.awt.BorderLayout;importjava.awt.GridLayout;importjava.util.Hashtable;importjava.awt.event.*;importjavax.swing.*;publicclassMainFrameextendsJFrame{JPanelp_ctrl,p_content,p_term;JComboBoxwdchoose,wdnumber;JButtonb_start,b_ok,b_next,b_term;JLabelrtcnt,wgcnt,right,rate
2、;JTextFieldtxt_meaning,txt_word;Hashtablewdtable;String[]words,meanings;inti_right,i_wrong;floatf_rate;intindex=0;publicMainFrame(){super("单词测验");init();this.setLayout(newBorderLayout());this.add(p_ctrl,BorderLayout.NORTH);this.add(p_content,BorderLayout.CENTER
3、);this.add(p_term,BorderLayout.SOUTH);this.setSize(400,300);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}publicstaticvoidmain(String[]args){MainFramemf=newMainFrame();mf.setVisible(true);}voidinit(){p_ctrl=newJPanel();p_ctrl.setLayout(newGridLayout(1,3));wdchoose=newJ
4、ComboBox();for(inti=65;i<91;i++)wdchoose.addItem((char)i);wdchoose.addItem("全部");wdnumber=newJComboBox();for(intj=10;j<=100;j++)wdnumber.addItem(j);b_start=newJButton("开始答题");p_ctrl.add(wdchoose);p_ctrl.add(wdnumber);p_ctrl.add(b_start);p_content=newJPanel();p_content.setLayo
5、ut(newGridLayout(4,2));rtcnt=newJLabel("正确数:");wgcnt=newJLabel("错误数:");right=newJLabel("正确答案:");rate=newJLabel("正确率:");txt_word=newJTextField();txt_meaning=newJTextField();txt_meaning.setEditable(false);p_content.add(rtcnt);p_content.add(wgcnt);p_content.add(right);p_content.
6、add(rate);p_content.add(txt_meaning);p_content.add(txt_word);p_term=newJPanel();p_term.setLayout(newGridLayout(1,3));b_ok=newJButton("确认");b_next=newJButton("下一题");b_term=newJButton("结束");p_term.add(b_ok);p_term.add(b_next);p_term.add(b_term);b_start.addActionListener(newActi
7、onListener(){publicvoidactionPerformed(ActionEvente){index=0;Stringsql;Stringitem1=String.valueOf(wdchoose.getSelectedItem()),item2=String.valueOf(wdnumber.getSelectedItem());if(item1.equals("全部"))sql="select*fromwordslimit0,"+item2;elsesql="select*fromwordswherewordlike'"+it
8、em1+"%'limit0,"+item2;try{DBtools.connect();wdtable=DBtools.getWords