TODO List

master
3009594 2024-10-11 00:26:58 +02:00
parent 1ba8e34a54
commit 3826d33c6b
7 changed files with 357 additions and 31 deletions

View File

@ -0,0 +1,23 @@
package TodoListApp.Domain;
import java.util.ArrayList;
public class ProgrammSystem {
private TaskList tasks;
public ProgrammSystem() {
this.tasks = new TaskList();
}
public void addTask(String title, String beschreibung, String eingabeTaskprioritaet){
tasks.addTaskZuList(title, beschreibung, eingabeTaskprioritaet);
}
public ArrayList<String> showAllTasks() {
return tasks.printAllTask();
}
}

View File

@ -7,15 +7,12 @@ import TodoListApp.Domain.KlassenException.*;
public class TaskList { public class TaskList {
private ArrayList<Task> alleTasks; private ArrayList<Task> alleTasks;
private Task task;
public TaskList() { public TaskList() {
this.alleTasks = new ArrayList<>(); this.alleTasks = new ArrayList<>();
} }
public boolean addTask(String title, String beschreibung, String eingabeTaskprioritaet)throws FalscheEinagebException { public boolean addTaskZuList(String title, String beschreibung, String eingabeTaskprioritaet) {
Prioritaet taskPrioritaet = null; Prioritaet taskPrioritaet = null;
switch (eingabeTaskprioritaet) { switch (eingabeTaskprioritaet) {
case "niedrig": case "niedrig":
@ -31,14 +28,13 @@ public class TaskList {
break; break;
default: default:
taskPrioritaet = taskPrioritaet.Niedrig; taskPrioritaet = taskPrioritaet.Niedrig;
throw new FalscheEinagebException("Ungültige Priorität. Standardmäßig wird 'niedrig' verwendet");
} }
task = new Task(title,beschreibung,taskPrioritaet);
alleTasks.add(task);
return true;
alleTasks.add(new Task(title,beschreibung,taskPrioritaet));
return true;
} }
public boolean removeTask(Task task) { public boolean removeTask(Task task) {
for (Task t : alleTasks) { for (Task t : alleTasks) {
@ -59,7 +55,7 @@ public class TaskList {
throw new TaskNichtGefundenException("Task wurde nicht gefunden" ); throw new TaskNichtGefundenException("Task wurde nicht gefunden" );
} }
public ArrayList<String> getAlleGemachteTasks() { public ArrayList<String> printAlleGemachteTasks() {
ArrayList<String> alleGemachteTasks = new ArrayList<>(); ArrayList<String> alleGemachteTasks = new ArrayList<>();
for (Task t : alleTasks) { for (Task t : alleTasks) {
if (t.isIstGemacht() == true) if (t.isIstGemacht() == true)
@ -73,12 +69,8 @@ public class TaskList {
int index = 1; int index = 1;
for (Task t : alleTasks) { for (Task t : alleTasks) {
printallTasks.add(index++ + ".Task: " + t.toString() + "."); printallTasks.add(index++ + ".Task: " + t.toString() + ".");
printallTasks.add("\n");
} }
return printallTasks; return printallTasks;
} }
} }

View File

@ -0,0 +1,81 @@
package TodoListApp.GUI_UserInterface;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
import TodoListApp.Domain.*;
public class GUI_UserInterface extends JFrame {
private JPanel contentPane;
private JButton addTask;
private JButton zeigeAlleTasks;
private JTextArea AllTasksArea;
public GUI_UserInterface() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
setBounds(100, 100, 696, 661);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JPanel panel = new JPanel();
panel.setBackground(new Color(0, 128, 255));
panel.setBounds(0, 0, 680, 622);
contentPane.add(panel);
panel.setLayout(null);
JLabel lblNewLabel = new JLabel("TO DO List");
lblNewLabel.setForeground(new Color(255, 255, 255));
lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 22));
lblNewLabel.setBounds(152, 24, 340, 57);
panel.add(lblNewLabel);
JPanel panel_1 = new JPanel();
panel_1.setBounds(10, 97, 660, 398);
panel.add(panel_1);
panel_1.setLayout(null);
AllTasksArea = new JTextArea();
AllTasksArea.setEnabled(false);
AllTasksArea.setEditable(false);
AllTasksArea.setForeground(new Color(0, 0, 0));
AllTasksArea.setFont(new Font("Arial", Font.BOLD, 14));
AllTasksArea.setBounds(10, 11, 640, 376);
panel_1.add(AllTasksArea);
addTask = new JButton("Task hinzufügen");
addTask.setBounds(10, 506, 159, 29);
panel.add(addTask);
zeigeAlleTasks = new JButton("Alle Taks");
zeigeAlleTasks.setBounds(193, 506, 159, 29);
panel.add(zeigeAlleTasks);
this.setVisible(true);
}
public JButton getAddTask() {
return addTask;
}
public JButton getZeigeAlleTasks() {
return zeigeAlleTasks;
}
public JTextArea getAllTasksArea() {
return AllTasksArea;
}
public void setAllTasksArea(JTextArea allTasksArea) {
AllTasksArea = allTasksArea;
}
}

View File

@ -0,0 +1,156 @@
package TodoListApp.GUI_UserInterface;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import javax.swing.table.DefaultTableModel;
import TodoListApp.Domain.*;
public class GUI_addTask extends JFrame {
private JPanel contentPane;
private JTextField tasktitle;
private JTextField taskBeschreibung;
private ButtonGroup priorityGroup;
private JButton submitTask;
private JRadioButton hoch, mittel,niedrig ;
public GUI_addTask() {
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE );
setBounds(100, 100, 515, 618);
contentPane = new JPanel();
contentPane.setBackground(new Color(255, 255, 255));
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JPanel panel = new JPanel();
panel.setBorder(new LineBorder(new Color(255, 255, 255), 3));
panel.setBackground(new Color(0, 128, 255));
panel.setForeground(new Color(255, 255, 255));
panel.setBounds(31, 26, 441, 517);
contentPane.add(panel);
panel.setLayout(null);
JLabel lblNewLabel = new JLabel("Füge Task hinzu");
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 18));
lblNewLabel.setForeground(new Color(255, 255, 255));
lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel.setBounds(76, 11, 289, 58);
panel.add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("Title:");
lblNewLabel_1.setForeground(new Color(255, 255, 255));
lblNewLabel_1.setHorizontalAlignment(SwingConstants.LEFT);
lblNewLabel_1.setFont(new Font("Tahoma", Font.BOLD, 14));
lblNewLabel_1.setBounds(24, 79, 103, 14);
panel.add(lblNewLabel_1);
JLabel lblNewLabel_1_1 = new JLabel("Beschreibung: ");
lblNewLabel_1_1.setHorizontalAlignment(SwingConstants.LEFT);
lblNewLabel_1_1.setForeground(Color.WHITE);
lblNewLabel_1_1.setFont(new Font("Tahoma", Font.BOLD, 14));
lblNewLabel_1_1.setBounds(24, 121, 103, 14);
panel.add(lblNewLabel_1_1);
JLabel lblNewLabel_1_3 = new JLabel("Priorität:");
lblNewLabel_1_3.setHorizontalAlignment(SwingConstants.LEFT);
lblNewLabel_1_3.setForeground(Color.WHITE);
lblNewLabel_1_3.setFont(new Font("Tahoma", Font.BOLD, 14));
lblNewLabel_1_3.setBounds(24, 203, 103, 14);
panel.add(lblNewLabel_1_3);
tasktitle = new JTextField();
tasktitle.setBounds(142, 77, 133, 20);
panel.add(tasktitle);
tasktitle.setColumns(10);
taskBeschreibung = new JTextField();
taskBeschreibung.setColumns(10);
taskBeschreibung.setBounds(142, 119, 133, 20);
panel.add(taskBeschreibung);
// RadioButtons erstellen
hoch = new JRadioButton("Hoch");
hoch.setSelected(true);
hoch.setBounds(142, 165, 89, 23);
panel.add(hoch);
mittel = new JRadioButton("Mittel");
mittel.setBounds(142, 201, 89, 23);
panel.add(mittel);
niedrig = new JRadioButton("Niedrig");
niedrig.setBounds(142, 240, 89, 23);
panel.add(niedrig);
// ButtonGroup erstellen, um die RadioButtons zu gruppieren
priorityGroup = new ButtonGroup();
priorityGroup.add(hoch);
priorityGroup.add(mittel);
priorityGroup.add(niedrig);
submitTask = new JButton("Submit");
submitTask.setBounds(24, 323, 123, 23);
panel.add(submitTask);
}
public void zeigeFensterAddTask() {
this.setVisible(true);
}
public void closeFensterAddTask() {
this.setVisible(false);
}
public JTextField getTasktitle() {
return tasktitle;
}
public void setTasktitle(JTextField tasktitle) {
this.tasktitle = tasktitle;
}
public JTextField getTaskBeschreibung() {
return taskBeschreibung;
}
public void setTaskBeschreibung(JTextField taskBeschreibung) {
this.taskBeschreibung = taskBeschreibung;
}
public ButtonGroup getPriorityGroup() {
return priorityGroup;
}
public JButton getSubmitTask() {
return submitTask;
}
public JRadioButton getHoch() {
return hoch;
}
public JRadioButton getMittel() {
return mittel;
}
public JRadioButton getNiedrig() {
return niedrig;
}
public void resetButtons() {
tasktitle.setText("");
taskBeschreibung.setText("");
hoch.setSelected(true);
}
public void showInfo(String message) {
JOptionPane.showMessageDialog(null, message, "Studen angemeldet", JOptionPane.INFORMATION_MESSAGE);
}
}

View File

@ -0,0 +1,71 @@
package TodoListApp.GUI_UserInterface;
import TodoListApp.Domain.ProgrammSystem;
import TodoListApp.Domain.KlassenException.FalscheEinagebException;
public class Userverwalter {
private ProgrammSystem system;
private GUI_UserInterface user;
private GUI_addTask taskHinziFuegenFenster;
public Userverwalter() {
this.system = new ProgrammSystem();
this.user = new GUI_UserInterface();
this.taskHinziFuegenFenster = new GUI_addTask();
// Buttons User:
user.getAddTask().addActionListener(e -> {
try {
zeigeFenster();
} catch (FalscheEinagebException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
});
taskHinziFuegenFenster.getSubmitTask().addActionListener(e -> {
try {
addTask();
} catch (FalscheEinagebException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
});
user.getZeigeAlleTasks().addActionListener(e -> showAllTasks());
}
public void zeigeFenster() throws FalscheEinagebException {
taskHinziFuegenFenster.zeigeFensterAddTask();
}
public void addTask() throws FalscheEinagebException {
String title = taskHinziFuegenFenster.getTasktitle().getText();
String beschreibung = taskHinziFuegenFenster.getTaskBeschreibung().getText();
String priorität;
if (taskHinziFuegenFenster.getHoch().isSelected())
priorität = "hoch";
else if (taskHinziFuegenFenster.getMittel().isSelected())
priorität = "mittle";
else if (taskHinziFuegenFenster.getNiedrig().isSelected())
priorität = "niedrig";
else
priorität = "niedrig";
system.addTask(title, beschreibung, priorität);
taskHinziFuegenFenster.resetButtons();
taskHinziFuegenFenster.showInfo("Neuer Task wurde Erfolgreich hinzugefügt!");
}
public void showAllTasks() {
for (String s : system.showAllTasks()) {
user.getAllTasksArea().append(s);
user.getAllTasksArea().append("\n");
}
}
}

View File

@ -1,11 +1,13 @@
package TodoListApp; package TodoListApp;
import TodoListApp.Domain.KlassenException.FalscheEinagebException; import TodoListApp.Domain.KlassenException.FalscheEinagebException;
import TodoListApp.GUI_UserInterface.GUI_UserInterface;
import TodoListApp.GUI_UserInterface.Userverwalter;
public class Main { public class Main {
public static void main(String[] args) throws FalscheEinagebException { public static void main(String[] args) throws FalscheEinagebException {
new UserInterface(); new Userverwalter();
} }

View File

@ -19,6 +19,7 @@ public class UserInterface {
String beschreibung; String beschreibung;
String taskprioritaet; String taskprioritaet;
boolean aktiv = true; boolean aktiv = true;
System.out.println();
System.out.println("<<Willkommen in meinem ToDo-List Programm>>"); System.out.println("<<Willkommen in meinem ToDo-List Programm>>");
System.out.println(); System.out.println();
while (aktiv) { while (aktiv) {
@ -43,8 +44,8 @@ public class UserInterface {
System.out.print("Taskpriorität:"); System.out.print("Taskpriorität:");
System.out.print("> "); System.out.print("> ");
taskprioritaet = eingabe.nextLine().trim(); taskprioritaet = eingabe.nextLine().trim();
if (tasks.addTask(title, beschreibung, taskprioritaet)) // if (tasks.addTask(title, beschreibung, taskprioritaet))
System.out.println("Task erfolgreich hinzugefügt"); // System.out.println("Task erfolgreich hinzugefügt");
break; break;
case "2": case "2":