diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..c995aa5 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.debug.settings.onBuildFailureProceed": true +} \ No newline at end of file diff --git a/Java Code/.project b/Java Code/.project index 5a05115..bec1bdc 100644 --- a/Java Code/.project +++ b/Java Code/.project @@ -14,4 +14,15 @@ org.eclipse.jdt.core.javanature + + + 1753897780379 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/Java Code/src/PhoneDirectoryGUI$Contact.class b/Java Code/src/PhoneDirectoryGUI$Contact.class new file mode 100644 index 0000000..e4fb05e Binary files /dev/null and b/Java Code/src/PhoneDirectoryGUI$Contact.class differ diff --git a/Java Code/src/PhoneDirectoryGUI.class b/Java Code/src/PhoneDirectoryGUI.class new file mode 100644 index 0000000..f20faf8 Binary files /dev/null and b/Java Code/src/PhoneDirectoryGUI.class differ diff --git a/Java Code/src/PhoneDirectoryGUI.java b/Java Code/src/PhoneDirectoryGUI.java new file mode 100644 index 0000000..bfe1b82 --- /dev/null +++ b/Java Code/src/PhoneDirectoryGUI.java @@ -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 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(""); + } +} diff --git a/JavaComplete/.project b/JavaComplete/.project index 0e17203..d3b55d0 100644 --- a/JavaComplete/.project +++ b/JavaComplete/.project @@ -14,4 +14,15 @@ org.eclipse.jdt.core.javanature + + + 1753897780398 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/JavaComplete/bin/Animal.class b/JavaComplete/bin/Animal.class index de0dd49..4de6ea5 100644 Binary files a/JavaComplete/bin/Animal.class and b/JavaComplete/bin/Animal.class differ diff --git a/JavaLesson41/.project b/JavaLesson41/.project index 087e90c..cd2d567 100644 --- a/JavaLesson41/.project +++ b/JavaLesson41/.project @@ -33,4 +33,15 @@ org.eclipse.jdt.core.javanature org.eclipse.wst.jsdt.core.jsNature + + + 1753897780405 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + +