1.先安裝SWT Designer插件.
2.新建SWT/JFace項目


3.在可視窗口中Design中,進行增加如下組件.

4.各選中文本組件在Events屬性中選中事件處理類型verity->text 并雙擊后面區域,這樣將到它進行監聽注冊.


5.選中事件處理類型Selection->widgetselected并雙擊后面區域,這樣將到它進行監聽注冊.

6.雙擊提交后進入代碼編輯界面,輸入代碼:
??button.addSelectionListener(new SelectionAdapter() {
???public void widgetSelected(final SelectionEvent e) {
????
????String sname = name.getText();
????String spwd = pwd.getText();
????try {
?????Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
?????Connection con = DriverManager.getConnection(
???????"jdbc:odbc:test", "", "");
?????Statement stmt = con.createStatement();
?????ResultSet rs = stmt
???????.executeQuery("select * from userid where name='"+sname+"'and psw='"+spwd+"'");
?????if (rs.next()) {
??????MessageDialog.openInformation(shell, "",
????????"謝謝你的登錄!你是合法用戶!");
?????} else {
??????MessageDialog.openInformation(shell, "",
????????"請你正確登錄!用戶名或密碼不正確!");
?????}
?????rs.close();
?????stmt.close();
?????con.close();
????} catch (Exception e1) {
?????e1.printStackTrace();
????}
???}
??});
7.運行如下:



8.如下為數據庫設計,當然要在這個項目之運行之前設計好!


對新手一定是絕好的教程哦
posted on 2006-08-25 09:08
摩西 閱讀(726)
評論(0) 編輯 收藏