Swing address book problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jp0424
    New Member
    • Oct 2011
    • 6

    Swing address book problem

    Hiya everyone. I'm doing a project to code a swing program records basic information on people, with the ability to edit, delete, and view the data, and output the data to a file. I chose a text file for this. To see the format that I used in logging the information, please look at problem1.jpg. I have done all except the edit and delete windows. For both windows, the program will read the data from the file and populate the fields such as

    First Name: first_name
    Last Name: last_name

    and so on. Now the first problem comes from the fact that multiple records are stored in the text file, and the program must go to the next record (forwards/backwards) to edit/delete the data. Is there a way to go to the next record from the record format that I made up? Okay, so look at problem1.jpg again. What I want to do is to move from the first dataset (First Name: Justin...Phone: 7373732) to the next one (Julius...83838 ) and so on for other entries.

    Next is the editing/deleting part. I know how to change the data, problem is, I want to update the current data, and from what I know, if I place the append to the PrintWriter function it will add a new entry to the file. If I remove the append argument, PrintWriter will clear the other records and just write the changes that I specified on the textFields. What I want is to change the data that I want to change and leave the others alone. Now for the delete part, I believe (I haven't start this part) that I would just set the values to " ", just plain spaces, so like

    Code:
    output.println("First Name: "+fname);
    would be
    Code:
    output.println("");
    Correct me if I'm wrong on that one. I believe if I do this successfully it will leave a big gap between the entries that are not deleted. Is there a way to rearrange the data when an entry is deleted?

    Okay so what have I done. For populating the fields I did a dirty way of using the scanner, then using skip to "skip" the strings that I don't need then retrieve the unskipped strings to show on the textFields.

    e.g.

    Code:
    Scanner s = new Scanner (new FileInputStream("data.txt"));
          s.skip("First Name: ");
          String fname = s.nextLine();
          //edFname is the name of the textField
          edFname.setText(fname);
    and this goes on for every field. Aside from that I have nothing. I'm on a brick wall here, and I've tried all possible ways to address the problem. If you have any problems understanding what I typed, please refer to the attachments below, and if you have additional questions please do ask me. Thank you.
    Attached Files
Working...