Java! How to read from a file to GUI?
-
I need to create a program that will read from a file and output the information into a JFrame. I know how to create a program to read a file, but I just need some help reading the file to GUI. Any help would be appreciated! package ism3230_ch6assignment; import java.io.*; import java.util.*; public class ISM3230_Ch6Assignment { /** * @param args the command line arguments */ public static void main(String[] args) throws FileNotFoundException { /** * declaration of variables */ int counter; double TestAvg = 0; double classAvg = 0; String name; char grade; /** * input and output file names */ Scanner inFile = new Scanner(new FileReader("612TestScores.txt")); PrintWriter outFile = new PrintWriter("612TestScoresout.txt"); /** * will print column headers in output file */ outFile.println("Student Test1 Test2 Test3 Test4 Test5 Average Grade"); /** * while loop reads the data from the input file */ while (inFile.hasNext()) { /** * reads the student's name from the input file and outputs it in the outFile */ name = inFile.next(); outFile.printf("%-10s", name); TestAvg = calculateAverage(inFile, outFile); outFile.printf("%6.2f ", TestAvg); classAvg = classAvg + TestAvg; grade = calculateGrade(TestAvg); outFile.printf("%3s%n", grade); } classAvg = classAvg / 10; outFile.println(); outFile.println("Class Average = " + classAvg); outFile.close(); } /** * Void method calculateAverage determines each student's average from the 5 * test scores and displays the average in the output file. */ public static double calculateAverage(Scanner inF, PrintWriter outF) { int score; int sum = 0; int count;; for (count = 1; count <= 5; count++) { score = inF.nextInt(); outF.printf("%4d ", score); sum = sum + score; } return sum / 5.0; } /** * Value-returning method calculateGrade determines student's grade from input * data and returns each student's grade in the output file. */ public static char calculateGrade(double avg) { if (avg >= 90) return 'A'; else if (avg >= 80) return 'B'; else if (avg >= 70) return 'C'; else if (avg >= 60) return 'D'; else return 'F'; } }
-
Answer:
I didn't read your code very carefully or look for mistakes, but it seems like you already have code for reading the data you need from the file. The missing element, then, is the GUI. A simple solution would be to place all of the text in a String and then set the text of a text area. If you have never written a GUI before, you might find this resource helpful: http://docs.oracle.com/javase/tutorial/uiswing/index.html
ladyiver... at Yahoo! Answers Visit the source
Related Q & A:
- How to know if a file has 'access' monitor in linux?Best solution by Unix and Linux
- How do I send a file in Yahoo mail?Best solution by Yahoo! Answers
- How can I send a file to a friend on Hotmail?Best solution by askdavetaylor.com
- How do you attach a file on Hotmail?Best solution by Yahoo! Answers
- How do I unrar a file?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.