-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTodoListApp.java
More file actions
78 lines (67 loc) · 2.53 KB
/
TodoListApp.java
File metadata and controls
78 lines (67 loc) · 2.53 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class TodoListApp extends JFrame {
private DefaultListModel<String> todoListModel;
private JList<String> todoList;
private JTextField newITF;
private JButton addButton;
private JButton removeButton;
public TodoListApp() {
setTitle("Java practice app");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(800,600);
setLayout(new BorderLayout());
//List model és lista
todoListModel = new DefaultListModel<>();
todoList = new JList<>(todoListModel);
JScrollPane scrollPane = new JScrollPane(todoList);
add(scrollPane, BorderLayout.CENTER);
// Törlés gomb
removeButton = new JButton("Törlés");
removeButton.setBackground(Color.green);
removeButton.setForeground(Color.BLUE);
removeButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int selectedIndex = todoList.getSelectedIndex();
if (selectedIndex != -1) {
todoListModel.remove(selectedIndex);
}
}
});
//Hozzáadás gomb
newITF = new JTextField();
addButton = new JButton("Hozzáadás");
addButton.setBackground(Color.GREEN);
addButton.setForeground(Color.BLUE);
addButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String newItem = newITF.getText();
if (!newItem.isEmpty()) {
todoListModel.addElement(newItem);
newITF.setText("");
}
}
});
// Panel
JPanel inputPanel = new JPanel(new BorderLayout());
inputPanel.setBackground(Color.GREEN);
inputPanel.setForeground(Color.GRAY);
inputPanel.add(newITF, BorderLayout.CENTER);
inputPanel.add(addButton, BorderLayout.EAST);
inputPanel.add(removeButton, BorderLayout.SOUTH);
add(inputPanel, BorderLayout.SOUTH);
setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new TodoListApp();
}
});
}
}