blah123123 0 Newbie Poster

Im trying to make an employee database where the user can add, delete, search for, view all, edit an employee, and quit. After the user clicks the add or delete button, the program is supposed to allow them to input the names and other things nd when they press enter it should add or delete an employee. Same for search and edit and view all is supposed to output all the names of the employees. Quit is just supposed to exit the program. I was able to create a fully functioning program without GUI but I was told to use GUI and I cannot create the program. Any help is appreciated.

Here is what i have done so far:
(The lines that are commented out are trial and error. I used them but I had some problems so I tried to make the program without them but I didnt want to completely take them out)

import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class EmployeeButtonstest implements ActionListener{
private JButton addButton;
private JButton deleteButton;
private JButton editButton;
private JButton searchButton;
private JButton viewButton;
private JButton quitButton;

JTextField fnameField = new JTextField (10);
JTextField lnameField = new JTextField (10);
JTextField phonenumField = new JTextField (20);
JTextField addressField = new JTextField (20);

JFrame frame;
JPanel panel;

public EmployeeButtonstest() {
//super ("ICT Employee Database");
frame = new JFrame("Test");
//frame.setLayout(new Layout(FlowLayout));
panel = new JPanel();
frame.setLayout(new FlowLayout());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setSize(800,300);

}

public void make(){

addButton = new JButton("Add Employee");
panel.add(addButton);

deleteButton = new JButton("Delete Employee");
panel.add(deleteButton);

editButton = new JButton("Edit Employee");
panel.add(editButton);

searchButton = new JButton("Search Employee");
panel.add(searchButton);

viewButton = new JButton("View Employees");
panel.add(viewButton);

quitButton = new JButton("Quit");
panel.add(quitButton);

addButton.addActionListener(this);
deleteButton.addActionListener(this);
editButton.addActionListener(this);
searchButton.addActionListener(this);
frame.add(panel);
}


public void actionPerformed(ActionEvent event) {

if (event.getSource() == addButton)
{
panel.revalidate();
panel.removeAll();

//add text fields
panel.add(fnameField);
panel.add(lnameField);
panel.add(phonenumField);
panel.add(addressField);

panel.repaint();
}
else if(event.getSource() == deleteButton)
{
//string = String.format("Delete Employee: %s", event.getActionCommand());

panel.revalidate();
panel.removeAll();
panel.add(fnameField);
panel.add(lnameField);

panel.repaint();
}
else if(event.getSource() == editButton)
{
//string = String.format("Edit Employee: %s", event.getActionCommand());

panel.revalidate();
panel.removeAll();
panel.add(fnameField);
panel.add(lnameField);

panel.repaint();

}
else if(event.getSource() == searchButton)
{
//string = String.format("Search Employee: %s", event.getActionCommand());

panel.revalidate();
panel.removeAll();
panel.add(fnameField);
panel.add(lnameField);

panel.repaint();
}

// JOptionPane.showMessageDialog(null, string);
}
}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.