Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 19th, 2003, 03:17 AM
Registered User
 
Join Date: Oct 2003
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






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
posting data from JAVA GUI eforce Java GUI 0 July 16th, 2003 12:00 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.