Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > BOOK: Beginning Java 2
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning Java 2
This is the forum to discuss the Wrox book Beginning Java 2, SDK 1.4 Edition by Ivor Horton; ISBN: 9780764543654
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Java 2 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 19th, 2003, 03:17 AM
Registered User
 
Join Date: Oct 2003
Location: Thai Pao Lo, , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Java GUI /Input

I want to put the information of my so called AddressBook into a GUI
frame using label but apparently the character seem to stick together
is there anyway to make it look like a list
this is the listing of my program
thank you very much for your help
much oblige

import java.util.*;
import java.io.*;
import javax.swing.*;
import java.awt.*;

public class AddressBook {
public static void main (String[] args)
{

StringTokenizer tokenizer;
String line;
String addBook="";
String name,address,phnum,notes;
String file="book.ad";
int phone_num,search_num, count = 0;

ArrayList addList = new ArrayList();
try
{
FileReader fr = new FileReader (file);
BufferedReader inFile = new BufferedReader (fr);

line = inFile.readLine();
while (line != null)
{
tokenizer = new StringTokenizer (line,"~");

name = tokenizer.nextToken();
address = tokenizer.nextToken();
phnum = tokenizer.nextToken();
notes = tokenizer.nextToken();
addList.add(new AddressEntry(name,address,phnum,notes))
;
line = inFile.readLine();

}

inFile.close();
}
catch (FileNotFoundException exception)
{
System.out.println ("The file " + file + " was not found.");
}
catch (IOException exception)
{
System.out.println (exception);
}




for(int i=0;i<addList.size();i++)
{
Object b= addList.get(i);
addBook+=(((AddressEntry)b).getName()+"\t"+((Addre ssEntry)
b).getAddress()+"\n");
}


JFrame frame = new JFrame ("List");
JLabel l1 = new JLabel (addBook);
frame.getContentPane().add (l1);

frame.pack();
frame.setVisible(true);
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
}

}


public class AddressEntry
{
private String name,address,phnum,notes;

public AddressEntry(String name,String address,String phnum,
String notes)
{
this.name=name;
this.address=address;
this.phnum=phnum;
this.notes=notes;
}


public String getName()
{
return name;
}
public String getAddress()
{
return address;
}
public String getPhnum()
{
return phnum;
}
public String getNotes()
{
return notes;
}
public String getAbook()
{
return name+"\t"+address+"\t"+phnum+"\t"+notes;
}

public String setName(String name)
{
this.name=name;
return name;
}
public String setAddress(String address)
{
this.address=address;
return address;
}
public String setPhnum(String phnum)
{
this.phnum=phnum;
return phnum;
}
public String setNotes(String notes)
{
this.notes=notes;
return notes;
}
}

this is the files of the
book.ad

Chris~Swanston Barry 111~5666-888~Java Rules
Nay~Namimbia 1111~5556667~GUI Forever
Jack~Williamston 333~555-88888~Linux Mandrake rule

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
is there a useful java gui design tool? yulin11 Java GUI 4 September 2nd, 2008 10:20 PM
HTML GUI for java abhinayak Java GUI 1 February 1st, 2008 03:38 AM
Java Gui (Reload Class) Axar Java GUI 0 June 10th, 2006 05:35 PM
>>Free Download Visual Java GUI Development Tool bigjava Java GUI 1 May 21st, 2004 08:15 AM
posting data from JAVA GUI eforce Java GUI 0 July 16th, 2003 12:00 PM



All times are GMT -4. The time now is 04:35 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.