I am having trouble getting my GUI TEXTAREA field to resemble my console output. The GUI contains a short explanation of what I am looking for. I have tried converting the integer array to a string array but the output is not the same as the command line. Can someone explain what I am doing wrong.
import java.io.FileReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTextArea; public class RecurringGrowthCell { public static void main(String[] args) { String textArea1 = "Hello can someone help me, I want to replace the text in this field with \nthe data that you see in the command line.\n" + "I am monitoring bacterial growth in our science lab at work, and keeping track of each recurring growth number by paper is quite difficult\n" + " since papers tend to get easily misplaced in the lab.\n" + "I would like to have the same output from the command line placed in a GUI textArea, " + "preferably this textArea." + " Can someone tell me what should I do first or point out what I am doing wrong." + "\n\n\n\n\n\n\n Thanks"; //Set JTextArea text to created String JTextArea textArea = new JTextArea(textArea1); //Set JTextArea to line wrap textArea.setLineWrap(true); //Set JTextArea text to word wrap textArea.setWrapStyleWord(true); //Create scrollbar for text area JScrollPane scrollBarForTextArea=new JScrollPane(textArea,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); JFrame frame=new JFrame("Recurring Growth Data"); frame.add(scrollBarForTextArea); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(500,500); frame.setLocationRelativeTo(null); frame.setVisible(true); Growth_Numbers(); } private static void Growth_Numbers() { try { //Open file to read BufferedReader reader1 = new BufferedReader(new FileReader("col1.csv")); //======================================================================================== int[] Growth_numbers1 = new int[73]; //======================================================================================== //Initialize all counts to zero. for (int i = 0; i < 73; i++ ) //Growth column {Growth_numbers1[i] = 0;} //======================================================================================== String Growth_nums; //======================================================================================== //======================================================================================== while ((Growth_nums = reader1.readLine()) != null) { String[] pieces1 = Growth_nums.split(","); for (int j = 1; j <= 1; j++) { int IncrementNumber1 = Integer.parseInt(pieces1[j]); Growth_numbers1[IncrementNumber1]++; } } reader1.close(); //========================================================================================= //========================================================================================= // Loop through array of counts to print them and their frequency. for (int i = 1; i < 73; i++) { show_text(i, Growth_numbers1); } //Nums = Arrays.toString(Growthnumbers1); //System.out.println(Nums); } catch (Exception e) { System.out.println("There was a problem opening and processing the file."); } } //show_text =================================================================================== public static int[] show_text(int i, int[] Growth_numbers1) { System.out.printf("%-10s\n", new Object[]{ i + ": " + Growth_numbers1[i] }); return Growth_numbers1; } }
I have made multiple attempts to get my GUI TEXTAREA output to resemble my console output. I don't know what I am doing wrong. I was successful in one attempt at getting the following output to my TEXTAREA.
[ 0, 0, 6, 10, 4, 4, 7
2, 4, 6, 5, 3, 1, 4, 4
3, 0, 2, 5, 2, 0, 0, 0,
2, etc, etc, etc, ]
The above output is what I got in my GUI. This is the "output" that I do not want.
The output below is what I would like to see in my GUI TEXTAREA.
1: 6
2: 10
3: 4
4: 4
5: 7
6: 2
7: 4
8: 6
9: 4
10: 5
11: 3
12: 1
13: 4
14: 4
15: 3
16: 0
17: 2
18: 5
19: 2
20: 0
21: 0
22: 0
23: 2
24: 3
25: 1
26: 0
27: 0
28: 3
29: 0
30: 0
31: 0
32: 0
33: 0
34: 1
35: 0
36: 1
37: 0
38: 0
39: 0
40: 0
41: 0
42: 0
43: 0
44: 0
45: 0
46: 0
47: 0
48: 0
49: 0
50: 0
51: 0
52: 0
53: 0
54: 0
55: 0
56: 0
57: 0
58: 0
59: 0
60: 0
61: 0
62: 0
63: 0
64: 0
65: 0
66: 0
67: 0
68: 0
69: 0
70: 0
71: 0
72: 0
=======================================
Can someone tell, show, explain, comment, offer an opinion, advice, etc, on what my first step should be?
I have uploaded the col.txt file that the code reads. Feel free to run the code to get a general idea of what I should do.
I have uploaded the code and output for those who would like to run the code to see what the problem is. You do not have to run it, you do not have to solve it if you don't
want to. I would appreciate advice on what I'm doing wrong or where I should start.
Thanks