java.Microproject_repaired
java.Microproject_repaired
SEMESTER: IV
Part A
2.Editing Contact:
User should be able to modify existing contact details.
3.Searching Contacts:
The application should provide a way to find specific contacts by
Name,number,or other criteria.
4.Displaying Contact:
Users should be able to view a list of all stored contacts or search
Results.
5.Deleting Contacts:
The application should allow users to remove contact.
6.Data Storage:
the contact information can be stored in a database or a simple file
system.
CODE :
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
public ContactBookAWT() {
prepareGUI();
}
private void prepareGUI() {
mainFrame = new Frame("Contact Book");
mainFrame.setSize(600, 500);
mainFrame.setLayout(new BorderLayout(10, 10)); mainFrame.addWindowListener(new
WindowAdapter() {
public void windowClosing(WindowEvent windowEvent) {
System.exit(0);
}
});
inputPanel = new Panel();
inputPanel.setLayout(new GridLayout(3, 2, 5, 5));
inputPanel.setPreferredSize(new Dimension(550, 100));
inputPanel.add(nameLabel);
inputPanel.add(nameText);
inputPanel.add(phoneLabel);
inputPanel.add(phoneText);
inputPanel.add(emailLabel);
inputPanel.add(emailText);
buttonPanel.add(addButton);
buttonPanel.add(viewButton);
buttonPanel.add(deleteButton);
buttonPanel.add(clearButton);
mainFrame.add(inputPanel, BorderLayout.NORTH);
mainFrame.add(buttonPanel, BorderLayout.CENTER);
mainFrame.add(displayPanel, BorderLayout.SOUTH);
mainFrame.setVisible(true);
}
if (!name.isEmpty()) {
for (int i = 0; i < contacts.size(); i++) {
if (contacts.get(i).contains("Name: " + name)) {
contacts.remove(i);
found = true;
break;
}
}
if (found) {
contactArea.setText("Contact Deleted Successfully!\n");
} else {
contactArea.setText("Contact Not Found!\n");
}
clearFields();
} else {
contactArea.setText("Enter a name to delete!\n");
}
}