📄 client.java
字号:
import java.net.*;
import java.io.*;
import java.awt.event.*;
import java.awt.*;
public class client extends WindowAdapter
implements ActionListener{
// Frame f;
TextField tf1,tf2,tf3;
Label label1,label2,label3;
Button b;
Panel p;
Socket s1;
OutputStream sout;
InputStream sin;
DataOutputStream dos;
DataInputStream dis;
float a1=0,a2=0,he=0;
public static void main(String args[]){
client ce = new client();
ce.go();
}
public void go()
{ Frame f=new Frame("wenhuiping");
p=new Panel();
p.setLayout(null);
tf1=new TextField();
tf2=new TextField();
tf3=new TextField();
label1=new Label("输入第一个数:");
label2=new Label("输入第二个数:");
label3=new Label("两个数之和:");
b=new Button("发送");
label1.setSize(100,15);
label2.setSize(100,15);
label3.setSize(80,15);
tf1.setSize(100,20);
tf2.setSize(100,20);
tf3.setSize(100,20);
b.setSize(50,20);
b.setLocation(50,50);
f.add(p,"Center");
p.add(label1);
label1.setLocation(120,50);
tf1.setLocation(120,100);
label2.setLocation(250,50);
tf2.setLocation(250,100);
label3.setLocation(120,200);
tf3.setLocation(200,200);
p.add(tf1);
p.add(label2);
p.add(tf2);
p.add(b);
p.add(label3);
p.add(tf3);
f.setSize(400,300);
f.setVisible(true);
f.addWindowListener(this);
b.addActionListener(this);
try{
s1=new Socket("localhost",8305);
}
catch(IOException e){}
}
public void windowClosing(WindowEvent e){
System.exit(0);
}
public void actionPerformed(ActionEvent e){
a1=Float.parseFloat(tf1.getText());
a2=Float.parseFloat(tf2.getText());
try{
sout=s1.getOutputStream();
dos=new DataOutputStream(sout);
dos.writeFloat(a1);
dos.writeFloat(a2);
sin=s1.getInputStream();
dis=new DataInputStream(sin);
he=dis.readFloat();
tf3.setText(String.valueOf(he));
}
catch(IOException ioe){}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -