题目要求:有用户登录等GUI界面,用户数据存在数据库里,并体现面向对象编程思想。
具体如下:
此系统要求包含维护、查询、统计三个主要模块。
- 维护模块完成商品的录入、修改和出库功能。
- 查询模块包括单项查询、组合查询,使用户能方便准确地获得所需数据,并能查询结果。
- 统计模块能够及时、准确地统计出用户所需的各种数据。
程序源代码
登录部分代码
package 项目;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Button;
public class Login {
Shell sShell = null; // @jve:decl-index=0:visual-constraint="12,7"
private Label label1 = null;
private Label label2 = null;
private Label label3 = null;
private Text text1 = null;
private Text text2 = null;
private Button buttondl = null;
private Button buttonzc = null;
private Label label4 = null;
public static void main(String[] args) {
Display display = Display.getDefault();
Login thisClass = new Login();
thisClass.createSShell();
thisClass.sShell.open();
while (!thisClass.sShell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
void createSShell() {
sShell = new Shell();
sShell.setText("登录");
sShell.setBackground(new Color(Display.getCurrent(), 255, 160, 100));
sShell.setSize(new Point(646, 420));
sShell.setLayout(null);
label1 = new Label(sShell, SWT.NONE);
label1.setBounds(new Rectangle(145, 26, 268, 74));
label1.setBackground(new Color(Display.getCurrent(), 255, 160, 100));
label1.setFont(new Font(Display.getDefault(), "华文行楷", 36, SWT.BOLD));
label1.setText("欢迎登录");
label2 = new Label(sShell, SWT.NONE);
label2.setBounds(new Rectangle(120, 133, 71, 28));
label2.setFont(new Font(Display.getDefault(), "微软雅黑", 10, SWT.NORMAL));
label2.setBackground(new Color(Display.getCurrent(), 255, 160, 100));
label2.setText("用户名:");
label3 = new Label(sShell, SWT.NONE);
label3.setBounds(new Rectangle(118, 207, 74, 29));
label3.setFont(new Font(Display.getDefault(), "微软雅黑", 10, SWT.NORMAL));
label3.setBackground(new Color(Display.getCurrent(), 255, 160, 100));
label3.setText(" 密 码:");
text1 = new Text(sShell, SWT.BORDER);
text1.setBounds(new Rectangle(203, 130, 210, 32));
text2 = new Text(sShell, SWT.BORDER | SWT.PASSWORD);
text2.setBounds(new Rectangle(203, 204, 214, 32));
buttondl = new Button(sShell, SWT.NONE);
buttondl.setBounds(new Rectangle(141, 300, 111, 39));
buttondl.setText("登录");
buttondl.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e){
String sql="select * from 用户登录";
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=D://仓库管理.mdb";
Connection con=DriverManager.getConnection(url,"","");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(sql); //结果集ResultSet
while(rs.next())
{
String id=rs.getString("用户名");
String pass=rs.getString("密码");
if(id.equals(text1.getText().trim())&&pass.equals(text2.getText().trim()))//标签事件
{
label4.setText("登录成功!");
主页面 zhuye = new 主页面();
zhuye.createSShell();
zhuye.sShell.open();
sShell.setVisible(false);//隐藏当前的窗口
}
else if(text1.getText().equals("")||text2.getText().equals("")||text1.getText().equals("")) {
label4.setText("用户名和密码不能为空!");
}
else{
label4.setText("用户名或密码错误,请重新输入!");
}
}
con.close()