无法在TextArea中获取我的控制台输出,我希望数据显示在多行上,但它不是

时间:2014-10-01 15:41:06

标签: java file jtextarea

我无法让我的控制台/终端输出类似于JTEXTAREA中的GUI输出。我希望数据出现在多行上,但它不是。有人可以看一下,并为我的代码问题提供意见和解决方案。谢谢!

import java.io.*;
import java.util.Arrays;
import java.io.FileReader;
import java.io.PrintWriter;
import java.util.Arrays;

import javax.swing.*;

public class RecurringGrowthCells
{
public static void main(String[] args)
{
    JFrame frame = new JFrame("Recurring Bacterial Growth Data");
    JTextArea textArea = new JTextArea();
    int[] Growth_numbers1 = new int[73];

    String text = "";

    try{
        BufferedReader reader1 = new BufferedReader(new FileReader("col1.csv"));

        for (int i = 0; i < 73; i++ )            //Growth
        {
            Growth_numbers1[i] = 0;
        }

        String Growth_nums = "";

        while(Growth_nums!=null)
        {
            Growth_nums = reader1.readLine();
            String[] pieces1 = Growth_nums.split(",");

            for (int j = 1; j <= 1; j++)
            {
                int IncrementNumber1 = Integer.parseInt(pieces1[j]);
                Growth_numbers1[IncrementNumber1]++;
            }

            text = text + Growth_nums + Growth_numbers1 + "\n";

            //For Loop is for console output.... Not GUI
            for (int i = 1; i < 73; i++)
            {
                show_text(i, Growth_numbers1);
            }
        }

    } catch(Exception ex){
        ex.printStackTrace();
        System.out.println("Why is this exception being thrown.");
    }

    textArea.setText(text);

    frame.add(new JScrollPane(textArea));
    frame.setSize(500, 800);
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

  public static int[] show_text(int i, int[] Growth_numbers1)
  {
      System.out.printf("%-10s\n", new Object[]{ i + ": " + Growth_numbers1[i] });
      return Growth_numbers1;
  }
}

以下是显示日期和测试编号的col1.csv示例。

6/17/14    18

6/18/14    18

6/19/14    18

6/20/14    18

6/21/14    18

6/22/14    1

6/23/14    2

6/24/14    9

6/25/14    2

我希望输出显示如下:

1: 4
2: 10
3: 4
4: 4
5: 6
6: 1
7: 2
8: 5
9: 4
10: 3
11: 3
12: 1
13: 2

但不是像我预期的那样出现在多行上,而是将它们组合成一行。

bad-output good-output

0 个答案:

没有答案