From 3826d33c6b7ff7df1fd1343e93616483e0b6f12f Mon Sep 17 00:00:00 2001 From: 3009594 Date: Fri, 11 Oct 2024 00:26:58 +0200 Subject: [PATCH] TODO List --- .../TodoListApp/Domain/ProgrammSystem.java | 23 +++ .../src/TodoListApp/Domain/TaskList.java | 48 +++--- .../GUI_UserInterface/GUI_UserInterface.java | 81 +++++++++ .../GUI_UserInterface/GUI_addTask.java | 156 ++++++++++++++++++ .../GUI_UserInterface/Userverwalter.java | 71 ++++++++ Programmierung2/src/TodoListApp/Main.java | 4 +- .../src/TodoListApp/UserInterface.java | 5 +- 7 files changed, 357 insertions(+), 31 deletions(-) create mode 100644 Programmierung2/src/TodoListApp/Domain/ProgrammSystem.java create mode 100644 Programmierung2/src/TodoListApp/GUI_UserInterface/GUI_UserInterface.java create mode 100644 Programmierung2/src/TodoListApp/GUI_UserInterface/GUI_addTask.java create mode 100644 Programmierung2/src/TodoListApp/GUI_UserInterface/Userverwalter.java diff --git a/Programmierung2/src/TodoListApp/Domain/ProgrammSystem.java b/Programmierung2/src/TodoListApp/Domain/ProgrammSystem.java new file mode 100644 index 0000000..86eb69e --- /dev/null +++ b/Programmierung2/src/TodoListApp/Domain/ProgrammSystem.java @@ -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 showAllTasks() { + return tasks.printAllTask(); + } + + + +} diff --git a/Programmierung2/src/TodoListApp/Domain/TaskList.java b/Programmierung2/src/TodoListApp/Domain/TaskList.java index 68e1dae..1f3223f 100644 --- a/Programmierung2/src/TodoListApp/Domain/TaskList.java +++ b/Programmierung2/src/TodoListApp/Domain/TaskList.java @@ -7,37 +7,33 @@ import TodoListApp.Domain.KlassenException.*; public class TaskList { private ArrayList alleTasks; - private Task task; - - public TaskList() { this.alleTasks = new ArrayList<>(); } - public boolean addTask(String title, String beschreibung, String eingabeTaskprioritaet)throws FalscheEinagebException { - Prioritaet taskPrioritaet = null; - switch (eingabeTaskprioritaet) { - case "niedrig": - taskPrioritaet = taskPrioritaet.Niedrig; - break; + public boolean addTaskZuList(String title, String beschreibung, String eingabeTaskprioritaet) { + Prioritaet taskPrioritaet = null; + switch (eingabeTaskprioritaet) { + case "niedrig": + taskPrioritaet = taskPrioritaet.Niedrig; + break; - case "mittel": - taskPrioritaet = taskPrioritaet.Mittel; - break; + case "mittel": + taskPrioritaet = taskPrioritaet.Mittel; + break; - case "hoch": - taskPrioritaet = taskPrioritaet.Hoch; - break; - default: - taskPrioritaet = taskPrioritaet.Niedrig; - throw new FalscheEinagebException("Ungültige Priorität. Standardmäßig wird 'niedrig' verwendet"); + case "hoch": + taskPrioritaet = taskPrioritaet.Hoch; + break; + default: + taskPrioritaet = taskPrioritaet.Niedrig; + } + + alleTasks.add(new Task(title,beschreibung,taskPrioritaet)); + return true; } - task = new Task(title,beschreibung,taskPrioritaet); - alleTasks.add(task); - return true; - - } + public boolean removeTask(Task task) { @@ -59,7 +55,7 @@ public class TaskList { throw new TaskNichtGefundenException("Task wurde nicht gefunden" ); } - public ArrayList getAlleGemachteTasks() { + public ArrayList printAlleGemachteTasks() { ArrayList alleGemachteTasks = new ArrayList<>(); for (Task t : alleTasks) { if (t.isIstGemacht() == true) @@ -73,12 +69,8 @@ public class TaskList { int index = 1; for (Task t : alleTasks) { printallTasks.add(index++ + ".Task: " + t.toString() + "."); - printallTasks.add("\n"); } - - return printallTasks; - } } diff --git a/Programmierung2/src/TodoListApp/GUI_UserInterface/GUI_UserInterface.java b/Programmierung2/src/TodoListApp/GUI_UserInterface/GUI_UserInterface.java new file mode 100644 index 0000000..2490d17 --- /dev/null +++ b/Programmierung2/src/TodoListApp/GUI_UserInterface/GUI_UserInterface.java @@ -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; + } + + +} diff --git a/Programmierung2/src/TodoListApp/GUI_UserInterface/GUI_addTask.java b/Programmierung2/src/TodoListApp/GUI_UserInterface/GUI_addTask.java new file mode 100644 index 0000000..fee6f93 --- /dev/null +++ b/Programmierung2/src/TodoListApp/GUI_UserInterface/GUI_addTask.java @@ -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); + } +} + diff --git a/Programmierung2/src/TodoListApp/GUI_UserInterface/Userverwalter.java b/Programmierung2/src/TodoListApp/GUI_UserInterface/Userverwalter.java new file mode 100644 index 0000000..235947b --- /dev/null +++ b/Programmierung2/src/TodoListApp/GUI_UserInterface/Userverwalter.java @@ -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"); + } + } +} diff --git a/Programmierung2/src/TodoListApp/Main.java b/Programmierung2/src/TodoListApp/Main.java index 80f0553..5ab2c0a 100644 --- a/Programmierung2/src/TodoListApp/Main.java +++ b/Programmierung2/src/TodoListApp/Main.java @@ -1,11 +1,13 @@ package TodoListApp; import TodoListApp.Domain.KlassenException.FalscheEinagebException; +import TodoListApp.GUI_UserInterface.GUI_UserInterface; +import TodoListApp.GUI_UserInterface.Userverwalter; public class Main { public static void main(String[] args) throws FalscheEinagebException { - new UserInterface(); + new Userverwalter(); } diff --git a/Programmierung2/src/TodoListApp/UserInterface.java b/Programmierung2/src/TodoListApp/UserInterface.java index 23a132c..356b894 100644 --- a/Programmierung2/src/TodoListApp/UserInterface.java +++ b/Programmierung2/src/TodoListApp/UserInterface.java @@ -19,6 +19,7 @@ public class UserInterface { String beschreibung; String taskprioritaet; boolean aktiv = true; + System.out.println(); System.out.println("<>"); System.out.println(); while (aktiv) { @@ -43,8 +44,8 @@ public class UserInterface { System.out.print("Taskpriorität:"); System.out.print("> "); taskprioritaet = eingabe.nextLine().trim(); - if (tasks.addTask(title, beschreibung, taskprioritaet)) - System.out.println("Task erfolgreich hinzugefügt"); +// if (tasks.addTask(title, beschreibung, taskprioritaet)) +// System.out.println("Task erfolgreich hinzugefügt"); break; case "2":