Java JTextField在换行符处删除字符串,而不是追加

Java JTextField在换行符处删除字符串,而不是追加,java,swing,textarea,newline,readline,Java,Swing,Textarea,Newline,Readline,我正在尝试为客户端应用程序创建GUI。BufferedReader的.readLine用作输入流。问题是它打印换行符并在控制台中完美返回回车符,但一旦我尝试将其附加到文本区域,它似乎只是重写了前面的字符串。下面是示例代码 public class AirlinesClient extends JFrame implements ActionListener { public static BufferedReader socketIn = null; public static

我正在尝试为客户端应用程序创建GUI。BufferedReader的.readLine用作输入流。问题是它打印换行符并在控制台中完美返回回车符,但一旦我尝试将其附加到文本区域,它似乎只是重写了前面的字符串。下面是示例代码

 public class AirlinesClient extends JFrame implements ActionListener {
    public static BufferedReader socketIn = null;
    public static PrintWriter socketOut = null;
    public static Socket connection = null;
    public static String breakline;
    public static String command;
    public AirlinesClient() throws UnknownHostException, IOException{
        JPanel schPanel = new JPanel();
        JButton Schedules  = new JButton ("Flight Schedules");
        JButton Pilots  = new JButton ("Pilots' shifts");
//mainFrame
          super.setSize(300, 400);
          setLocationByPlatform(true);
          setDefaultCloseOperation(EXIT_ON_CLOSE);
          setVisible(true);
//adding ScheduleButton's panel to the root frame
          schPanel.setLayout(null);
          getContentPane().add(schPanel);
//Adding Schedule button
          Schedules.setBounds(75, 10, 150, 50);
          Schedules.setVisible(true);
          schPanel.add(Schedules);
//Adding action on click
          Schedules.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {      
                  JTextArea area = new JTextArea(20,20);
                  JFrame scheduleFrame = new JFrame("Information");
                  scheduleFrame.setSize(800,400);
                  scheduleFrame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
                  scheduleFrame.setLocationRelativeTo(null);
                  scheduleFrame.add(area);                               
                  scheduleFrame.setVisible(true);   
                  socketOut.flush();
                  socketOut.println("1");
                  area.append(breakline);

            }
        });

//Adding pilots' shifts       
          Pilots.setBounds(75, 70, 150, 50);
          Pilots.setVisible(true);
          schPanel.add(Pilots);

    }

    public static void main(String[] args) throws UnknownHostException, IOException {

        new AirlinesClient();

        int port = 1234;
        String host = "localhost";
        connection = new Socket(host,port);
        socketIn = new BufferedReader(new      InputStreamReader(connection.getInputStream()));
        socketOut = new PrintWriter(connection.getOutputStream(),true);

        try{    
        System.out.println("Successfully connected to the server!");
do{         
//This prints the output in the console and it ends when the server sends $$$
            while (!(breakline =socketIn.readLine()).equals("$$$")){
                System.out.println(breakline);
            }
//Command is input from the user keyboard but for testing purposes I'm only using
//a single socketOut command(from the actionlistener) to send commands      
        }while(command!="0");
        System.out.println("Closing connection to server!");
    }catch(IOException e){
        e.printStackTrace();
    } finally{
           try{
               if(socketIn!=null) socketIn.close();
               if(socketOut!=null) socketOut.close();
               if(connection!=null) connection.close();
             }
             catch(IOException e){
               System.err.println("Socket could not be closed!");
             }
           }

    }
    @Override
    public void actionPerformed(ActionEvent arg0) {

    }
}

1 Java GUI必须在不同的操作系统、屏幕大小、屏幕分辨率等上工作,在不同的地区使用不同的PLAF。因此,它们不利于像素完美布局。而是使用布局管理器,或与布局填充和边框一起使用。2使用缩进代码行和代码块的逻辑和一致形式。缩进的目的是使代码流更易于遵循。。。。3为了更快地获得更好的帮助,发布一个最小的完整的可验证示例或简短的、自包含的、正确的示例。