Ajp MP

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

A

PROJECT REPORT
ON

“Address Book”

DIPLOMA IN COMPUTER ENGINEERING

BY

MR.Chudiwal Shreaysh Rajendra(19)

Under the guidance of


Miss.R.S.Patil

DEPARTMENT OF COMPUTER ENGINEERING SANJIVANI RURAL


EDUCATION SOCIETY’S SANJIVANI K.B.P. POLYTECHNIC,
KOPARGAON-423603
2023-2024

MISS.R.S.PATIL MR.G.N.JORVEKAR
(Subject Teacher) (H.O.D)
INDEX
SR.NO. TITLE PAGE NO.
1 Introduction 3
2 Algorithm 4
3 Program Code 5
4 Output 7
5 Conclusion 9
6 Reference 9
INTRODUCTION

The provided Java code is an implementation of a simple address book application using
Java Swing, a toolkit for creating graphical user interfaces in Java. This address book
application serves as a practical example of creating a basic desktop application for
managing a list of contacts. It allows users to add and remove contact names in a graphical
user interface. At its core, the "AddressBook" class extends the JFrame class, which is a top-
level container for holding Swing components. It encapsulates the entire application, and its
primary responsibilities include managing the list of contacts, creating and updating the
graphical user interface, and handling user interactions. The application's user interface
comprises a list of contacts displayed in a JList component, along with two buttons for
adding and removing contacts. These buttons are contained within a separate JPanel for a
cleaner layout. The "Add Contact" button allows users to input the name of a new contact,
and this name is then added to both the contact list and the JList model. Conversely, the
"Remove Contact" button allows users to select a contact from the list and remove it.
Overall, this code is a demonstration of building a basic desktop application in Java,
providing a foundation for more complex applications. It showcases how to create a Swing-
based graphical user interface, handle user interactions, and maintain data in a list model.
While this code is intentionally simple, it can be a starting point for creating more feature-
rich address book applications, integrating functionalities like saving and loading contacts, or
even connecting to external databases for more robust contact management.
Algorithm

1. Import the necessary Java Swing libraries for GUI development.

2. Create a class named "AddressBook" that extends `JFrame` to build the main application
window.

3. Declare and initialize essential class members:


- `contacts`: An `ArrayList` to store contact names.
- `contactList`: A `JList` for displaying contacts.
- `listModel`: A `DefaultListModel` to manage data in the `JList`.
- `startButton`: A button to start the application.
- `stopButton`: A button to stop the application.

4. Configure the main frame by setting its title, size, and default close operation.

5. Create two main panels:


- `listPanel` for displaying the contact list.
- `buttonPanel` for housing the "Add Contact," "Remove Contact," "Start," and "Stop"
buttons.

6. Create the "Add Contact" button that allows users to input a contact's name via a dialog
box and adds the name to both the `contacts` list and the `listModel`.

7. Create the "Remove Contact" button, which enables users to select a contact from the list
and remove it, updating both the `contacts` list and the `listModel.

8. Create the "Start" button to begin the application. When clicked, this button initializes the
application and activates the "Add Contact" and "Remove Contact" buttons.

9. Create the "Stop" button to halt the application. When clicked, this button deactivates the
"Add Contact" and "Remove Contact" buttons, preventing further interactions.

10. Implement the `main` method as the entry point for the application. Within this method,
ensure that the graphical user interface components are created and updated on the Swing
event dispatch thread to avoid concurrency issues. Create an instance of the "AddressBook"
class, make the main application window visible, and run the application.
PROGRAM CODE

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class EntryExitApp {


private JFrame frame;
private DefaultListModel<String> entryListModel;
private JList<String> entryList;

public EntryExitApp() {
frame = new JFrame("Entry and Exit Management");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());

entryListModel = new DefaultListModel<>();


entryList = new JList<>(entryListModel);

JButton addButton = new JButton("Add Entry");


addButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
addEntry();
}
});

JButton removeButton = new JButton("Remove Entry");


removeButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
removeEntry();
}
});

JPanel buttonPanel = new JPanel();


buttonPanel.add(addButton);
buttonPanel.add(removeButton);
frame.add(buttonPanel, BorderLayout.NORTH);
frame.add(new JScrollPane(entryList), BorderLayout.CENTER);

frame.setSize(400, 300);
frame.setVisible(true);
}

private void addEntry() {


String name = JOptionPane.showInputDialog("Enter Name:");
String address = JOptionPane.showInputDialog("Enter Address:");
String intime = JOptionPane.showInputDialog("Enter In Time:");

if (name != null && address != null && intime != null) {


String entry = "Name: " + name + ", Address: " + address + ", In Time: " + intime;
entryListModel.addElement(entry);
}
}

private void removeEntry() {


int selectedIndex = entryList.getSelectedIndex();
if (selectedIndex != -1) {
entryListModel.remove(selectedIndex);
}
}

public static void main(String[] args) {


SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new EntryExitApp();
}
});
}
}
OUTPUT
CONCLUSION

The provided Java code exemplifies a simple address book application built using Java
Swing. It introduces a graphical user interface (GUI) where users can manage a list of
contact names. The application extends the JFrame class, defining a main window for the
address book. Within this frame, the code initializes data structures like an ArrayList for
storing contacts, a JList for displaying them, and a DefaultListModel for managing the data
within the JList.

The GUI consists of two primary panels: one for displaying the contact list and the other for
housing buttons to add and remove contacts. Users can input a contact's name through a
dialog box, and upon submission, the name is dynamically added to both the contact list and
the JList. Similarly, users can select a contact from the list and remove it using the "Remove
Contact" button, updating the list in real-time.

This code demonstrates core principles of Java Swing, event handling, and building a
functional desktop application. It can serve as a fundamental building block for more
complex software projects involving contact management, data persistence, and advanced
features. In essence, it provides a solid starting point for those interested in GUI development
with Java.

REFERENCE

Sites:-
https://www.javatpoint.com/java-tutorial
https://www.geeksforgeeks.org/java/?ref=ghm

Books:-
Advanced Java Programming (Uttam K. Roy, 2015)
The Java Programming Language (James Gosling, 1995)

You might also like