This repository was archived by the owner on Jun 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy patheasy level
More file actions
59 lines (54 loc) · 1.93 KB
/
easy level
File metadata and controls
59 lines (54 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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<String> 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);
}
}