Thread: Java GUI /Input
View Single Post
  #1 (permalink)  
Old October 19th, 2003, 03:17 AM
linfakngiau linfakngiau is offline
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