Home > Back-end >  To monitor call client components can't display
To monitor call client components can't display

Time:09-27

Protected void do_button_actionPerformed (MouseEvent e) {
JList Lt=(JList) Um participant etSource ();
Int clickCount=um participant etClickCount ();
If (clickCount==2) {
@ SuppressWarnings (" deprecation ")
Object [] ob=lt getSelectedValues ();
String s4=(String) ob [0].
If (s4. Equals (" server ")) {
The new network ();//this is my client class
}

Followed by the client, I run the client have no problem alone, to monitor the calling component cannot display, now show the connection, the server can also communication
Public class network {
/* *
* @ author zhuxiaobu
* create LAN communication main interface
*/
Private static final long serialVersionUID=- 699 l;
Private JPanel j1.
Private JTextArea jt1;
Private JTextArea jt2;
Protected Socket client=null;
Private File sendImageFile=null;
Private Image receiveImage=null;
Private background back2;
Private background back3;
Protected DataOutputStream out1.
Protected a DataInputStream in1.
Private File fe1=null;
Private File fe2=null;
Private Image backImage=null;
Private JFrame fm1;
The public network () {
init();
Jt1. Append (" trying to connect... \n");
Try {
The client=new Socket (" 127.0.0.1 ", 1609);//instantiate the Socket object
Jt1. Append (" connection success \ n ");//output information
While (true) {//if the socket is connected state
if (client !=null & amp; & ! Client. IsClosed ()) {
The out1=new DataOutputStream (client. GetOutputStream ());//get the output stream object
In1=new a DataInputStream (client. GetInputStream ());//get the input stream object
GetServerInfo ();
}
The else {
The client=new Socket (" 127.0.0.1 ", 1609);
}
}
} the catch (Exception e) {
e.printStackTrace();//output exception information
}
}
Private void getServerInfo () {
Try {
String name=in1. ReadUTF ();
Long length=in1. ReadLong ();
Byte [] b1=new byte [(int) length];//create an array of bytes
for(int i=0; iB1 [I]=in1. ReadByte ();
}
If (name. Equals (" String ")) {
String s1=new String (b1);
Jt1. Append (" server: "+ s1 +" \ n ");
}
Else if (name) equals (" Image ")) {
ReceiveImage=new ImageIcon (b1). The getImage ();
Back2. SetImage (receiveImage);
Back2. Repaint ();
}
The else {
FileDialog dialog=new FileDialog (fm1, "save");//create dialog
Dialog. SetMode (FileDialog. SAVE);//Settings dialog to save dialog
Dialog. SetFile (name);
Dialog. SetVisible (true);//show the save dialog
String path=dialog. GetDirectory ();//get the file save the path
String newFileName=dialog. GetFile ();//get a save file name
If (path==null | | newFileName==null) {
return;
}
String pathAndName=path + "\ " + newFileName;//the full path to the file
FileOutputStream fOut=new FileOutputStream (pathAndName);
FOut. Write (b1);
FOut. Flush ();
FOut. Close ();
Jt1. Append (" file receiving end, ");
}
} the catch (Exception e) {
} the finally {
Try {
If (in1!=null) {
In1. Close ();//off flow
}
if (client !=null) {
Client. The close ();//close the socket
}
} the catch (IOException e) {
e.printStackTrace();
}
}
}
Public void init () {
Fm1=new JFrame ();
Fm1. SetTitle (" client ");
Fm1. SetResizable (false);
Fm1. SetBounds (200200610510);
J1=new JPanel ();
J1. SetLayout (new BorderLayout (0, 0));
J1. SetBorder (new EmptyBorder (5, 5, 5, 5));
The Container c1=fm1. GetContentPane ();
C1. The add (j1, BorderLayout. CENTER);
JPanel j2=new JPanel ();
Dimension di1=new Dimension (600 ');
J2. SetPreferredSize (di1);
J1. Add (j2, BorderLayout. NORTH);
Background back1=new background ();
Back1. SetImage (Toolkit. GetDefaultToolkit (). The getImage (getClass (). The getResource ("/background1. JPG ")));
J2. SetLayout (new BorderLayout (0, 0));
J2. Add (back1, BorderLayout. CENTER);
JPanel j3=new JPanel ();
Dimension di2=new Dimension (480260);
J3. SetPreferredSize (di2);
J3. SetLayout (new BorderLayout (0, 0));
J1. Add (j3, BorderLayout. CENTER);
Jt1=new JTextArea ();
The JScrollPane js1=new JScrollPane (jt1);
Jt1. SetLineWrap (true);
J3. Add (js1, BorderLayout. CENTER);
JPanel j4=new JPanel ();
Dimension di3=new Dimension (480150);
J4. SetPreferredSize (di3);
J4. SetLayout (new BorderLayout (0, 0));
J1. Add (j4, BorderLayout. SOUTH);
JPanel j5=new JPanel ();
Dimension di4=new Dimension (480-30);
J5. SetPreferredSize (di4);
J5. SetBorder (new LineBorder (Color black));
J5. SetLayout (new FlowLayout (FlowLayout. LEFT));
J4. Add (j5, BorderLayout. NORTH);
JButton btn2=new JButton (" font ");
Btn2. AddActionListener (new ActionListener () {
@ Override
Public void actionPerformed (an ActionEvent e) {
//show the color selection dialog
JFontChooser one=new JFontChooser (new Font (" founder ShuTi ", the Font, BOLD, 18), the new Color (204102255));
//JFontChooser one=new JFontChooser ();//no arguments
One. The showDialog (null, 500200);
//get selected font
The Font Font=one. GetSelectedfont ();
//get to choose the color of the
Color Color=one. GetSelectedcolor ();
If (the font!=null& & Color! nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related