Results 1 to 6 of 6
  1. #1
    SBL
    SBL is offline Member
    Join Date
    Nov 2009
    Posts
    9
    Rep Power
    0

    Default Import data from file into a gui

    Hi there,

    pretty new to all this so sorry for any errors.
    Pretty much im creating an appilcation that is an address book. My question is what can i use to "import" data from a file and put it into different JtextFields.
    Can i just use a buffer reader?

    thanks

  2. #2
    zweibieren is offline Senior Member
    Join Date
    Aug 2009
    Location
    Pittsburgh, PA
    Posts
    284
    Rep Power
    6

    Default

    There is no magic.
    The principle is to define a file format and then write methods to read and write files.
    For a simple address book, one line per entry may suffice.
    Separating the fields with semicolons may also work.

    The application will have one class of objects for entries--call int Entry;
    and another class for the whole collection--call it AddressBook.
    Class Entry has method parseLine(String line) to parse a line and create an Entry.
    It has another method toLine() that generates a line of text for writing to a file.
    Class AddressBook has a method readFile(BufferedReader brdr).
    This method reads each line, calls Entry.parseLine, and appends the result to a collection.
    AddressBook has another method writeFile(BufferedWriter bwtr).
    This calls toLine() for each Entry in the collection
    and writes the result to bwtr.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by SBL View Post
    Hi there,

    pretty new to all this so sorry for any errors.
    Pretty much im creating an appilcation that is an address book. My question is what can i use to "import" data from a file and put it into different JtextFields.
    Can i just use a buffer reader?

    thanks
    Welcome to forum :)

    Step down your requirement. You've to read the file first and then place those data into a UI. Then you've to design the UI, using Swing/AWT. Now think about that user only can see the UI, not the file reading process. So the process hidden from the user basically. Keep in mind read about thread in Java.

    What you've tried so far? Can you show your attempt here, any line of ceo you are trying to write...

  4. #4
    SBL
    SBL is offline Member
    Join Date
    Nov 2009
    Posts
    9
    Rep Power
    0

    Default

    Thanks for the reply, pretty much i have my gui working i have one class file with my contacts in. i origionaly had the data in my main file like so:
    Contact n1 = new Contact("Simon Lockyer", "07920798945", "3 Ensbury Avenue, Bournemouth, Dorset, Bh10 4hf", "Simon@gmail.com");
    Contact n2 = new Contact("Darren Light","07847964578", "5 Ensbury Avenue, Bournemouth, Dorset, Bh15 1ed", "Light@Darren.com");
    Contact n3 = new Contact("Nick Aylward", "07549876481", "3 Ensbury Avenue, Bournemouth, Dorset, Bh10 4hf", "Nick@gmail.com");
    Contact n4 = new Contact("Nick Hell", "07549876481", "3 Ensbury Avenue, Bournemouth, Dorset, Bh10 4hf", "Nick@gmail.com");
    Contact n5 = new Contact("Nick New", "07549876481", "3 Ensbury Avenue, Bournemouth, Dorset, Bh10 4hf", "Nick@gmail.com");

    addContact(n1);
    addContact(n2);
    addContact(n3);
    addContact(n4);
    addContact(n5);
    }

    im still a little confused do i need to create another class file to have parse line and to line in it?

    thanks

  5. #5
    zweibieren is offline Senior Member
    Join Date
    Aug 2009
    Location
    Pittsburgh, PA
    Posts
    284
    Rep Power
    6

    Default

    class Contact looks like the right place for parseLine() and toLine().

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Import error for csv file in outlook
    By nida in forum New To Java
    Replies: 5
    Last Post: 09-07-2012, 01:22 AM
  2. how to import xfdf file into the pdf file
    By jkrishnanvenkat in forum New To Java
    Replies: 3
    Last Post: 11-09-2009, 02:46 AM
  3. How to import file from same directory?
    By Splat in forum New To Java
    Replies: 5
    Last Post: 10-14-2009, 04:11 AM
  4. how to import a ejb bean in java file
    By vijayinani in forum Enterprise JavaBeans (EJB)
    Replies: 2
    Last Post: 06-30-2009, 10:05 PM
  5. how to import war file with tomcat?
    By makpandian in forum NetBeans
    Replies: 0
    Last Post: 12-31-2008, 11:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •