Java登陆注册系统模仿qq登陆界面Word格式文档下载.docx
《Java登陆注册系统模仿qq登陆界面Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《Java登陆注册系统模仿qq登陆界面Word格式文档下载.docx(15页珍藏版)》请在冰豆网上搜索。
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
*功能:
通过“用户名,登陆密码”进行用户注册
**=======================================================================**
*/
privatevoidzhuce(){
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或者直接登录!
"
提醒"
}
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可以直接登录!
bott.setText("
已注册成功!
请登录!
combobox.removeAllItems();
additem();
}
}
else{
bott.setText("
提示:
密码不能小于六位数!
catch(Exceptione){
thrownewRunException(e.getMessage(),e);
finally{
Utils.free(rs,ps,conn);
*【##privatevoidadditem()】增加最后登录用户的7名
模仿qq的登录记录功能
privatevoidadditem(){
Connectionconn=null;
PreparedStatementps=null;
ResultSetrs=null;
try{
conn=Utils.getConnection();
Stringsql="
selectusersfromlogin.dlu"
ps=conn.prepareStatement(sql);
rs=ps.executeQuery();
rs.afterLast();
inti=0;
Strings=null;
while(rs.previous()&
&
i<
8){
i++;
s=rs.getString("
users"
combobox.addItem(s);
}catch(SQLExceptione){
thrownewRunException(e.getMessage(),e);
finally{
Utils.free(rs,ps,conn);
privatevoidgetPassword(){
Stringut=String.valueOf(combobox.getSelectedItem());
selectusers,passwordsfromlogin.dluwhereusers=?
ps.setString(1,ut);
Strings1=null;
while(rs.next()){
s1=rs.getString("
passwords"
password.setText(s1);
*【##privatevoiddenglu】登陆界面
密码验证通过,进入主操作界面,仅类内使用
privatevoiddenglu(){
if(rs.next()){
if(ptext.equals(rs.getString
(2))){
this.setVisible(false);
newMainProgram();
System.exit
(1);
JOptionPane.showMessageDialog(null,"
您输入的用户和密码不正确,\n请重新输入"
"
错误"
JOptionPane.ERROR_MESSAGE);
您输入的用户不存在,请重新输入,\n或者先注册"
JOptionPane.INFORMATION_MESSAGE);
}catch(Exceptione){
*ActionListener监听
publicvoidactionPerformed(ActionEventen){
if(en.getSource()==b_regedit){
zhuce();
elseif(en.getSource()==b_login){
denglu();
*ItemListener监听
publicvoiditemStateChanged(ItemEventes){
getPassword();
password.requestFocus(true);
*FocusListener监听
publicvoidfocusGained(FocusEventfe){
if(fe.getSource()==combobox){
bott.setText("
请输入用户名!
elseif(fe.getSource()==password){
请输入密码!
密码必须大于六位数"
elseif(fe.getSource()==b_login){
登录系统!
elseif(fe.getSource()==b_regedit){
注册账号"
publicvoidfocusLost(FocusEventesd){}
*KeyListener监听
publicvoidkeyPressed(KeyEventke){
if(ke.getKeyChar()==KeyEvent.VK_ENTER){
if(ke.getSource()==combobox){
password.requestFocus(true);
if(password.getPassword().length>
0){
denglu();
}elseif(ke.getKeyChar()==KeyEvent.VK_ESCAPE){//按ESC键退出系统
quit();
publicvoidkeyReleased(KeyEventkr){}
publicvoidkeyTyped(KeyEventkt){}
*主函数main接入口
publicstaticvoidmain(Stringargs[]){
newDengLu();
}
classRunExceptionextendsRuntimeException{
publicRunException(){
//TODOAuto-generatedconstructorstub
publicRunException(Stringmessage){
super(message);
publicRunException(Throwablecause){
super(cause);
publicRunException(Stringmessage,Throwablecause){
super(message,cause);
//TODOA