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
摩西 阅读(724)
评论(0) 编辑 收藏