Challenge involving creating a file on GUI & seeing one record at a time...

Hi,
If anyone can help me with this project I'd be most appreciative. I'll try and explain the problem the best I can. I'm adding students to a database at a university they're either a Graduate or an Undergraduate. I'm taking in first, lastname's, ssn, & ACT/SAT/GMAT test results. I have a GUI called StudentRecord that has all the JTextFields, JButton's, etc. I'm also writing it to a .txt file called StudentDA. For this I used a BufferedFile reader.
What I really need is on my StudentRecord when I click the display button I want it to show one record at a time in another JFrame. This other JFrame I named it display. I'm trying to create an instance of JFrame inside of the actionPerformed for StudentRecord but when I click display nothing happens.
I adding the students with a vector that I'm calling v. I want the Display to read from the .txt file and display one at a time hence next, and previous. I'm going to post the tidbit of relevant code. If anyone can help me you'd be my hero for the day for all time I've tried to get this to work.
Here's the StudentRecord (GUI) display part:
      public void actionPerformed( ActionEvent event )
     try {
          Display d = new Display(StudentDA.v);
         }//end try
        //catch right here no problems with this..Here's the DataAccess part:
public class StudentDA{
  static Vector v = new Vector();;
  static String pathName = "a:/Final Project/test1.txt";
  static File studentFile = new File(pathName);
  static String status;
  public StudentDA() {}
  public static void initialize() {
    if (studentFile.exists() && studentFile.length() !=0) {
     try{
      BufferedReader in = new BufferedReader(new
      FileReader(studentFile) );
      do{
         status = in.readLine();
          if(status.equals ("uGrad")) {
            uGrad u = new uGrad();
            u.setFName(in.readLine() );
            u.setLName(in.readLine() );
            u.setssNum(Integer.parseInt(in.readLine()) );
            u.setACT(Integer.parseInt(in.readLine() ));
            v.add(u);
            System.out.println(u + "inside ugrad");
          }//end if uGrad
          else{
            if(status.equals("Grad")) {
            //same process as uGrad
            v.add(g);
          }//end else Grad
      }while (status != null);
    }//end try statement
    catch (Exception e) {
      }//end catch
    }//end if there's something there
  }//end method initialize
  //creating the terminate method
  public static void terminate() {
    try{
      PrintStream out = new PrintStream ( new
      FileOutputStream (studentFile) );
      for (int i = 0; i < v.size(); i++) {
        Student s = (Student) v.elementAt(i);
        String p = s.printRecord();
        StringTokenizer rt = new StringTokenizer(p, "\t");
        while (rt.hasMoreTokens() ) {
          out.println(rt.nextToken() );
          }//end while
      }//end for loop
    }//end try loop
    catch (Exception e){
    }//end catch
  }//end terminate
public static void add(Student s){// throws DuplicateException{
          boolean duplicate = false;
          for(int i = 0; i < v.size(); i++){
               if(s.getssNum() == ((Student)(v.elementAt(i))).getssNum()){
                    duplicate = true;
                    break;
               if(duplicate){
                    throw new DuplicateException("Student Already Exists");
               else{
                    v.add(s);
}//end add method
}//end classHere's the display class:
public class Display extends JFrame {
     private JButton Next, Previous;
     private JTextField statusField, firstField, lastField, socialField, advPlacementField, actField;
     private JLabel statusLabel, firstLabel, lastLabel, socialLabel, advPlacementLabel, actLabel;
     private JPanel fieldPanel, buttonsPanel;
     private JTextArea displayArea;
     static int count = 0;
     static String status;
     public Display(){}
public Display(Vector v){
     //setting up the GUI components for the display class here
     //JTextAreas & JLabels
     buttonsPanel = new JPanel();
     buttonsPanel.setLayout(new GridLayout(1,2));
    Next = new JButton("Next");
    buttonsPanel.add(Next);
    Next.addActionListener(
    new ActionListener() {
      public void actionPerformed( ActionEvent event )
          //try to catch display errors
       try {
                    count++;
                 displayData(count);
                 //displayData();
      }//end try
          catch {
         }//end catch
      } // end actionPerformed
    } // end anonymous inner class
    ); // end call to addActionListener
    buttonsPanel.add(Next);
    Previous = new JButton("Previous");
    buttonsPanel.add(Previous);
    Previous.addActionListener(
    new ActionListener() {
      public void actionPerformed( ActionEvent event )
          //try to catch display errors
          try {
               count--;
               displayData(count);
               //displayData();
         }//end try
          catch {
         }//end catch
      } // end actionPerformed
    } // end anonymous inner class
    ); // end call to addActionListener
}//end display() constructor
public void displayData(int count) {
     StudentDA.initialize();
       if (status.equals ("uGrad")) {
       //these are all part of the StudentRecord GUI not Display GUI
            fieldPanel.setVisible(true);
            buttonsPanel.setVisible(true);
            actLabel.setVisible(true);
            actField.setVisible(true);
            advPlacementLabel.setVisible(false);
            advPlacementLabel.setVisible(false);
       }//end if
       else {
            if(status.equals ("Grad")) {
             fieldPanel.setVisible(true);
             buttonsPanel.setVisible(true);
             actLabel.setVisible(false);
             actField.setVisible(false);
             advPlacementLabel.setVisible(true);
             advPlacementLabel.setVisible(true);
              }//end if
       }//end else
}//end method displayData()
public static void main ( String args[] )
    Display application = new Display();
    application.addWindowListener(
          new WindowAdapter(){
               public void windowClosing( WindowEvent e)
                    System.exit(0);
    application.setSize( 300, 200);
    application.setVisible( true );
};//end main
}//end class Display{}I know this is long but if anyone can help I'd greatly appreciate it. Please ask me if you need me to clarify something, I tried to not make it way too long. --rockbottom01
     

I'm not really too sure what it is that you are after, but here is some code, that loads up an array with each line of a .txt file, then displays them. I hope you can make use of a least some of it.
just ask if you don't understand any of the code.
String array[];
int i;
public Test() {
          readFile("file.txt");
          i = 0;
          nextEntry();
     public void nextEntry() {
          Display display = new Display();
          display.show();
     class Display extends JFrame implements ActionListener {
          JLabel label1;
          JButton button;
          public Display() {
               label1 = new JLabel(array);
               button = new JButton("OK");
               getContentPane().setLayout(new FlowLayout());
               getContentPane().add(label1);
               getContentPane().add(button);
               button.addActionListener(this);
          public void actionPerformed(ActionEvent e) {
               setVisible(false);
               i++;
               if(i < array.length) {
                    nextEntry();
     public void readFile(String fileName) {
          String s, s2 = "";
          int lineCount = 0;
          BufferedReader in;
          try {
               in = new BufferedReader(new FileReader(fileName));
               while((s = in.readLine()) != null) {
                    lineCount++;
               array = new String[lineCount];
               in.close();
               in = new BufferedReader(new FileReader(fileName));
               int j = 0;
               while((s = in.readLine()) != null) {
                    array[j] = s;
                    j++;
          catch(IOException e) {
               System.out.println("Error");

Similar Messages

  • Does iTunes match need to locate the actual files or just see its record in your library database? I am currently traveling in US and I have US and Australian iTunes accounts. But all my music files are on a hard drive in Australia.

    Does iTunes match need to locate the actual files or just see its record in your library database? I am currently traveling in US and I have US and Australian iTunes accounts. But all my music files are on a hard drive in Australia. Can I start using itunes music match while I am travelling without the actual music files attached to my itunes?

    In your situation I strongly recommend you read over that KB article. The international iTunes Stores are not cross-compatible.
    My understanding of how it would work is that when activating iTunes Match on your US Store account, any songs you have in your iTunes Library that were purchased from the AUS Store account will NOT be matched. As I understand it, those files will be uploaded (which means you need the files on a local HDD). I also do not think it is possible to have iTunes Match active on more than one store ID on the same computer. But since iTunes Match is not available internationally yet, that point is moot for the moment.
    To be honest you might want to wait until the service is available internationally so you can guage how will it will serve you.

  • XML import only creates one record at a time

    Hi All,
    I have an XML import map that automatically imports data into main product table. It's working fine when the XML file has only one main record. When it has more than one record, the import manager and import server can only import the last record in the file and skip the rest.
    I already checked the record matching tab. It correctly shows that all records will be created and 0 will be skipped. Even the log file indicates all records are created after I execute the map. Yet, when I try to look for them in the data manager, I can only find the last one. If I execute the map with the exact same file again, it will create one more record again and skip the rest.
    Someone else posted the same question a while back: Import map issue one record at a time. But it was never answered. Does anyone else have this issue? Is this a MDM bug?
    Thanks,
    Kenny

    Hi Kenny,
    Please refer to the note below:
    Note 1575981
    Regards,
    Neethu Joy

  • I can only see one photo at a time

    I use to be able to see a thumbnail of all my photos. Now for some reason I can only see one photo at at a time. I have to use the scroll bar to go up and down. It is so frustrating. Please help.

    Welcome to the Apple Discussions.
    In the lower right corner of the iPhoto window is a slider. Move it to the left. Does that work?
    Regards.

  • Can't create new files nor open existing ones.

    It's been a while since I last used photoshop, a similar kind of problem made me move away from the product, but the new features in CS6 are enticing enough for me to be interested in trying it again.
    My problem is that, while the interface is completely usable (I can open the color picker, play with tools and preselects) trying to open a file or creating a new one does absolutely nothing.
    File->New or CTRL+N will show the busy cursor for but a brief second, and then disappear, dragging a file to the interface shows me the "denied" cursor (black circle with a bar), File->Open lets me browse my disk but then when I select the image, nothing happens.
    I've been scouring the forums for a solution to this and tried so many things that it's impossible for me to even try and list them all, so I'll accept any suggestion and try anything, I'll sum up what I did try in the first post (if it stays editable).
    Please let me succeed in this, I'd love to go back to photoshop.

    How can I test the other display theory? I didn't connect any new monitor (I do use 2) but I occasionally use stuff like remote desktop tools.
    I'll try and update the display drivers (even tho I updated them recently).
    P.S.: opening it on the other monitor worked. What the heck. Any way I can make it work on both monitors?
    I'll be making more tests in the meanwhile.

  • Filer warning of creating multiple files even though only one is created

    I'm using the Apt tool with a custom program that I wrote to autogenerate some Java classes for my project. Unfortunately, the Filer is throwing a warning. Even thought the below code is only called once, I get a multiple create warning. Any ideas what's causing this?
    Mark McKay
    Filer filer = env.getFiler();
    PrintWriter pw = filer.createSourceFile(indexClassName);
    warning: Attempt to create 'C:\dev\cvs.kitfox.com\scarlet\gen\com\kitfox\scarlet\\Index.java' multiple times

    I disocvered that this error was coming from the fact that my processor was being called twice - once for my original soruce files, and then again to process the file I had just generated. Once I handled the case of the reentrant call to process(), I was able to avlid this warning.

  • Creating Interactive Files with more than one URL

    Hello, here's my problem: I want to create more than one button instance that go to different URL address's. From the Adobe Video Workshop, I got the code:
    interactive_test.addEventListener(MouseEvent.CLICK, buttonClickHandler);
    function buttonClickHandler(event:MouseEvent):void {
                    navigateToURL(new URLRequest("http://www.adobe.com"));
    This works fine with one button instance. When I copy and paste the code for another button instance, i.e:
    butn1.addEventListener(MouseEvent.CLICK, buttonClickHandler);
    function buttonClickHandler(event:MouseEvent):void {
                    navigateToURL(new URLRequest("http://www.adobe.com"));
    butn2.addEventListener(MouseEvent.CLICK, buttonClickHandler);
    function buttonClickHandler(event:MouseEvent):void {
                    navigateToURL(new URLRequest("http://www.adobe.com"));
    I get 1021 duplicate function error. I think I understand in priciple what's wrong but don't know how to fix it. MyI knowledge of Action Script 3 is zero. What I need is sample code that works that I could copy and paste, with appropriate changes.
    Thanks in advance for your help, Richard

    use different function names or flash won't know which function to use:
    butn1.addEventListener(MouseEvent.CLICK, buttonClickHandler1);
    function buttonClickHandler1(event:MouseEvent):void {
                    navigateToURL(new URLRequest("http://www.adobe.com"));
    butn2.addEventListener(MouseEvent.CLICK, buttonClickHandler2);
    function buttonClickHandler2(event:MouseEvent):void {
                    navigateToURL(new URLRequest("http://www.adobe.com"));

  • Listing files in a jar, one screen at a time

    I need to list all the files in a .jar file from the DOS command line (using jar tf etc.). There are so many files that half of the list scrolls above the top of the window before the end of the list is displayed, so I can't see half the list. How do I tell it to pause the list when the screen is full, then continue scrolling only when I hit come key? I tried using \p (which is used in DOS) but that doesn't work.

    Redirect the output to a file, and then use Notepad to display the contents of that file.
    jar ... >somefile.txt

  • Creating a slide show...one image repeats multiple time throughout?

    to create a slide show I am dragging a soundtrack onto the new sequence icon...importing 117 jpeg images selecting them and choosing 'automate to sequence'...
    however, one of the jpeg images is being repeated throughout the sequence, over and over again...
    What am I doing wrong...i've even deleted the image from the source import file...and it just haunts me...
    Any assistance would be greatly appreciated.

    What version of PrPro do you have?
    There was a glitch with PSD's, in CS 5, and then CS 5.5, but that was supposedly corrected in the latest CS 5.5 update.
    Until then, the workflow, that Stephen_Spider suggested should work fine. You can create an Action to Open, then Save, and Automate>To Batch, for that, to correct an entire folder at a time.
    Good luck,
    Hunt

  • How can I delete my entire History file, without doing it one site at a time?

    I am able to delete a given site in my History file by right-clicking on it and indicating to delete it. How do I erase the entire file when it is no longer of any use to me?

    You can delete the places.sqlite file to remove all history.
    Firefox will use the most recent JSON backup in the bookmarkbackups folder to rebuild the bookmarks.
    *http://kb.mozillazine.org/Bookmarks_history_and_toolbar_buttons_not_working_-_Firefox

  • IDOC to File multiple segments to one record

    Hello,
    I have an xi scenerio where I am going from IDOC to flat file.   I have an issue where a segment can occur multiple times and I want to take the last segment of that multiple occuring segment as my record to flatfile.
    for example
           EDI_DC
              EMPLOYEE
                   EMPLOYEE_PERSONAL_INFO
                   EMPLOYEE_ADDRESS_INFO
                   EMPLOYEE_ADDRESS_INFO
                   EMPLOYEE_ADDRESS_INFO
                   EMPLOYEE_BENEFIT_INFO
    in the above example, i want to take the last occurance of the EMPLOYEE_ADDRESS_INFO in my message mapping without any logic around dates or statuses.
    is there an easy way to do this?
    thank you

    use this logic;
    source -> COUNT-
                              |--- EqualsS -> pass the source to target
    source -> INDEX -
    the logic is count function will give you the number of occurrences and Index will return the current occurrence.

  • Problem in creating csv file

    I have one problem in creating csv file.
    If one column has single line value, it is coming in single cell. But if the column has no.of lines using carriage return while entering into the table,
    I am not able to create csv file properly. That one column value takes more than one cell in csv.
    For example the column "Issue" has following value:
    "Dear
    I hereby updated the Human Resources: New User Registration Form Request.
    And sending the request for your action.
    Regards
    Karthik".
    If i try to create the csv file that particular record is coming as follows:
    0608001,AEGIS USERID,SINGAPORE,Dear
    I hereby updated the Human Resources: New User Registration Form Request.
    And sending the request for your action.
    Regards
    Karthik,closed.
    If we try to load the data in table it is giving error since that one record is coming in more than one line. How can I store that value in a single line in csv file.
    Pls help.

    I have tried using chr(10) and chr(13) like this......still it is not solved.
    select REQNO ,
    '"'||replace(SUBJECT,chr(13),' ')||'"' subject,
    AREA ,
    REQUESTOR ,
    DEPT ,
    COUNTRY ,
    ASSIGN_TO ,
    to_Date(START_DT) ,
    START_TIME ,
    PRIORITY ,
    '"'||replace(issues, chr(13), ' ')||'"' issues,
    '"'||replace(SOLUTIONS,chr(13),' ')||'"' SOLUTIONS ,
    '"'||replace(REMARKS,chr(13),' ')||'"' REMARKS ,
    to_date(CLOSED_DT) ,
    CLOSED_TIME ,
    MAN_DAYS ,
    MAN_HRS ,
    CLOSED_BY ,
    STATUS from asg_log_mstr
    Pls help.

  • How to create a file when i run the report

    hi all
    i want to run the report and each time i run the same report to create a separate word file for the report o/p ?
    is there exist a procedure to create a fiel?

    hi magoo thanks for your consederation
    i use forms 10g
    But your answer is to create the file , but when i run the report next time the file overided by the new file ,
    But i want to generate a new file beside the old created file (how can i create separate file althouth the file name take the same name of the report)
    thanks.

  • How do restore the podcasts, audiobooks, etc., in the itunes 12 sidebar? I can only see one at a time. grrr.

    I've updated to iTunes 12.0.1.26, and the sidebar library list has disappeared. It looks like all I can see is one item at a time in the list. Either Music OR Podcasts OR Audiobooks, but not all of them as a list. This is so frustrating. I don't want to see one thing at a time, I want to see everything I have.
    Is there any way to restore it to the previous view?

    Thanks for taking a stab at it: that didn't prove to be the problem. That option in the settings for tabbed browsing was not checked.
    I may be a bit behind the times: I am used to tabbed browsing showing all the tabs it possibly can, instead of just the last one. Sometimes it won't even show the last tab: I can have 15 tabs open, and not see a single tab. I've been confused by this into closing a window with lots of tabs open, because it looks like a single page-window.
    My main problem with the tab-bar flashing to the end of the row is that it means a great deal more mouse-clicking around to browse.
    I haven't tried installing the latest beta. Maybe that would fix the problem.
    Toddo

  • Numbers tell me I need an uptodate version to open a file created but I have the latest version so I am unable to open the files. I see others are having the same problem. Is there a solution?

    Numbers tell me I need an upto date version to open files though I have the latest version installed and used to create the files in the first place is there a solution.

    Please see this user tip:
    Need newer version of Numbers to open file

Maybe you are looking for