appletclient.java
来自「java网络高级编程的配套源码,java网络高级编程为清华出版社出版.」· Java 代码 · 共 74 行
JAVA
74 行
/*源程序清单8-19*/
import java.applet.*;
import borland.jbcl.layout.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
public class AppletClient extends Applet implements ActionListener
{
String hostname;
int port=8888;
TextField textField=new TextField();
static TextArea textArea=new TextArea();
Button button=new Button();
VerticalFlowLayout verticalFlowLayout = new VerticalFlowLayout();
UserThread userThread=null;
public AppletClient()
{
try
{
String p=getParamter("port");
port=Integer.parseInt(p);
URL url=this.getCodeBase();
String temp=url.getHost();
if(!(temp.equals("")))
hostname=temp;
else
hostname="127.0.0.1";
jbInit();
Socket socket=new Socket(hostname, port);
userThread=new UserThread(socket);
userThread.start();
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
public void jbInit() throws Exception
{
button.setLabel("发送信息");
this.setLayout(verticalFlowLayout);
textArea.setEditable(false);
this.add(textArea,null);
this.add(textField,null);
this.add(button,null);
textField.addActionListener(this);
button.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
Component com=(Component)e.getSource();
if(e.equals(button)||e.equals(textField))
{
sendString();
}
}
public void sendString()
{
String str=textField.getText();
if(userThread!=null)
{
userThread.sendString(str);
textField.setText("");
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?