Java登陆注册系统模仿qq登陆界面.docx

上传人:b****1 文档编号:231002 上传时间:2022-10-07 格式:DOCX 页数:11 大小:109.20KB
下载 相关 举报
Java登陆注册系统模仿qq登陆界面.docx_第1页
第1页 / 共11页
Java登陆注册系统模仿qq登陆界面.docx_第2页
第2页 / 共11页
Java登陆注册系统模仿qq登陆界面.docx_第3页
第3页 / 共11页
Java登陆注册系统模仿qq登陆界面.docx_第4页
第4页 / 共11页
Java登陆注册系统模仿qq登陆界面.docx_第5页
第5页 / 共11页
点击查看更多>>
下载资源
资源描述

Java登陆注册系统模仿qq登陆界面.docx

《Java登陆注册系统模仿qq登陆界面.docx》由会员分享,可在线阅读,更多相关《Java登陆注册系统模仿qq登陆界面.docx(11页珍藏版)》请在冰豆网上搜索。

Java登陆注册系统模仿qq登陆界面.docx

Java--登陆注册系统(数据库)

importjavax.swing.*;

importjava.awt.*;

importjava.awt.event.*;

importjava.sql.*;

publicclassDengLuextendsJFrameimplementsActionListener,KeyListener,ItemListener,FocusListener{

JLabeltop,bott;

JComboBoxcombobox;

JPasswordFieldpassword;

JButtonb_login,b_regedit;

JPanelpanelMain,panel_center;

publicDengLu(){

super("登陆系统");

panelMain=newJPanel(newBorderLayout(10,10)){

publicvoidpaintComponent(Graphicsg){

Graphics2Dg2=(Graphics2D)g;

super.paintComponent(g);

Imageimg=Toolkit.getDefaultToolkit().getImage("G:

\\image\\Denglubg.jpg");

g2.drawImage(img,0,0,this.getWidth(),this.getHeight(),this);

}

};

top=newJLabel();

top.setPreferredSize(newDimension(this.getWidth(),30));

bott=newJLabel();

bott.setForeground(Color.white);

bott.setPreferredSize(newDimension(this.getWidth(),25));

centerBuild();

additem();

panelMain.add(top,BorderLayout.NORTH);

panelMain.add(bott,BorderLayout.SOUTH);

panelMain.add(panel_center,BorderLayout.CENTER);

combobox.addItemListener(this);

password.addActionListener(this);

b_login.addActionListener(this);

b_regedit.addActionListener(this);

combobox.addFocusListener(this);

password.addFocusListener(this);

b_login.addFocusListener(this);

b_regedit.addFocusListener(this);

combobox.addKeyListener(this);

password.addKeyListener(this);

this.addWindowListener(newWindowAdapter(){

publicvoidwindowClosing(WindowEventwe){

quit();

}

});

this.setContentPane(panelMain); //设置窗口面板

this.setSize(350,235);

Dimensionfrm=this.getSize();

Dimensionscr=Toolkit.getDefaultToolkit().getScreenSize();

this.setLocation((scr.width-frm.width)/2,(scr.height-frm.height)/2);

this.setResizable(false); //设置窗口不可放大缩小

this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

//sunswing.setWindowCenter(this);

this.setVisible(true);

//password.requestFocus(true); //设置焦点给密码框

}

privatevoidcenterBuild(){

JLabelL1,L2;

panel_center=newJPanel(null);

panel_center.setOpaque(false);

L1=newJLabel("用户名:

");

L1.setForeground(Color.white);

L2=newJLabel("登录密码:

");

L2.setForeground(Color.white);

b_login=newJButton("登陆");

b_regedit=newJButton("注册");

combobox=newJComboBox();

combobox.addItem("");

password=newJPasswordField();

L1.setBounds(50,14,60,20);

L2.setBounds(50,48,60,20);

b_login.setBounds(68,87,86,28);

b_regedit.setBounds(186,87,86,28);

combobox.setBounds(115,12,171,23);

password.setBounds(115,46,170,23);

combobox.setEditable(true);

panel_center.add(L1);

panel_center.add(L2);

panel_center.add(b_login);

panel_center.add(b_regedit);

panel_center.add(combobox);

panel_center.add(password);

}

privatevoidquit(){

intflag=0;

Stringmsg="您现在要关闭系统吗?

";

flag=JOptionPane.showConfirmDialog(null,msg,"提示",JOptionPane.YES_NO_OPTION);

if(flag==JOptionPane.YES_OPTION){

this.setVisible(false);

System.exit(0);

}

}

/**=======================================================================**

* 【##privatevoidzhuce】注册用户界面

* 参数:

* 返回值:

* 权限:

private

* 功能:

通过“用户名,登陆密码”进行用户注册

**=======================================================================**

*/

private voidzhuce(){

Stringutext=String.valueOf(combobox.getSelectedItem());

Stringptext=password.getText();

if(utext.trim().equals("")||ptext.equals("")){

JOptionPane.showMessageDialog(null,"用户名、登陆密码不能为空!

",

"警告",JOptionPane.INFORMATION_MESSAGE);

}

else{

Connectionconn=null;

PreparedStatementps=null;

ResultSetrs=null;

try{

conn=Utils.getConnection();

Stringsql="selectusersfromlogin.dluwhereusers=?

";

ps=conn.prepareStatement(sql);

ps.setString(1,utext);

rs=ps.executeQuery();

if(rs.next()){ //用户存在

JOptionPane.showMessageDialog(null,"该用户已注册,请重新输入用户名注册,\n或者直接登录!

",

"提醒",JOptionPane.INFORMATION_MESSAGE);

}

else{

if(ptext.length()>=6){

sql="insertintologin.dlu(users,passwords)values(?

?

)";

ps=conn.prepareStatement(sql);

ps.setString(1,utext);

ps.setString(2,ptext);

intup=ps.executeUpdate();

if(up==1){

JOptionPane.showMessageDialog(null,"注册成功,\n可以直接登录!

",

"提醒",JOptionPane.INFORMATION_MESSAGE);

bott.setText("已注册成功!

请登录!

");

combobox.removeAllItems();

additem();

}

}

else{

bott.setText("提示:

密码不能小于六位数!

");

}

}

}

catch(Exceptione){

thrownewRunException(e.getMessage(),e);

}

finally{

Utils.free(rs,ps,conn);

}

}

}

/**=======================================================================**

* 【##privatevoidadditem()】增加最

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 考试认证 > IT认证

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1