The ToDo App is a simple Java Swing-based desktop application that allows users to add and delete tasks. It demonstrates the use of Swing components, event handling, and layout management in Java GUI development.
Build a To-Do list using Java Swing that performs basic task management operations.
- Java
- Swing (built-in GUI toolkit)
- IntelliJ IDEA Community Edition or Eclipse
A fully functional Java GUI application that supports adding and deleting tasks from a list.
- Add tasks to a list
- Delete selected tasks
- Scrollable task list using
JScrollPane - Simple and clean GUI layout
-
Save the code as
ToDoApp.java. -
Open a terminal in the project directory.
-
Compile the file:
javac ToDoApp.java
-
Run the program:
java ToDoApp
-
The ToDo App window will open where you can add or delete tasks.
- Swing Components (
JFrame,JPanel,JButton,JTextField,JList,JScrollPane) - Event Handling using
ActionListener - Layout Management (
BorderLayout,GridLayout) - DefaultListModel for dynamic task management
Swing is a Java GUI toolkit that provides lightweight components for building desktop applications.
AWT is platform-dependent and uses native components, while Swing is platform-independent and provides more flexible, lightweight components.
ActionListener is an interface used to handle action events, such as button clicks.
Layouts are managed using layout managers like BorderLayout, FlowLayout, and GridLayout to control component placement.
The Event Dispatch Thread (EDT) is a special thread that handles all GUI updates and event processing in Swing.
Common GUI components include JButton, JLabel, JTextField, JList, JPanel, and JFrame.
You can register multiple event listeners or use anonymous inner classes or lambda expressions to handle different events.
JFrame represents the main window, while JPanel is a container used to organize and group components within the frame.
A scrollbar can be added by wrapping components inside a JScrollPane, for example: new JScrollPane(JList).
MVC (Model-View-Controller) separates an application into three layers: Model (data), View (UI), and Controller (logic), improving modularity and maintainability.