資源簡介
隨機點名器是一個能夠從Excel文件的某個Sheet中讀出班級所有同學的名單,然后通過產生一個隨機數選中其中一個同學回答問題,然后輸入回答問題的得分,并將該得分存入Excel表的另外一個Sheet中的簡單程序。 實現要點:通過開源項目jExcel提供的jxl.jar包,實現Excel文件的讀寫。很適合做課程設計使用。(內含可直接在Eclipse運行的源代碼和課程設計報告)

代碼片段和文件信息
package?com.gdupt.javabigjob;
import?java.awt.Container;
import?java.awt.FlowLayout;
import?java.awt.event.ActionEvent;
import?java.awt.event.ActionListener;
import?java.sql.Connection;
import?java.sql.DriverManager;
import?java.sql.ResultSet;
import?java.sql.SQLException;
import?java.sql.Statement;
import?javax.swing.JButton;
import?javax.swing.Jframe;
import?javax.swing.JLabel;
import?javax.swing.JMenu;
import?javax.swing.JMenuBar;
import?javax.swing.JMenuItem;
import?javax.swing.JOptionPane;
import?javax.swing.JPasswordField;
import?javax.swing.JTextField;
import?com.mysql.jdbc.BlobFromLocator;
//定義Window
public?class?LoginWin?extends?Jframe?implements?ActionListener?{
//創建組件
private?JLabel?lblUserName;?//標簽
private?JLabel?lblUserPsw;
private?JTextField?txfUserName;?//文本框
private?JPasswordField?pwfUserPsw;?//密碼框
private?JButton?btnSubmit;?//按鈕
private?JButton?btnCencal;
//構造方法
public?LoginWin()?{
//實例化各組件對象
this.lblUserName?=?new?JLabel(“用戶:“);
this.lblUserPsw?=?new?JLabel(“密碼:“);
this.txfUserName?=new?JTextField(20);
this.pwfUserPsw?=?new?JPasswordField(20);
this.btnSubmit?=?new?JButton(“確定“);
this.btnCencal?=?new?JButton(“取消“);
//為按鈕設置名字
this.btnSubmit.setName(“btnSubmit“);
this.btnCencal.setName(“btnCencal“);
//注冊監聽者
this.btnSubmit.addActionListener(this);
this.btnCencal.addActionListener(this);
//取得窗口的內容面板
Container?container?=?this.getContentPane();
//設置布局管理器
container.setLayout(new?FlowLayout());
//將各組件添加到窗口
this.add(lblUserName);
this.add(txfUserName);
this.add(lblUserPsw);
this.add(pwfUserPsw);
this.add(btnSubmit);
this.add(btnCencal);
//設置窗口屬性(標題,大小,位置,可視化...)
this.settitle(“請登錄“);
this.setSize(300?250);
this.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
this.setLocation(400?200);
this.setVisible(true);
}
@Override?//設置監聽方式
public?void?actionPerformed(ActionEvent?e)?{
//獲得事件源
object?o?=?e.getSource();
//如果o是按鈕
if(o?instanceof?JButton)?{
//將o轉型為按鈕
JButton?button?=?(JButton)?o;
//獲得名字
String?name?=?button.getName();
if(“btnSubmit“.equals(name))?{
Connection?cnt?=?this.getDatabaseCon();
try?{
Statement?s?=?cnt.createStatement();
ResultSet?rs?=?s.executeQuery(“select*?from?ManagerialStaff?where?username=‘“?+?txfUserName.getText()?+?“‘?and?userpsw=‘“?+?pwfUserPsw.getText()?+?“‘;“);
if(rs.next())?{
JOptionPane.showMessageDialog(null?“登錄成功!“);
this.dispose();
s.close();
cnt.close();
MainWindow?mw?=?new?MainWindow();
}else?{
JOptionPane.showMessageDialog(null?“登錄失敗,請重試!“);
}
}?catch?(SQLException?e1)?{
//?TODO?Auto-generated?catch?block
e1.printStackTrace();
}
}
if(“btnCencal“.equals(name))?{
JOptionPane.showMessageDialog(null?“歡迎?“?+?this.txfUserName.getText()?+?“?再來!“);
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-03-27?20:13??基于Java的課堂隨機點名器\
?????目錄???????????0??2018-03-27?20:13??基于Java的課堂隨機點名器\源代碼_可直接運行\
?????文件????????4542??2017-12-15?15:54??基于Java的課堂隨機點名器\源代碼_可直接運行\LoginWin.java
?????文件???????10403??2017-12-18?23:20??基于Java的課堂隨機點名器\源代碼_可直接運行\MainWindow.java
?????文件?????????133??2017-12-18?23:18??基于Java的課堂隨機點名器\源代碼_可直接運行\Test.java
?????文件??????126686??2018-03-27?20:11??基于Java的課堂隨機點名器\課程設計報告.docx
- 上一篇:基于Java的課堂_隨機點名器
- 下一篇:xm
l加xslt轉化成html
評論
共有 條評論