Formatter with JOptionPane
Hi Guys, :o
I have made a GUI program with String components that involves the user entering different information and the JOptionPane shows the results. Now I have to make a file using the Formatter class to read what the user put in the JOptionPane. The code below just takes my whole GUI program and puts it into the output, how do I call just the JOptionPane??Thanks :D
Code:
import java.util.*;
import java.io.*;
public class ReadFromFileWithScanner{
public static void main(String[]args) {
File rcfile = new File("C:\\Users\\Kelly\\Documents\\Misc\\RentalCarReservation.java"); //Declaring & Initalizing
try {
Scanner scn= new Scanner(rcfile);
while(scn.hasNext()){
String line = scn.nextLine();
System.out.println(line);
}
}
catch(FileNotFoundException fnfe) {
System.out.println("Here is your Rental Information!!");
}
Formatter output= new Formatter();
try{
output = new Formatter("C:\\Users\\Kelly\\Documents\\Misc\\RentalCarReservation.java"); //writes a new file for you but you need to open it
output.close(); //have to close the program
}
catch(FileNotFoundException fnfe){
output.close();
System.out.println("File doesn't exist!!");
} // local to this catch
finally {
output.close();
}
}
}