Page 2 of 2 FirstFirst 12
Results 21 to 36 of 36
  1. #21
    Jkiller295 is offline Member
    Join Date
    May 2010
    Posts
    20
    Rep Power
    0

    Default

    like the code above, i successfully read the whole table of Clients and Addresses. Now i want to use the Street name only for the combobox, i tried to use line.split(); but this gave me another string of array. How can i separate the street name only, to put in the combobox

  2. #22
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Huh? You haven't created an Address class yet. And I don't see where you fill the List of addresses. You're like three steps further than you should be.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #23
    Jkiller295 is offline Member
    Join Date
    May 2010
    Posts
    20
    Rep Power
    0

    Default

    oh snap. i posted the wrong code and didnt recheck just now :P
    PHP Code:
    import java.io.*;
    import java.util.LinkedList;
    public class Address
    {
    	LinkedList addressList = new LinkedList();
    	
    	Address()
    	{
    		inputAdd();
    	}
    	public void inputAdd()
    	{
    		try
    		{
    			BufferedReader br = new BufferedReader(new FileReader("Addresses.csv"));
    			while(true)
    			{
    				String line = br.readLine();
    				if(line == null)break;
    				addressList.add(line);
    				System.out.println(line); // display the address
    			}
    			System.out.println();
    			br.close();
    		}
    		catch(IOException io)
    		{
    			System.out.println(io.getMessage());
    		}
    	
    	}
    	public Object getAddress(int index)
    	{
    		return addressList.get(index-1); // the list index starts with 0
    	}
    	public static void main(String []args)
    	{
    		Address a=new Address();
    		System.out.println(a.getAddress(49)); //testing to get a specific address
    		String s = (String)a.getAddress(0);
    		String []sa = s.split(",");
    		System.out.println(sa[3]+" - "+sa[2]);
    	}
    }
    the client class should be the same. at this line
    System.out.println(sa[3]+" - "+sa[2]);
    this is what i want to be displayed in the comboBox, and comboBox only takes 1 String [] as argument right ? So, there are 50 addresses ? what's the correct way ? :confused:

  4. #24
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Again, you should not add the line to the List, but 50 instances of a custom class Address. This class encapsulates the Client ID, road, post code etc, it does not do any file reading. You need to fill a CombBoxModel with those Address instances. And I'd use an ArrayList instead of a LinkedList.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  5. #25
    Jkiller295 is offline Member
    Join Date
    May 2010
    Posts
    20
    Rep Power
    0

    Default

    you should not add the line to the List, but 50 instances of a custom class Address.This class encapsulates the Client ID, road, post code etc, it does not do any file reading
    i dont understand this part, so where do i actually do the file reading ?? im really confused now :confused:

  6. #26
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    In some other class, or your main process class.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  7. #27
    Jkiller295 is offline Member
    Join Date
    May 2010
    Posts
    20
    Rep Power
    0

    Default

    just to clarify, are u saying that the client & address classes are just to store data that is read from the static main method ?? then passing them around to other classes ?

  8. #28
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Yes, they are only used to store the data. No, your main method should never contain more than a handful lines of code.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  9. #29
    Jkiller295 is offline Member
    Join Date
    May 2010
    Posts
    20
    Rep Power
    0

    Default

    oki doki, thanks a lot. let me try. 1st time learn object oriented :(

  10. #30
    Jkiller295 is offline Member
    Join Date
    May 2010
    Posts
    20
    Rep Power
    0

    Default

    Hi, I'm back :D
    The attachment is my current project. Everything seems to work fine. Now I just need a way to export the data to a text file.
    The format of output is
    L.K. Simons ABN 20-345-459 // my company name
    Collection Service Invoice //title
    Collection Date: 21-05-2010 //current date
    Client: Megadodo Publications // owner of the address chosen from comboBox

    Service Address:
    12,Bowman St, Seven Hills, 2147 // comboBox

    Collection Details:
    Recycling : blah blah blah // anything from the NewCollection class

    Net $xx,xx GST $xx,xx Total $xx,xx //also calculated in NewCollection class
    That's all :D
    Attached Files Attached Files

  11. #31
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    See reply #2, third link, IO tutorial. That covers all you need.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  12. #32
    Jkiller295 is offline Member
    Join Date
    May 2010
    Posts
    20
    Rep Power
    0

    Default

    no no.. i know how to write to a file using BufferedWriter, but not in the format mentioned above, specifically with all the data. Do i have to make another class and then get information from 1 of the class I currently have or something ?

  13. #33
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Well you have all the information needed somewhere. Gather all the bits and pieces and pass them to an output class or method and write them to file.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  14. #34
    Jkiller295 is offline Member
    Join Date
    May 2010
    Posts
    20
    Rep Power
    0

    Default

    wa. informations are scattered all over the place. im doomed

  15. #35
    chyrl is offline Senior Member
    Join Date
    Mar 2010
    Location
    Manila, Philippines
    Posts
    257
    Rep Power
    5

    Default

    This thread is a String manipulation problem.
    The solution are said to you.

    Try reading the BufferedWriter API. This would solve on how you could manipulate the file. If I am not mistaken, using the append method would append a string to the file.

    You should understand further how the data in the file are used and placed.

    You're making progress in the last posts.
    Every project, package, class, method, variable, syntax, algorithm, etc.
    are registered in my memory bank. Thanks to this thread.

  16. #36
    Jkiller295 is offline Member
    Join Date
    May 2010
    Posts
    20
    Rep Power
    0

    Default

    oki doki. i guess have to read all the I/O stuff again :D
    thanks anw

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 4
    Last Post: 04-22-2009, 11:02 PM
  2. Replies: 8
    Last Post: 12-01-2008, 02:07 PM
  3. Close Active Window (?)
    By dcnorman07 in forum New To Java
    Replies: 2
    Last Post: 10-03-2008, 05:55 PM
  4. Changing Active Window
    By jmHoekst in forum New To Java
    Replies: 1
    Last Post: 06-14-2008, 12:21 AM
  5. How to close an open JFrame window from a jsp page?
    By kasisaiganesh in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 05-27-2008, 06:29 PM

Posting Permissions

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