Group#19
Group#19
Group#19
Project Title:
To-Do List System
Submitted to:
Ma’am Madiha Haider Syed
& Ma’am Zahra Abbas
Code:
package application;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.layout.*;
import javafx.stage.Stage;
import java.sql.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("To-Do List");
initializeDatabase();
tasks = FXCollections.observableArrayList();
ListView<TaskItem> todoListView = new ListView<>(tasks);
TextField taskInput = new TextField();
Button addButton = new Button("Add");
Button deleteButton = new Button("Delete");
Button completeButton = new Button("Complete");
Button editButton = new Button("Edit");
DatePicker datePicker = new DatePicker();
Button addDueDateButton = new Button("Add Due Date");
addButton.setOnAction(e -> {
String taskDescription = taskInput.getText().trim();
if (!taskDescription.isEmpty()) {
LocalDateTime timestamp = LocalDateTime.now();
LocalDate dueDate = LocalDate.now();
TaskItem newTask = new TaskItem(taskCounter++, taskDescription, timestamp,
dueDate, false);
tasks.add(newTask);
saveTaskToDatabase(newTask);
taskInput.clear();
}
});
deleteButton.setOnAction(e -> {
int selectedIndex = todoListView.getSelectionModel().getSelectedIndex();
if (selectedIndex != -1) {
TaskItem deletedTask = tasks.remove(selectedIndex);
deleteTaskFromDatabase(deletedTask);
}
});
completeButton.setOnAction(e -> {
int selectedIndex = todoListView.getSelectionModel().getSelectedIndex();
if (selectedIndex != -1) {
TaskItem selectedTask = tasks.get(selectedIndex);
selectedTask.setCompleted(true);
todoListView.refresh();
updateTaskInDatabase(selectedTask);
}
});
editButton.setOnAction(e -> {
int selectedIndex = todoListView.getSelectionModel().getSelectedIndex();
if (selectedIndex != -1) {
TaskItem selectedTask = tasks.get(selectedIndex);
String editedTaskDescription = taskInput.getText().trim();
if (!editedTaskDescription.isEmpty()) {
selectedTask.setDescription(editedTaskDescription);
taskInput.clear();
todoListView.refresh();
updateTaskInDatabase(selectedTask);
}
}
});
addDueDateButton.setOnAction(e -> {
int selectedIndex = todoListView.getSelectionModel().getSelectedIndex();
if (selectedIndex != -1) {
TaskItem selectedTask = tasks.get(selectedIndex);
LocalDate selectedDate = datePicker.getValue();
if (selectedDate != null) {
selectedTask.setDueDate(selectedDate);
datePicker.setValue(null);
todoListView.refresh();
updateTaskInDatabase(selectedTask);
} else {
System.out.println("Please select a due date.");
}
}
});
try {
Image backgroundImage = new
Image("file:///Users/ahmadlatif/Documents/Semester5/OOP/Lab/Chapter14/To-Do-List/
images/ali.jpeg");
BackgroundImage background = new BackgroundImage(
backgroundImage, BackgroundRepeat.REPEAT, BackgroundRepeat.REPEAT,
BackgroundPosition.DEFAULT, BackgroundSize.DEFAULT
);
Background backgroundObject = new Background(background);
pane.setBackground(backgroundObject);
} catch (Exception e) {
e.printStackTrace();
System.out.println("Error loading the background image: " + e.getMessage());
}
@Override
public String toString() {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String formattedTimestamp = timestamp.format(formatter);
String formattedDueDate = (dueDate != null) ? dueDate.toString() : "";
String status = completed ? " (Completed)" : "";
return id + ". " + description + " - " + formattedTimestamp +
" Due Date: " + formattedDueDate + status;
}
}
}
Interface:
How it works?
When we type our task in the first section and press add
button then the task will be added and displayed, and it
will also be saved into our database connected. The time
will be shown with task when it saved and the due date
will be automatically set as the current date.
We can further edit our task, Delete our task, Mark it as
Completed and change the due date. In case of Due Date,
the calendar will open as follow
Uses:
We can use it in our daily lives to manage our tasks.
Task Management is easy and compatible to
everyone.
We can retrieve each task from database.