• Post Reply Bookmark Topic Watch Topic
  • New Topic

telephone book

 
mehmet melik
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i have a this code. i new java. i want to make a telephone book. please help me
thanks!!




import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.ibm.jvm.io.FileOutputStream;

public class PhoneBook extends JFrame implements ActionListener{
DataOutputStream output;
JLabel lbl1;
JLabel lbl2;
JTextField txt1;
JTextField txt2;

JButton bt1;
JButton bt2;
Container c;
public static void main(String[] args){

JFrame jf = new PhoneBook ();
jf.setVisible(true);

}
public PhoneBook (){
super("Open File");
c=getContentPane() ;
try{

output = new DataOutputStream(new FileOutputStream("book.txt"));

} catch(IOException e)

{ System.err.println("File not open\n"+e.toString());

System.exit(1);

}


c.setLayout( new GridLayout(3,2));
lbl1 = new JLabel ("enter a name:");
lbl2 = new JLabel ("Telephone:");
c.add(lbl1);
c.add(lbl2);
txt1 = new JTextField(15) ;
txt2 = new JTextField(15) ;
c.add(txt1);
c.add(txt2);
bt1 = new JButton("Save");
bt1.addActionListener( this);
bt2 = new JButton("List");
bt2.addActionListener( this);
c.add(bt1);
c.add(bt2);
setVisible( true);

}

public void add_name(){


int phoneNumber;
if(!txt2.getText().equals(""))
{
try
{

phoneNumber = Integer.parseInt( txt2.getText() );
if (!phoneNumber.getText().equals(" ") ){

cikti.writeInt( phoneNumber );
cikti.writeUTF( txt1.getText());

}
txt1.setText( "");
txt2.setText( "");
}
catch(NumberFormatException nfe)

{

System.err.println("");

}

catch(IOException io)

{

System.err.println("err writing file\n"+io.toString());

System.exit(1);

}

}


}
public void actionPerformed(ActionEvent e){

add_name();
if(e.getSource() ==bt1){

try{ output.close();}

catch(IOException io)

{

System.err.println("File not Close\n"+io.toString());

}

System.exit(0);

}
}
}
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Mehmet-


please help me


Help with what? Does the code not work? If so, what is it supposed to do, and what does not work as you expect it to? Are there exceptions?

People here will be glad to help you, but they won't take a piece of code and try to figure out what's missing to make it a working program. You need to describe where you're stuck.
[ August 10, 2005: Message edited by: Ulf Dittmer ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!