为什么System.out.println(Aa.readLine() 输出的是false ?

package l;//客户端

import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import java.security.Key;

public class Q extends Frame{
PrintStream L;
Q F;
// BufferedWriter L;
Frame s=new Frame("客户端");
TextArea s1=new TextArea ();
TextField s2=new TextField();
public Q(){
s.setSize(500,500);
s.setVisible(true);
s.add(s1,BorderLayout.CENTER);
s.add(s2,BorderLayout.SOUTH);
s.pack();

s.addWindowListener(new WindowAdapter(){

@Override
public void windowClosing(WindowEvent e) {
// TODO Auto-generated method stub
super.windowClosing(e);
System.exit(0);
}

});
s2.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e) {

L.print(s2.getText());
s1.append(s2.getText()+"\n");
s2.setText("");

}

});
}
public void aa(){
try {
s1.append("等待与服务器连接"+"\n");
Socket s=new Socket("192.168.1.105",9080);
OutputStream S=s.getOutputStream();
// OutputStreamWriter SS=new OutputStreamWriter(S);
L=new PrintStream(S);
// L=new BufferedWriter(SS);
s1.append("服务器连接成功"+"\n");

} catch (UnknownHostException e) {
// TODO Auto-generated catch block

s1.append("服务器连接失败"+"\n");
} catch (IOException e) {
// TODO Auto-generated catch block

s1.append("服务器连接失败"+"\n");
}
}
public static void main(String args[]){
Q F=new Q();
F.aa();
// F.pack();

}
}

动漫人物
浏览 201回答 1
1回答

吃鸡游戏

import java.io.*;import java.net.*;import java.util.*;import java.awt.*;import javax.swing.*;public class Server extends JFrame{private JTextArea jta=new JTextArea();public static void main(String[] args){ new Server(); }public Server(){setLayout(new BorderLayout());add(new JScrollPane(jta),BorderLayout.CENTER);setTitle("Server");setSize(500,300);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setVisible(true);try{ServerSocket serverSocket=new ServerSocket(8000);jta.append("Server started at "+new Date()+'\n');Socket socket=serverSocket.accept();DataInputStream inputFromClient=new DataInputStream(socket.getInputStream());DataOutputStream outputToClient=new DataOutputStream(socket.getOutputStream());while(true){double radius=inputFromClient.readDouble();double area=radius*radius*Math.PI;outputToClient.writeDouble(area);jta.append("Radius received from client: "+radius+'\n');jta.append("Area found: "+area+'\n');}}catch(IOException ex){ System.err.println(ex); }}}客户端代码如下:import java.io.*;import java.net.*;import java.awt.*;import java.awt.event.*;import javax.swing.*;public class Client extends JFrame{private JTextField jtf=new JTextField();private JTextArea jta=new JTextArea();private DataOutputStream toServer;private DataInputStream fromServer;public static void main(String args[]){new Client();}public Client(){JPanel p=new JPanel();p.setLayout(new BorderLayout());p.add(new JLabel("Enter radius:"),BorderLayout.WEST);p.add(jtf,BorderLayout.CENTER);jtf.setHorizontalAlignment(JTextField.RIGHT);setLayout(new BorderLayout());add(p,BorderLayout.NORTH);add(new JScrollPane(jta),BorderLayout.CENTER);jtf.addActionListener(new ButtonListener());setTitle("Client");setSize(500,300);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setVisible(true);try{Socket socket=new Socket("dzy_3347ff08bc0.whpu.edu.cn",8000);fromServer=new DataInputStream(socket.getInputStream());toServer=new DataOutputStream(socket.getOutputStream());}catch(IOException ex){ System.out.println(ex); }}private class ButtonListener implements ActionListener{public void actionPerformed(ActionEvent e){try{double radius=Double.parseDouble(jtf.getText().trim());toServer.writeDouble(radius);toServer.flush();double area=fromServer.readDouble();jta.append("Radius is "+radius+"\n");jta.append("Area received from the server is "+area+'\n');}catch(IOException ex){ System.out.println(ex); }}}}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java
Python