abhs_94
Oct 27th, 2008, 09:04 AM
import java.io.FileOutputStream;
import java.io.FileInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import java.io.*;
import dat;
import java.awt.*;
import java.util.*;
import java.awt.event.*;
public class LinkedList1 extends Frame implements ActionListener, java.io.Serializable
{
Button bAdd;
Button bDel;
Button bFind;
TextField tName=new TextField(40);
TextField tId=new TextField(40);
TextField tNum=new TextField(40);
FileOutputStream outFile;
ObjectOutputStream out;
FileInputStream inFile;
ObjectInputStream in;
public static void main(String s[])
{
LinkedList1 l1=new LinkedList1();
l1.setSize(300,400);
l1.setVisible(true);
}
public void LinkedList1()
{
bAdd=new Button("Add");
bDel=new Button("Delete");
bFind=new Button("Find");
setLayout(new BorderLayout());
Panel p;
p=new Panel();
p.add(bAdd);
p.add(bDel);
p.add(bFind);
add("North",p);
p=new Panel();
p.setLayout(new GridLayout(3,2));
p.add(new Label("Name:"));
p.add(tName);
p.add(new Label("Email ID:"));
p.add(tId);
p.add(new Label("Phone Number:"));
p.add(tNum);
add(p);
bAdd.addActionListener(this);
bDel.addActionListener(this);
bFind.addActionListener(this);
try
{
outFile= new FileOutputStream("file.dat");
out = new ObjectOutputStream(outFile);
inFile= new FileInputStream("file.dat");
in = new ObjectInputStream(inFile);
}
catch(FileNotFoundException f)
{
System.out.println("erro");
}
catch(IOException io)
{
System.out.println("erro");
}
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==bAdd)
{
System.out.println("Test1");
//dat d=new dat("abhi","adgf","aiegfiyaf");
// out.writeObject(d);
}
else if(e.getSource()==bFind)
{
String sn;
sn=tName.getText();
dat dd;
try
{
while(in.readObject()!=null)
{
dd= (dat) in.readObject();
if(dd.name==sn)
{
tId.setText(dd.Id);
}
}
}
catch(OptionalDataException ode)
{
System.out.println("erro");
}
catch(ClassNotFoundException ode)
{
System.out.println("erro");
}
catch(IOException io)
{
System.out.println("erro");
}
}
}
}
Please ignore the name "linkedlist1". This file compiles easily but when i try to run it the frame doesn't show the panels it is supposed to. Please help
import java.io.FileInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import java.io.*;
import dat;
import java.awt.*;
import java.util.*;
import java.awt.event.*;
public class LinkedList1 extends Frame implements ActionListener, java.io.Serializable
{
Button bAdd;
Button bDel;
Button bFind;
TextField tName=new TextField(40);
TextField tId=new TextField(40);
TextField tNum=new TextField(40);
FileOutputStream outFile;
ObjectOutputStream out;
FileInputStream inFile;
ObjectInputStream in;
public static void main(String s[])
{
LinkedList1 l1=new LinkedList1();
l1.setSize(300,400);
l1.setVisible(true);
}
public void LinkedList1()
{
bAdd=new Button("Add");
bDel=new Button("Delete");
bFind=new Button("Find");
setLayout(new BorderLayout());
Panel p;
p=new Panel();
p.add(bAdd);
p.add(bDel);
p.add(bFind);
add("North",p);
p=new Panel();
p.setLayout(new GridLayout(3,2));
p.add(new Label("Name:"));
p.add(tName);
p.add(new Label("Email ID:"));
p.add(tId);
p.add(new Label("Phone Number:"));
p.add(tNum);
add(p);
bAdd.addActionListener(this);
bDel.addActionListener(this);
bFind.addActionListener(this);
try
{
outFile= new FileOutputStream("file.dat");
out = new ObjectOutputStream(outFile);
inFile= new FileInputStream("file.dat");
in = new ObjectInputStream(inFile);
}
catch(FileNotFoundException f)
{
System.out.println("erro");
}
catch(IOException io)
{
System.out.println("erro");
}
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==bAdd)
{
System.out.println("Test1");
//dat d=new dat("abhi","adgf","aiegfiyaf");
// out.writeObject(d);
}
else if(e.getSource()==bFind)
{
String sn;
sn=tName.getText();
dat dd;
try
{
while(in.readObject()!=null)
{
dd= (dat) in.readObject();
if(dd.name==sn)
{
tId.setText(dd.Id);
}
}
}
catch(OptionalDataException ode)
{
System.out.println("erro");
}
catch(ClassNotFoundException ode)
{
System.out.println("erro");
}
catch(IOException io)
{
System.out.println("erro");
}
}
}
}
Please ignore the name "linkedlist1". This file compiles easily but when i try to run it the frame doesn't show the panels it is supposed to. Please help