📄 computer_client.java
字号:
import java.net.*;import java.io.*;import java.awt.*;import java.awt.event.*;import java.applet.*;public class Computer_client extends Applet implements Runnable,ActionListener{ Button 计算;TextField 输入三边长度文本框,计算结果文本框; Socket socket=null; DataInputStream in=null; DataOutputStream out=null; Thread thread; public void init() {setLayout(new GridLayout(2,2)); Panel p1=new Panel(),p2=new Panel(); 计算=new Button(" 计算"); 输入三边长度文本框=new TextField(12);计算结果文本框=new TextField(12); p1.add(new Label("输入三角形三边的长度,用逗号或空格分隔:"));p1.add( 输入三边长度文本框); p2.add(new Label("计算结果:"));p2.add(计算结果文本框);p2.add(计算); 计算.addActionListener(this); add(p1);add(p2); } public void start() { try {socket = new Socket(this.getCodeBase().getHost(), 4331); in = new DataInputStream(socket.getInputStream()); out = new DataOutputStream(socket.getOutputStream()); } catch (IOException e){} if (thread == null) {thread = new Thread(this); thread.setPriority(Thread.MIN_PRIORITY); thread.start(); } } public void run() {String s=null; while(true) { try{s=in.readUTF(); } catch (IOException e) {计算结果文本框.setText("与服务器已断开");break;} 计算结果文本框.setText(s); } } public void actionPerformed(ActionEvent e) {if (e.getSource()==计算) { String s=输入三边长度文本框.getText(); if(s!=null) { try{out.writeUTF(s);} catch(IOException e1){} } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -