Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

telephone book

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);

}
}
}
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
To do a great right, do a little wrong - shakepeare. twisted little ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic