diff --git a/Programmierung2/src/TodoListApp/GUI_UserInterface/GUI_UserInterface.java b/Programmierung2/src/TodoListApp/GUI_UserInterface/GUI_UserInterface.java index 2490d17..d827e38 100644 --- a/Programmierung2/src/TodoListApp/GUI_UserInterface/GUI_UserInterface.java +++ b/Programmierung2/src/TodoListApp/GUI_UserInterface/GUI_UserInterface.java @@ -13,6 +13,7 @@ public class GUI_UserInterface extends JFrame { private JButton addTask; private JButton zeigeAlleTasks; private JTextArea AllTasksArea; + private JButton clear; public GUI_UserInterface() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE ); @@ -57,6 +58,10 @@ public class GUI_UserInterface extends JFrame { zeigeAlleTasks.setBounds(193, 506, 159, 29); panel.add(zeigeAlleTasks); + clear = new JButton("Clear TextArea"); + clear.setBounds(384, 506, 159, 29); + panel.add(clear); + setLocationRelativeTo(null); this.setVisible(true); } @@ -76,6 +81,14 @@ public class GUI_UserInterface extends JFrame { public void setAllTasksArea(JTextArea allTasksArea) { AllTasksArea = allTasksArea; } + public void showInfo(String message) { + JOptionPane.showMessageDialog(null, message, "Studen angemeldet", JOptionPane.INFORMATION_MESSAGE); + } + + public JButton getClear() { + return clear; + } + } diff --git a/Programmierung2/src/TodoListApp/GUI_UserInterface/GUI_addTask.java b/Programmierung2/src/TodoListApp/GUI_UserInterface/GUI_addTask.java index fee6f93..9257e72 100644 --- a/Programmierung2/src/TodoListApp/GUI_UserInterface/GUI_addTask.java +++ b/Programmierung2/src/TodoListApp/GUI_UserInterface/GUI_addTask.java @@ -5,7 +5,6 @@ import java.awt.*; import javax.swing.*; import javax.swing.border.EmptyBorder; import javax.swing.border.LineBorder; -import javax.swing.table.DefaultTableModel; import TodoListApp.Domain.*; @@ -97,6 +96,7 @@ public class GUI_addTask extends JFrame { submitTask = new JButton("Submit"); submitTask.setBounds(24, 323, 123, 23); panel.add(submitTask); + setLocationRelativeTo(null); } public void zeigeFensterAddTask() { diff --git a/Programmierung2/src/TodoListApp/GUI_UserInterface/Userverwalter.java b/Programmierung2/src/TodoListApp/GUI_UserInterface/Userverwalter.java index 235947b..949917d 100644 --- a/Programmierung2/src/TodoListApp/GUI_UserInterface/Userverwalter.java +++ b/Programmierung2/src/TodoListApp/GUI_UserInterface/Userverwalter.java @@ -4,18 +4,19 @@ import TodoListApp.Domain.ProgrammSystem; import TodoListApp.Domain.KlassenException.FalscheEinagebException; public class Userverwalter { - + private ProgrammSystem system; private GUI_UserInterface user; private GUI_addTask taskHinziFuegenFenster; - + private int index = 0; + public Userverwalter() { - this.system = new ProgrammSystem(); - this.user = new GUI_UserInterface(); - this.taskHinziFuegenFenster = new GUI_addTask(); - - // Buttons User: - user.getAddTask().addActionListener(e -> { + 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) { @@ -23,8 +24,8 @@ public class Userverwalter { e1.printStackTrace(); } }); - - taskHinziFuegenFenster.getSubmitTask().addActionListener(e -> { + + taskHinziFuegenFenster.getSubmitTask().addActionListener(e -> { try { addTask(); } catch (FalscheEinagebException e1) { @@ -32,19 +33,19 @@ public class Userverwalter { e1.printStackTrace(); } }); - - user.getZeigeAlleTasks().addActionListener(e -> showAllTasks()); - + + user.getZeigeAlleTasks().addActionListener(e -> showAllTasks()); + user.getClear().addActionListener(e -> clearTextArea()); + } - + 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; @@ -56,16 +57,30 @@ public class Userverwalter { 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"); + if (system.showAllTasks().size() == 0) + user.showInfo("Momentan befinden sich keine Taks"); + + else if (index >= system.showAllTasks().size()) + user.showInfo("Es gibt keine Tasks mehr!"); + + else { + while (index < system.showAllTasks().size()) { + user.getAllTasksArea().append(system.showAllTasks().get(index++)); + user.getAllTasksArea().append("\n"); + } } + + } + + public void clearTextArea() { + user.getAllTasksArea().setText(""); + index = 0; } }