The Code fmregister of the registration form is implemented as follows:
Package client;
Import javax. Swing .*;
Import java. AWT .*;
Import com. Borland. jbcl. layout .*;
Import java. AWT. event .*;
Import java.net .*;
Import java.net. Socket;
Import java. Io .*;
Import java. util. vector;
Public class fmregister extends jframe {
Xylayout xylayout1 = new xylayout ();
Jpanel jpanel1 = new jpanel ();
Jlabel jlabel1 = new jlabel ();
Xylayout xylayout2 = new xylayout ();
Jlabel jlabel2 = new jlabel ();
Jtextfield nickname = new jtextfield ();
Jlabel jlabel3 = new jlabel ();
Jpasswordfield Password = new jpasswordfield ();
Jpasswordfield confirm = new jpasswordfield ();
Jlabel jlabel4 = new jlabel ();
Jbutton jbutton1 = new jbutton ();
Jbutton jbutton2 = new jbutton ();
Jlabel jlabel5 = new jlabel ();
Jradiobutton boy = new jradiobutton ();
Jradiobutton girl = new jradiobutton ();
Jlabel jlabel6 = new jlabel ();
Jcombobox headpic = new jcombobox ();
Jlabel jlabel7 = new jlabel ();
Jtextfield email = new jtextfield ();
Jlabel jlabel8 = new jlabel ();
Jlabel jlabel9 = new jlabel ();
Jtextarea info = new jtextarea ();
Private string [] pics = new string [] {// Avatar
"1.jpg"," 3.jpg ",
"5.jpg"," 7.jpg "};
String sername; // server name
Int SERVERPORT; // server port
Vector myinfo = new vector ();
Jtextfield comefrom = new jtextfield ();
Public fmregister (string S, int port ){
Try {
Sername = s;
SERVERPORT = port;
Jbinit ();
}
Catch (exception ex ){
Ex. printstacktrace ();
}
}
Void jbinit () throws exception {
Xylayout1.setwidth (262 );
Xylayout1.setheight (350 );
This. getcontentpane (). setbackground (systemcolor. desktop );
This. setforeground (systemcolor. desktop );
This. setresizable (false );
This. setstate (frame. Normal );
This. settitle ("Apply for a jicq account ");
This. getcontentpane (). setlayout (xylayout1 );
Jlabel1.setfont (New java. AWT. Font ("", 1, 18 ));
Jlabel1.setforeground (systemcolor. inactivecaptiontext );
Jlabel1.setopaque (false );
Jlabel1.sethorizontalalignment (swingconstants. center );
Jlabel1.sethorizontaltextposition (swingconstants. center );
Jlabel1.settext ("jicq Registration Wizard ");
Jpanel1.setlayout (xylayout2 );
Jlabel2.setfont (New java. AWT. Font ("", 0, 14 ));
Jlabel2.setforeground (systemcolor. desktop );
Jlabel2.settext ("nickname :");
Jpanel1.setbackground (systemcolor. inactivecaptiontext );
Jpanel1.setborder (borderfactory. createloweredbevelborder ());
Jpanel1.setverifyinputwhenfocustarget (true );
Nickname. setforeground (systemcolor. desktop );
Nickname. settext ("");
Jlabel3.settext ("Password :");
Jlabel3.setforeground (systemcolor. desktop );
Jlabel3.setfont (New java. AWT. Font ("", 0, 14 ));
Jlabel4.setfont (New java. AWT. Font ("", 0, 14 ));
Jlabel4.setforeground (systemcolor. desktop );
Jlabel4.settext ("confirm :");
Jbutton1.setbackground (systemcolor. inactivecaptiontext );
Jbutton1.setfont (New java. AWT. Font ("", 0, 14 ));
Jbutton1.setforeground (systemcolor. desktop );
Jbutton1.setborder (borderfactory. createraisedbevelborder ());
Jbutton1.settext ("OK ");
Jbutton1.addactionlistener (New fmregister_jbutton?actionadapter (this ));
Jbutton2.setbackground (systemcolor. inactivecaptiontext );
Jbutton2.setfont (New java. AWT. Font ("", 0, 14 ));
Jbutton2.setforeground (systemcolor. desktop );
Jbutton2.setborder (borderfactory. createraisedbevelborder ());
Jbutton2.settext ("Remove ");
Jbutton2.addmouselistener (New java. AWT. event. mouseadapter (){
Public void mouseclicked (mouseevent e ){
Jbutton2_mouseclicked (E );
}
});
Password. settext ("");
Confirm. settext ("");
Jlabel5.settext ("Sex :");
Jlabel5.setforeground (systemcolor. desktop );
Jlabel5.setfont (New java. AWT. Font ("", 0, 14 ));
Boy. setbackground (systemcolor. inactivecaptiontext );
Boy. setfont (New java. AWT. Font ("", 0, 14 ));
Boy. setforeground (systemcolor. desktop );
Boy. setselected (true );
Boy. settext ("handsome brother ");
Girl. settext ("female ");
Girl. setforeground (systemcolor. desktop );
Girl. setbackground (systemcolor. inactivecaptiontext );
Girl. setfont (New java. AWT. Font ("", 0, 14 ));
Jlabel6.setfont (New java. AWT. Font ("", 0, 14 ));
Jlabel6.setforeground (systemcolor. desktop );
Jlabel6.settext ("header image :");
Headpic. setbackground (systemcolor. Window );
Headpic. setforeground (systemcolor. desktop );
Headpic. setborder (borderfactory. createlineborder (color. Black ));
Jlabel7.setforeground (systemcolor. desktop );
Jlabel7.setrequestfocusenabled (true );
Jlabel7.settext ("Mailbox :");
Jlabel7.setfont (New java. AWT. Font ("", 0, 14 ));
Email. settext ("");
Email. setforeground (systemcolor. desktop );
Jlabel8.settext ("from :");
Jlabel8.setforeground (systemcolor. desktop );
Jlabel8.setrequestfocusenabled (true );
Jlabel8.setfont (New java. AWT. Font ("", 0, 14 ));
Jlabel9.setfont (New java. AWT. Font ("", 0, 14 ));
Jlabel9.settext ("Signature :");
Jlabel9.setrequestfocusenabled (true );
Jlabel9.setforeground (systemcolor. desktop );
Info. setfont (New java. AWT. Font ("", 0, 14 ));
Info. setforeground (systemcolor. desktop );
Info. setborder (borderfactory. createlineborder (color. Black ));
Info. setcaretcolor (systemcolor. desktop );
Info. settext ("");
Comefrom. setfont (New java. AWT. Font ("", 0, 11 ));
Comefrom. setforeground (systemcolor. desktop );
Comefrom. settext ("");
This. getcontentpane (). Add (jpanel1, new xyconstraints (3, 27,254,279 ));
Jpanel1.add (Info, new xyconstraints (60,175,179, 93 ));
Jpanel1.add (nickname, new xyconstraints (60, 9,179, 17 ));
Jpanel1.add (jlabel2, new xyconstraints (8, 6,-1, 23 ));
Jpanel1.add (jlabel3, new xyconstraints (8, 33, 56, 23 ));
Jpanel1.add (password, new xyconstraints (60, 37,179, 17 ));
Jpanel1.add (jlabel4, new xyconstraints (8, 60, 56, 23 ));
Jpanel1.add (confirm, new xyconstraints (60, 64,179, 17 ));
Jpanel1.add (jlabel5, new xyconstraints (8, 88, 56, 23 ));
Jpanel1.add (boy, new xyconstraints (75, 92, 70, 18 ));
Jpanel1.add (girl, new xyconstraints (163, 92, 78, 18 ));
Jpanel1.add (jlabel7, new xyconstraints (8,142, 56, 23 ));
Jpanel1.add (jlabel9, new xyconstraints (8,169, 56, 23 ));
Jpanel1.add (email, new xyconstraints (60,148,179, 17 ));
Jpanel1.add (headpic, new xyconstraints (59,120, 59, 17 ));
Jpanel1.add (jlabel6, new xyconstraints (8,115, 56, 23 ));
Jpanel1.add (jlabel8, new xyconstraints (126,119,-1, 17 ));
Jpanel1.add (comefrom, new xyconstraints (177,121, 59, 18 ));
This. getcontentpane (). Add (jlabel1, new xyconstraints (46, 0,163, 24 ));
This. getcontentpane (). Add (jbutton2, new xyconstraints (145,318, 93, 21 ));
This. getcontentpane (). Add (jbutton1, new xyconstraints (21,317, 93, 21 ));
This. addwindowlistener (New windowadapter ()
{
Public void windowclosing (windowevent e ){
System. Exit (0 );
}
});
}
Void jbutton?action=med (actionevent e ){
// Problem: Confirm Password
/* If (! Password. GetPassword (). tostring (). Trim (). Equals (confirm. GetPassword (). tostring (). Trim ()))
{
Object MSG = "the password is inconsistent. Please enter it again! ";
Joptionpane. showmessagedialog (this, MSG, "jicq prompts you", joptionpane. error_message );
This. Password. settext ("");
This. Confirm. settext ("");
Return;
}*/
If (boy. isselected () & girl. isselected () | (! Boy. isselected ()&&! Girl. isselected ())){
Joptionpane. showmessagedialog (this, "Please select your gender, 'handsome guy 'or 'pretty girl '! "," Jicq prompts you ", joptionpane. error_message );
Boy. setselected (true );
Return;
}
Try {
System. Out. println (sername );
System. Out. println (SERVERPORT );
System. Out. println ("Now bagin registing your no ...");
Socket socket = new socket (inetaddress. getbyname (sername), SERVERPORT); // connect to the server
Bufferedreader in = new bufferedreader (New inputstreamreader (socket.
Getinputstream ()));
Printwriter out = new printwriter (New bufferedwriter (
New outputstreamwriter (socket. getoutputstream (), true );
String sex, IP;
If (boy. isselected ())
Sex = "handsome guy ";
Else
Sex = "beauty ";
IP = socket. getinetaddress (). getlocalhost (). gethostaddress ();
System. Out. println ("Client IP:" + IP );
Out. println ("new"); // sends a new user request
Out. println (nickname. gettext (). Trim (); // The name of the message to be sent.
Out. println (password. GetPassword ());
Out. println (email. gettext (). Trim ());
Out. println (info. gettext (). Trim ());
Out. println (comefrom. gettext ());
Out. println (headpic. getselectedindex (); // head picindex
Out. println (sex); // changed: add
Out. println (IP); // changed: add
String STR = "";
// Do {
STR = in. Readline (). Trim (); // read information from the server
// If an error occurs
If (Str. Equals ("false") joptionpane. showmessagedialog (this, "Sorry, error :-(",
"Jicq prompts you", joptionpane. information_message );
Else {// tell the user the number if the call succeeds
String no;
No = in. readline (). tostring (); //////////////////////////////////////// /// // tostring
Myinfo. Add (this. Nickname. gettext ());
Myinfo. Add (NO );
Myinfo. Add (IP );
Myinfo. Add ("1 ");
Myinfo. Add (string. valueof (this. headpic. getselectedindex ()));
Myinfo. Add (this. Email. gettext (). Trim ());
Myinfo. Add (this.info. gettext ());
Myinfo. Add (sex );
Myinfo. Add (this. comefrom. gettext (). tostring ());
Joptionpane. showmessagedialog (this, "registration successful. Your jicq number is" + NO, "jicq prompts you ",
Joptionpane. information_message );
This. Dispose (); // and open the Main Window
Fmmain main = new fmmain (myinfo, sername, SERVERPORT );
Main. Pack ();
Dimension screensize = toolkit. getdefatooltoolkit (). getscreensize ();
// Slide the form from the top right corner of the screen
Double left = screensize. getwidth ()-Main. getsize (). getwidth ();
Main. setlocation (INT) left, 0 );
Main. setvisible (true );
For (INT h = 0; H <= 445; H + = 1 ){
Main. setsize (183, H );
}
Main. setresizable (false );
}
// System. Out. println ("/N ");
//} While (! Str. Equals ("OK "));
// Socket. Close ();
}
Catch (ioexception E1 ){}
}
Void jbutton2_mouseclicked (mouseevent e ){
System. Exit (0 );
}
}
Class fmregister_jbutton?actionadapter implements java. AWT. event. actionlistener {
Fmregister adaptee;
Fmregister_jbutton?actionadapter (fmregister adaptee ){
This. adaptee = adaptee;
}
Public void actionreceivmed (actionevent e ){
Adaptee. jbutton?action=med (E );
}
}