Skip to main content

I want to add, search, edit, delete record of employee

2 replies [Last post]
Joined: 2010-07-15


I want to add record of employees save to file .txt, then search edit and delete
but i don't know how to do it

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;

public class manager {
private JFrame f;
private JTabbedPane tp;
private JPanel p1, p2, p3, p4;
private JButton btn1, btn2;
private JLabel l1, l2, l3;
private JTextField t1, t2, t3;

p1 = new JPanel(new GridLayout(4,2));
p2 = new JPanel(new GridLayout(3,3));
p3 = new JPanel(new GridLayout(3,3));
p4 = new JPanel(new GridLayout(3,3));

btn1 = new JButton("Submit");
btn2 = new JButton("Reset");

p1.add(l1 = new JLabel("Employee ID"));
p1.add(t1 = new JTextField(10));
p1.add(l2 = new JLabel("Employee Name"));
p1.add(t2 = new JTextField(10));
p1.add(l3 = new JLabel("Employee Address"));
p1.add(t3 = new JTextField(10));

btn1.addActionListener(new ActionListener()
public void ActionPerformed(ActionEvent ae)
String s1 = t1.getText();
String s2 = t2.getText();
String s3 = t3.getText();

if(s1=="" || s2=="" || s3=="")


btn2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)


public void launchFrame()
f = new JFrame("Hello khakhakha!");

tp = new JTabbedPane();

Container c = f.getContentPane();

tp.addTab("Add record", p1);
tp.addTab("Edit record", p2);
tp.addTab("Search record", p3);
tp.addTab("Delete record", p4);


public static void main(String args[]) {
manager guiWindow = new manager();

Can you help me!
Thanks a lot.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2010-03-16

You got all the GUI. The next stage seems creating the file and then inserting the data into it.
I don't know how good it is to utilize text file to store employee information, if you're building such a thing. Also I do think that it will be cumbersome to write code to access retrieve and maintain such a file. (Sorry no experience in such a way and never tried it) It's better to have a database and then create tables in it. Then write code for saving the GUI data in database and your app is ready.
Something like this

Joined: 2004-01-19

I'd suggest using a CMV (Control, Model, View) pattern. The Control contains the business logic, the Model represents your data, and the View is the GUI.

I like starting with the Model. In your case, it looks like you need an Employee class with id, name, and name as fields. Never access the fields directly - use getters and setters.

Your Control will handle all file operations - adding a new employee, searching for an employee, updating an employee, and deleting an employee.

You've already starting on the View, but it is customary to use TitleCase for classes and camelCase for instance variables.

Your plea sounds a lot like homework, so I'll let you try figure some stuff out using my answer as a guideline. if you have specific questions, go ahead and ask in this thread.