Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.debug.settings.onBuildFailureProceed": true
}
11 changes: 11 additions & 0 deletions Java Code/.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1753897780379</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
Binary file added Java Code/src/PhoneDirectoryGUI$Contact.class
Binary file not shown.
Binary file added Java Code/src/PhoneDirectoryGUI.class
Binary file not shown.
128 changes: 128 additions & 0 deletions Java Code/src/PhoneDirectoryGUI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import javax.swing.*;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.*;
import java.util.*;

public class PhoneDirectoryGUI {

static class Contact {
String firstName, lastName, email, phone, job;

Contact(String f, String l, String e, String p, String j) {
firstName = f;
lastName = l;
email = e;
phone = p;
job = j;
}

@Override
public String toString() {
return firstName + " " + lastName + ", " + email + ", " + phone + ", " + job;
}
}

static List<Contact> contacts = new ArrayList<>();
static JTextArea outputArea;

public static void main(String[] args) {
JFrame frame = new JFrame("Phone Directory");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 600);

JPanel panel = new JPanel();
panel.setLayout(new GridLayout(0, 2, 5, 5));

JTextField tfFirst = new JTextField();
JTextField tfLast = new JTextField();
JTextField tfEmail = new JTextField();
JTextField tfPhone = new JTextField();
JTextField tfJob = new JTextField();
JTextField tfSearch = new JTextField();

panel.add(new JLabel("First Name:"));
panel.add(tfFirst);
panel.add(new JLabel("Last Name:"));
panel.add(tfLast);
panel.add(new JLabel("Email:"));
panel.add(tfEmail);
panel.add(new JLabel("Phone:"));
panel.add(tfPhone);
panel.add(new JLabel("Job Title:"));
panel.add(tfJob);
panel.add(new JLabel("Search (Name/Phone):"));
panel.add(tfSearch);

JButton addBtn = new JButton("Add Contact");
JButton showBtn = new JButton("Show All");
JButton deleteBtn = new JButton("Delete");
JButton updateBtn = new JButton("Update");
JButton searchBtn = new JButton("Search");

panel.add(addBtn);
panel.add(showBtn);
panel.add(deleteBtn);
panel.add(updateBtn);
panel.add(searchBtn);

outputArea = new JTextArea(10, 40);
JScrollPane scrollPane = new JScrollPane(outputArea);

addBtn.addActionListener(e -> {
Contact c = new Contact(tfFirst.getText(), tfLast.getText(), tfEmail.getText(), tfPhone.getText(),
tfJob.getText());
contacts.add(c);
outputArea.setText("Added: " + c + "\n");
clearFields(tfFirst, tfLast, tfEmail, tfPhone, tfJob);
});

showBtn.addActionListener(e -> {
StringBuilder sb = new StringBuilder("All Contacts:\n");
for (Contact c : contacts)
sb.append(c).append("\n");
outputArea.setText(sb.toString());
});

deleteBtn.addActionListener(e -> {
String key = tfSearch.getText();
contacts.removeIf(c -> c.firstName.equalsIgnoreCase(key) || c.phone.equals(key));
outputArea.setText("Deleted contacts with name or phone: " + key);
});

searchBtn.addActionListener(e -> {
String key = tfSearch.getText();
StringBuilder sb = new StringBuilder("Search Results:\n");
for (Contact c : contacts) {
if (c.firstName.equalsIgnoreCase(key) || c.phone.equals(key))
sb.append(c).append("\n");
}
outputArea.setText(sb.toString());
});

updateBtn.addActionListener(e -> {
String key = tfSearch.getText();
for (Contact c : contacts) {
if (c.firstName.equalsIgnoreCase(key) || c.phone.equals(key)) {
c.firstName = tfFirst.getText();
c.lastName = tfLast.getText();
c.email = tfEmail.getText();
c.phone = tfPhone.getText();
c.job = tfJob.getText();
outputArea.setText("Updated: " + c + "\n");
break;
}
}
});

frame.getContentPane().add(panel, BorderLayout.NORTH);
frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
frame.setVisible(true);
}

static void clearFields(JTextField... fields) {
for (JTextField f : fields)
f.setText("");
}
}
11 changes: 11 additions & 0 deletions JavaComplete/.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1753897780398</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
Binary file modified JavaComplete/bin/Animal.class
Binary file not shown.
11 changes: 11 additions & 0 deletions JavaLesson41/.project
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,15 @@
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>
<filteredResources>
<filter>
<id>1753897780405</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>