appletclient.java.bak
字号:
import java.applet.Applet;
import java.awt.*;
import java.net.*;
import java.io.*;
public class AppletClient extends Applet
{ TextArea AcceptText=new TextArea(4,25);
TextField SendText=new TextField(25);
Socket s=null;
int port=1000;
DataInputStream sin=null;
PrintStream sout=null;
String HostName="192.168.0.6";
// String HostName="127.0.0.1";
public void init()
{ setLayout(new GridLayout(3,1));
add(AcceptText);
add(SendText);
SendText.setText("Client Area");
add(new Button("Submit"));
try
{ s=new Socket(HostName,port);
sin=new DataInputStream(s.getInputStream());
sout=new PrintStream(s.getOutputStream());
}
catch(UnknownHostException e)
{ AcceptText.appendText("\n"+"Don't know about host"+HostName);
}
catch(IOException e)
{ AcceptText.appendText("\n"+"Canot get I/O for the Connect to"+HostName);
}
AcceptText.appendText("Connected to "+s.getInetAddress()+":"+s.getPort());
}
public boolean action(Event event, Object arg)
{ if(arg.equals("Submit"))
{ String acceptString;
try
{ if(SendText.getText()!=null)
{ sout.println(SendText.getText());
if((acceptString =sin.readLine())!=null)
AcceptText.appendText("\n"+acceptString);
else
{ AcceptText.appendText("\n"+"Closed by Server");
}
}
}
catch(IOException e)
{ AcceptText.appendText("\n"+"I/O failed on the connection to"+HostName);
}
}
else
return super.action(event,arg);
return true;
}
public void destory()
{ try
{ sin.close();
sout.close();
s.close();
}
catch(IOException e)
{ AcceptText.appendText("\n"+"I/O failed on the connection to"+HostName);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -