Java Online Chat Project client Login window Logindialog registered user function Modify Register logic add empty username password feedback increase showmessagedialog () prompt box

Source: Internet
Author: User

The code for the Logindialog class is modified as follows:

 PackageCom.swift.frame;ImportJava.awt.EventQueue;Importjava.awt.event.ActionEvent;ImportJava.awt.event.ActionListener;ImportJava.awt.event.WindowAdapter;Importjava.awt.event.WindowEvent;ImportJava.io.DataInputStream;ImportJava.io.DataOutputStream;Importjava.io.IOException;Importjava.net.ConnectException;ImportJava.net.Socket;Importjava.sql.Connection;Importjava.sql.PreparedStatement;Importjava.sql.SQLException;ImportJavax.swing.JButton;ImportJavax.swing.JDialog;ImportJavax.swing.JFrame;ImportJavax.swing.JLabel;ImportJavax.swing.JPanel;ImportJavax.swing.JPasswordField;ImportJavax.swing.JTextField;ImportJavax.swing.UIManager;Importjavax.swing.UnsupportedLookAndFeelException;ImportJavax.swing.border.TitledBorder;ImportCom.swift.jdbc.DBAdd;ImportCom.swift.jdbc.DBUtil;ImportCom.swift.jdbc.User;ImportCom.swift.util.Center; Public classLogindialogextendsJDialog {PrivateJPasswordField passwordfield_2; PrivateJPasswordField passwordfield_1; PrivateJTextField textfield_2; PrivateJTextField TextField;    Socket s;    DataOutputStream dos;    DataInputStream dis;  Public Static voidMain (String args[]) {jframe.setdefaultlookandfeeldecorated (true); Jdialog.setdefaultlookandfeeldecorated (true); Try{Uimanager.setlookandfeel ("Javax.swing.plaf.nimbus.NimbusLookAndFeel"); } Catch(ClassNotFoundException E1) {e1.printstacktrace (); } Catch(instantiationexception E1) {e1.printstacktrace (); } Catch(illegalaccessexception E1) {e1.printstacktrace (); } Catch(unsupportedlookandfeelexception E1) {e1.printstacktrace (); } eventqueue.invokelater (NewRunnable () { Public voidrun () {Try{Logindialog Dialog=NewLogindialog (); Dialog.addwindowlistener (NewWindowadapter () { Public voidwindowclosing (windowevent e) {system.exit (0);                    }                    }); Dialog.setvisible (true); } Catch(Exception e) {e.printstacktrace ();    }            }        }); }     PublicLogindialog () {Super(); Setresizable (false); Settitle ("Online Chat Login Box"); Getcontentpane (). setlayout (NULL); SetBounds (100, 100, 427, 301);//registration height of 578, not registered is 301//Set Window Center         This. setlocation (Center.getpoint ( This. GetSize ())); FinalJButton button_1 =NewJButton (); Button_1.settext (Login); Button_1.setbounds (230, 222, 106, 36);        Getcontentpane (). Add (button_1); FinalJTextField textfield_1 =NewJTextField (); Textfield_1.setbounds (148, 90, 192, 42);        Getcontentpane (). Add (Textfield_1); FinalJLabel label =NewJLabel (); Label.settext (Account); Label.setbounds (76, 102, 66, 18);        Getcontentpane (). Add (label); FinalJLabel Label_1 =NewJLabel (); Label_1.settext (Password); Label_1.setbounds (76, 167, 66, 18);        Getcontentpane (). Add (Label_1); FinalJPasswordField Passwordfield =NewJPasswordField (); Passwordfield.setbounds (148, 155, 192, 42);        Getcontentpane (). Add (Passwordfield); FinalJButton button =NewJButton (); Button.addactionlistener (NewActionListener () { Public voidActionperformed (FinalActionEvent e) {                if(Logindialog. This. getheight () = = 301) {Logindialog. This. SetSize (427, 578); } Else{logindialog. This. setSize (427, 301); }                //The Settings window is continuously centeredLogindialog. This. setlocation (Center.getpoint (Logindialog. This. GetSize ()));        }        }); Button.settext (Registry); Button.setbounds (76, 222, 106, 36);        Getcontentpane (). Add (button); FinalJPanel Panel =NewJPanel (); Panel.setlayout (NULL); Panel.setborder (NewTitledborder (NULL, "Registered user", Titledborder.default_justification, Titledborder.default_position,NULL,NULL)); Panel.setbounds (10, 278, 401, 226);        Getcontentpane (). Add (panel); FinalJLabel label_2 =NewJLabel (); Label_2.setbounds (44, 41, 65, 18); Label_2.settext ("Phone Number:");        Panel.add (label_2); TextField=NewJTextField (); Textfield.setbounds (115, 35, 225, 30);        Panel.add (TextField); FinalJButton button_2 =NewJButton (); Button_2.settext ("Send Verification"); Button_2.setbounds (243, 75, 97, 30);        Panel.add (button_2); Textfield_2=NewJTextField (); Textfield_2.setbounds (115, 104, 95, 30);        Panel.add (textfield_2); FinalJLabel Label_3 =NewJLabel (); Label_3.settext ("Verification Code:"); Label_3.setbounds (44, 110, 65, 18);        Panel.add (Label_3); Passwordfield_1=NewJPasswordField (); Passwordfield_1.setbounds (115, 143, 231, 30);        Panel.add (passwordfield_1); Passwordfield_2=NewJPasswordField (); Passwordfield_2.setbounds (115, 175, 231, 30);        Panel.add (passwordfield_2); FinalJLabel Label_4 =NewJLabel (); Label_4.settext ("Password:"); Label_4.setbounds (44, 149, 65, 18);        Panel.add (Label_4); FinalJLabel label_5 =NewJLabel (); Label_5.settext ("Verify Password:"); Label_5.setbounds (44, 181, 65, 18);        Panel.add (label_5); FinalJButton button_3 =NewJButton (); Button_3.setbounds (47, 510, 97, 30);        Getcontentpane (). Add (Button_3); Button_3.settext (Give up); FinalJButton Button_4 =NewJButton (); Button_4.addactionlistener (NewActionListener () { Public voidActionperformed (FinalActionEvent e) {String phone=Textfield.gettext (); String Password=NULL; String str1=NewString (Passwordfield_1.getpassword ()). Trim (); String str2=NewString (Passwordfield_2.getpassword ()). Trim (); if(!phone.equals (") &&!str1.equals (" ") &&!str2.equals (" ")) {                    if(Str1.equals (str2)) {Password=NewString (Passwordfield_2.getpassword ()). Trim (); Try{dos.writeutf (phone);                        Dos.writeutf (password); } Catch(IOException E1) {e1.printstacktrace (); }                    } Else{javax.swing.JOptionPane.showMessageDialog (logindialog). This, "Input password is inconsistent ..."); System.out.println ("Input password is inconsistent ..."); Passwordfield_1.settext (""); Passwordfield_2.settext (""); }                                    }Else{javax.swing.JOptionPane.showMessageDialog (logindialog). This, "User name password must be filled ..."); return;        }            }        }); Button_4.setbounds (262, 510, 97, 30);        Getcontentpane (). Add (Button_4); Button_4.settext ("Registered users");        Connect ();  This. Addwindowlistener (NewWindowadapter () {@Override Public voidwindowclosed (windowevent e) {disconnect ();    }        }); }     Public voidConnect () {Try{s=NewSocket ("127.0.0.1", 8888); System.out.println ("A client logged in ....!"); DOS=NewDataOutputStream (S.getoutputstream ()); Dis=NewDataInputStream (S.getinputstream ()); } Catch(connectexception e) {System.out.println ("Service-side exception ..."); System.out.println ("Please confirm that the server is open ..."); } Catch(IOException e) {e.printstacktrace (); }    }     Public voidDisconnect () {Try {            if(Dos! =NULL) Dos.close (); if(s! =NULL) S.close (); } Catch(IOException e) {e.printstacktrace (); }    }}

Java Online Chat Project client Login window Logindialog registered user function Modify Register logic add empty username password feedback increase showmessagedialog () prompt box

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.