From 28c8e7737d7c01701cecdfe8be4c554f8846778c Mon Sep 17 00:00:00 2001 From: shanviii13 Date: Sun, 2 Jun 2024 14:23:59 +0530 Subject: [PATCH] Create easy level --- SHANVI SRIVASTAVA/easy level | 59 ++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 SHANVI SRIVASTAVA/easy level diff --git a/SHANVI SRIVASTAVA/easy level b/SHANVI SRIVASTAVA/easy level new file mode 100644 index 0000000..1fa175f --- /dev/null +++ b/SHANVI SRIVASTAVA/easy level @@ -0,0 +1,59 @@ +package com.example; +import javafx.application.Application; +import javafx.geometry.Insets; +import javafx.geometry.Pos; +import javafx.scene.Scene; +import javafx.scene.control.Button; +import javafx.scene.control.CheckBox; +import javafx.scene.control.ListView; +import javafx.scene.control.TextField; +import javafx.scene.layout.BorderPane; +import javafx.scene.layout.HBox; +import javafx.scene.layout.VBox; +import javafx.stage.Stage; + +public class ToDoListGUI extends Application { + private ListView listView; + private TextField taskInput; + + @Override + public void start(Stage primaryStage) { + BorderPane root = new BorderPane(); + listView = new ListView<>(); + taskInput = new TextField(); + taskInput.setPromptText("Enter a new task"); + Button addButton = new Button("Add"); + addButton.setOnAction(e -> addTask()); + Button deleteButton = new Button("Delete"); + deleteButton.setOnAction(e -> deleteTask()); + HBox inputBox = new HBox(10, taskInput, addButton, deleteButton); + inputBox.setAlignment(Pos.CENTER); + inputBox.setPadding(new Insets(10)); + VBox centerBox = new VBox(10, listView, inputBox); + centerBox.setPadding(new Insets(10)); + root.setCenter(centerBox); + Scene scene = new Scene(root, 300, 400); + primaryStage.setTitle("ToDo List"); + primaryStage.setScene(scene); + primaryStage.show(); + } + + private void addTask() { + String taskDescription = taskInput.getText().trim(); + if (!taskDescription.isEmpty()) { + listView.getItems().add(taskDescription); + taskInput.clear(); + } + } + + private void deleteTask() { + int selectedIndex = listView.getSelectionModel().getSelectedIndex(); + if (selectedIndex != -1) { + listView.getItems().remove(selectedIndex); + } + } + + public static void main(String[] args) { + launch(args); + } +}