import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.awt.event.*;
public class addrecord extends JFrame implements ActionListener
{
JLabel l1,l2,l3,l4,l5,l6,l7;
JTextField t1,t2,t3,t4;
JTextArea t5,t6;
JButton btnAdd,btnClear,btnExit;
JPanel p1;
RandomAccessFile data;
int counter = 0;
String id[] = new String[20];
String joined[] = new String[20];
String name[] = new String[100];
String phone[] =new String[13];
String address[] = new String[100];
String additional[] = new String[200];
public addrecord() throws Exception
{
data = new RandomAccessFile("staff.dat","rw");
counter = data.readInt();
for(int x=0; x < counter; x++)
{
id[x] = data.readUTF();
joined[x] = data.readUTF();
name[x] = data.readUTF();
phone[x] = data.readUTF();
address[x] = data.readUTF();
additional[x] = data.readUTF();
}
data.close();
setTitle("ADD RECORD");
setSize(600,400);
setResizable(true);
setVisible(true);
l1 = new JLabel("Cust ID :");
l1.setBounds(30,40,150,25);
l2 = new JLabel("Cust Joined Date :");
l2.setBounds(30,70,200,25);
l3 = new JLabel("Cust Name :");
l3.setBounds(30,100,200,25);
l4 = new JLabel("Cust Contatc No. :");
l4.setBounds(30,130,200,25);
l5 = new JLabel("Cust Address :");
l5.setBounds(30,160,200,25);
l6 = new JLabel("Additional Info :");
l6.setBounds(30,230,200,25);
l7 = new JLabel("Add Record");
l7.setBounds(130,5,150,25);
t1 = new JTextField();
t1.setBounds(150,40,200,25);
t2 = new JTextField();
t2.setBounds(150,70,200,25);
t3 = new JTextField();
t3.setBounds(150,100,200,25);
t4 = new JTextField();
t4.setBounds(150,130,200,25);
t5 = new JTextArea();
JScrollPane addressScrollPane = new JScrollPane(t5, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
addressScrollPane.setBounds(150,160,250,65);
t6 = new JTextArea();
JScrollPane additionalScrollPane = new JScrollPane(t6, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
additionalScrollPane.setBounds(150,230,300,65);
btnAdd = new JButton("Add");
btnAdd.setBounds(50,310,100,25);
btnClear = new JButton("Clear");
btnClear.setBounds(160,310,100,25);
btnExit = new JButton("Exit");
btnExit.setBounds(270,310,100,25);
btnAdd.addActionListener(this);
btnClear.addActionListener(this);
btnExit.addActionListener(this);
p1 = new JPanel();
p1.setLayout(null);
p1.add(l1);
p1.add(l2);
p1.add(l3);
p1.add(l4);
p1.add(l5);
p1.add(l6);
p1.add(l7);
p1.add(t1);
p1.add(t2);
p1.add(t3);
p1.add(t4);
p1.add(addressScrollPane);
p1.add(additionalScrollPane);
p1.add(btnAdd);
p1.add(btnClear);
p1.add(btnExit);
getContentPane().add (p1);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == btnAdd)
{
id[counter] = t1.getText();
joined[counter] = t2.getText();
name[counter] = t3.getText();
phone[counter] = t4.getText();
address[counter] = t5.getText();
additional[counter] = t6.getText();
counter++;
try {
data = new RandomAccessFile("staff.dat","rw");
data.writeInt(counter);
for(int x=0; x < counter; x++)
{
data.writeUTF(id[x]);
data.writeUTF(joined[x]);
data.writeUTF(name[x]);
data.writeUTF(phone[x]);
data.writeUTF(address[x]);
data.writeUTF(additional[x]);
}
data.close();
JOptionPane.showMessageDialog(null, "File Saved !!");
} catch (Exception w){JOptionPane.showMessageDialog(null, "File unable to saved !!");}
}
else if (e.getSource() == btnClear)
{
t1.setText("");
t2.setText("");
t3.setText("");
t4.setText("");
t5.setText("");
t6.setText("");
}
else if (e.getSource() == btnExit)
{
System.exit(0);
}
}
//public static void main(String args[]) throws Exception
//{
//addrecord add = new addrecord();
// }
}