tasks Zeigen

master
3009594 2024-10-11 00:51:42 +02:00
parent 3826d33c6b
commit 509f9372dd
3 changed files with 52 additions and 24 deletions

View File

@ -13,6 +13,7 @@ public class GUI_UserInterface extends JFrame {
private JButton addTask; private JButton addTask;
private JButton zeigeAlleTasks; private JButton zeigeAlleTasks;
private JTextArea AllTasksArea; private JTextArea AllTasksArea;
private JButton clear;
public GUI_UserInterface() { public GUI_UserInterface() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE ); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
@ -57,6 +58,10 @@ public class GUI_UserInterface extends JFrame {
zeigeAlleTasks.setBounds(193, 506, 159, 29); zeigeAlleTasks.setBounds(193, 506, 159, 29);
panel.add(zeigeAlleTasks); panel.add(zeigeAlleTasks);
clear = new JButton("Clear TextArea");
clear.setBounds(384, 506, 159, 29);
panel.add(clear);
setLocationRelativeTo(null);
this.setVisible(true); this.setVisible(true);
} }
@ -76,6 +81,14 @@ public class GUI_UserInterface extends JFrame {
public void setAllTasksArea(JTextArea allTasksArea) { public void setAllTasksArea(JTextArea allTasksArea) {
AllTasksArea = allTasksArea; AllTasksArea = allTasksArea;
} }
public void showInfo(String message) {
JOptionPane.showMessageDialog(null, message, "Studen angemeldet", JOptionPane.INFORMATION_MESSAGE);
}
public JButton getClear() {
return clear;
}
} }

View File

@ -5,7 +5,6 @@ import java.awt.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.border.EmptyBorder; import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder; import javax.swing.border.LineBorder;
import javax.swing.table.DefaultTableModel;
import TodoListApp.Domain.*; import TodoListApp.Domain.*;
@ -97,6 +96,7 @@ public class GUI_addTask extends JFrame {
submitTask = new JButton("Submit"); submitTask = new JButton("Submit");
submitTask.setBounds(24, 323, 123, 23); submitTask.setBounds(24, 323, 123, 23);
panel.add(submitTask); panel.add(submitTask);
setLocationRelativeTo(null);
} }
public void zeigeFensterAddTask() { public void zeigeFensterAddTask() {

View File

@ -4,18 +4,19 @@ import TodoListApp.Domain.ProgrammSystem;
import TodoListApp.Domain.KlassenException.FalscheEinagebException; import TodoListApp.Domain.KlassenException.FalscheEinagebException;
public class Userverwalter { public class Userverwalter {
private ProgrammSystem system; private ProgrammSystem system;
private GUI_UserInterface user; private GUI_UserInterface user;
private GUI_addTask taskHinziFuegenFenster; private GUI_addTask taskHinziFuegenFenster;
private int index = 0;
public Userverwalter() { public Userverwalter() {
this.system = new ProgrammSystem(); this.system = new ProgrammSystem();
this.user = new GUI_UserInterface(); this.user = new GUI_UserInterface();
this.taskHinziFuegenFenster = new GUI_addTask(); this.taskHinziFuegenFenster = new GUI_addTask();
// Buttons User: // Buttons User:
user.getAddTask().addActionListener(e -> { user.getAddTask().addActionListener(e -> {
try { try {
zeigeFenster(); zeigeFenster();
} catch (FalscheEinagebException e1) { } catch (FalscheEinagebException e1) {
@ -23,8 +24,8 @@ public class Userverwalter {
e1.printStackTrace(); e1.printStackTrace();
} }
}); });
taskHinziFuegenFenster.getSubmitTask().addActionListener(e -> { taskHinziFuegenFenster.getSubmitTask().addActionListener(e -> {
try { try {
addTask(); addTask();
} catch (FalscheEinagebException e1) { } catch (FalscheEinagebException e1) {
@ -32,19 +33,19 @@ public class Userverwalter {
e1.printStackTrace(); e1.printStackTrace();
} }
}); });
user.getZeigeAlleTasks().addActionListener(e -> showAllTasks()); user.getZeigeAlleTasks().addActionListener(e -> showAllTasks());
user.getClear().addActionListener(e -> clearTextArea());
} }
public void zeigeFenster() throws FalscheEinagebException { public void zeigeFenster() throws FalscheEinagebException {
taskHinziFuegenFenster.zeigeFensterAddTask(); taskHinziFuegenFenster.zeigeFensterAddTask();
} }
public void addTask() throws FalscheEinagebException { public void addTask() throws FalscheEinagebException {
String title = taskHinziFuegenFenster.getTasktitle().getText(); String title = taskHinziFuegenFenster.getTasktitle().getText();
String beschreibung = taskHinziFuegenFenster.getTaskBeschreibung().getText(); String beschreibung = taskHinziFuegenFenster.getTaskBeschreibung().getText();
String priorität; String priorität;
@ -56,16 +57,30 @@ public class Userverwalter {
priorität = "niedrig"; priorität = "niedrig";
else else
priorität = "niedrig"; priorität = "niedrig";
system.addTask(title, beschreibung, priorität); system.addTask(title, beschreibung, priorität);
taskHinziFuegenFenster.resetButtons(); taskHinziFuegenFenster.resetButtons();
taskHinziFuegenFenster.showInfo("Neuer Task wurde Erfolgreich hinzugefügt!"); taskHinziFuegenFenster.showInfo("Neuer Task wurde Erfolgreich hinzugefügt!");
} }
public void showAllTasks() { public void showAllTasks() {
for (String s : system.showAllTasks()) { if (system.showAllTasks().size() == 0)
user.getAllTasksArea().append(s); user.showInfo("Momentan befinden sich keine Taks");
user.getAllTasksArea().append("\n");
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;
} }
} }