Java固定资产管理系统源代码Word版Word格式.docx
《Java固定资产管理系统源代码Word版Word格式.docx》由会员分享,可在线阅读,更多相关《Java固定资产管理系统源代码Word版Word格式.docx(56页珍藏版)》请在冰豆网上搜索。
staticConnectionconn=null;
staticStatementstat=null;
staticResultSetrs=null;
staticStringurl="
jdbc:
sqlserver:
//127.0.0.1:
1433;
DatabaseName=_Property"
;
staticStringuser="
sa"
staticStringpassword="
"
JPanelp1,p2,p3,p4,p5;
JLabellbl1,lbl2,lbl3,lbl4;
JTextFieldtxt_name;
JPasswordFieldtxt_pwd;
JButtonbtn1,btn2,btn3;
static{
try{
Class.forName("
com.microsoft.sqlserver.jdbc.SQLServerDriver"
);
}catch(Exceptione){
System.out.println("
加载驱动失败"
e.printStackTrace();
}
}
publicuser_land(){
this.setTitle("
固定资产及设备用户登录"
p1=newJPanel();
p2=newJPanel();
p3=newJPanel();
p4=newJPanel();
p5=newJPanel();
lbl1=newJLabel("
欢迎登录"
lbl2=newJLabel("
用户名:
lbl3=newJLabel("
密码:
lbl4=newJLabel();
txt_name=newJTextField(10);
txt_pwd=newJPasswordField(10);
btn1=newJButton("
登录"
btn2=newJButton("
清空"
btn3=newJButton("
退出"
p1.add(lbl1);
p2.add(lbl2);
p2.add(txt_name);
p3.add(lbl3);
p3.add(txt_pwd);
p4.add(btn1);
p4.add(btn2);
p4.add(btn3);
p5.add(lbl4);
this.setLayout(newGridLayout(5,1));
this.add(p1);
this.add(p2);
this.add(p3);
this.add(p4);
this.add(p5);
this.setBounds(400,300,400,300);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
//添加按钮登录事件
btn1.addActionListener(
newActionListener(){
publicvoidactionPerformed(ActionEvente){
if((txt_name.getText().equals("
)==true)&
&
(txt_pwd.getText().equals("
)==false))
lbl4.setText("
登录失败,用户名不能为空"
)==false)&
)==true))
登录失败,密码不能为空"
登录失败,用户名/密码不能为空"
if(is_Property()){
newSys_interface().show();
}
elseif((txt_name.getText().equals("
登录失败,用户名/密码错误"
}
}
);
btn1.addActionListener(this);
//清空用户名和密码
btn2.addActionListener(
newActionListener(){
publicvoidactionPerformed(ActionEvente){
txt_name.setText(null);
txt_pwd.setText(null);
lbl4.setText(null);
}
);
//退出
btn3.addActionListener(
System.exit(0);
protectedvoiduser_land(ObjectsetVisible){
//TODOAuto-generatedmethodstub
publicbooleanis_Property(){
conn=DriverManager.getConnection(url,user,password);
//System.out.println("
连接成功"
stat=conn.createStatement();
Stringsql="
select*fromAdmin_Info"
rs=stat.executeQuery(sql);
while(rs.next()){
//System.out.println(rs.getString("
A_name"
)+"
\t"
+rs.getString("
A_pwd"
));
Stringname=txt_name.getText();
Stringpwd=txt_pwd.getText();
if(name.equals(rs.getString("
))&
pwd.equals(rs.getString("
))){
//System.out.println("
登录成功!
!
returntrue;
}catch(SQLExceptione){
连接失败!
!
//关闭数据库
finally{
try{
if(rs!
=null){
rs.close();
if(stat!
stat.close();
if(conn!
conn.close();
}catch(Exceptione2){
System.out.println("
关闭失败"
e2.printStackTrace();
returnfalse;
publicstaticvoidmain(String[]args){
newuser_land();
publicvoidactionPerformed(ActionEvente){
//System.exit(0);
this.setVisible(false);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
主界面
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
importjava.awt.BorderLayout;
importjava.a