commit f39421043a099935924a020848c553faa0dc381c parent a214d05e0f67e2e110a859013a80af184af70b1b Author: TranLili <tranlili96@gmail.com> Date: Wed, 25 Jan 2023 15:23:59 +0100 Made it work LOL Diffstat:
10 files changed, 24 insertions(+), 428 deletions(-)
diff --git a/OOP2023_a22willi_a21liltr_assignment2/.classpath b/OOP2023_a22willi_a21liltr_assignment2/.classpath @@ -6,5 +6,10 @@ </attributes> </classpathentry> <classpathentry kind="src" path="src"/> + <classpathentry kind="lib" path="src/ToDo.jar"> + <attributes> + <attribute name="module" value="true"/> + </attributes> + </classpathentry> <classpathentry kind="output" path="bin"/> </classpath> diff --git a/OOP2023_a22willi_a21liltr_assignment2/src/Main.java b/OOP2023_a22willi_a21liltr_assignment2/src/Main.java @@ -1,8 +0,0 @@ - -public class Main { - - public static void main(String[] args) { - //omg it works! - } - -} diff --git a/OOP2023_a22willi_a21liltr_assignment2/src/ToDo.jar b/OOP2023_a22willi_a21liltr_assignment2/src/ToDo.jar Binary files differ. diff --git a/OOP2023_a22willi_a21liltr_assignment2/src/assignment2/Main.java b/OOP2023_a22willi_a21liltr_assignment2/src/assignment2/Main.java @@ -0,0 +1,18 @@ +package assignment2; + +import javax.swing.JCheckBox; +import javax.swing.JFrame; + +public class Main { + + public static void main(String[] args) { + System.out.println("Hej Världen!"); + + JFrame frame = new JFrame(); + frame.setSize(400, 200); + frame.add(new JCheckBox()); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setVisible(true); + } + +} diff --git a/OOP2023_a22willi_a21liltr_assignment2/src/it401g/todo/HomeTask.java b/OOP2023_a22willi_a21liltr_assignment2/src/it401g/todo/HomeTask.java @@ -1,103 +0,0 @@ -package se.his.it401g.todo; - -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.Dimension; - -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JTextField; -import javax.swing.border.TitledBorder; - -/** - * Implements a simple home task type, following the Task.java interface class. - * - * This file licensed under the <a href="https://creativecommons.org/licenses/by/4.0/">Creative Commons (CC) BY 4.0 license</a>. - * - * @author Dr. Erik Billing, University of Skovde - * - */ -public class HomeTask extends JPanel implements Task { - - /** - * The editable text field. - */ - private JTextField text; - - /** - * The non editable text label. - */ - private JLabel textLabel; - - /** - * Check box holding the completion status. - */ - JCheckBox completed = new JCheckBox(); - - /** - * The task listener used for reporting changes to the main application. - */ - private TaskListener listener; - - /** - * This is the constructor for the task, initiating the GUI component for the task. Several listeners are used to react to various events in the GUI. - */ - public HomeTask() { - super(new BorderLayout()); - this.text = new JTextField("New task",20); - this.textLabel = new JLabel(); - this.textLabel.setVisible(false); - JPanel center = new JPanel(); - center.add(text); - center.add(textLabel); - add(center); - - TaskInputListener inputListener = new TaskInputListener(this, text, textLabel); - this.text.addKeyListener(inputListener); - this.textLabel.addMouseListener(inputListener); - - JButton remove = new JButton("Remove"); - add(remove,BorderLayout.EAST); - remove.addActionListener(inputListener); - - add(completed,BorderLayout.WEST); - completed.addItemListener(inputListener); - - setMaximumSize(new Dimension(1000,50)); - setBorder(new TitledBorder(getTaskType())); - } - - @Override - public String getText() { - return text.getText(); - } - - @Override - public String getTaskType() { - return "Home"; - } - - @Override - public void setTaskListener(TaskListener t) { - listener = t; - } - - @Override - public TaskListener getTaskListener() { - return listener; - } - - @Override - public boolean isComplete() { - return completed.isSelected(); - } - - @Override - public Component getGuiComponent() { - // Since this class extends JPanel, it is itself a GUI component, and thus we can return "this". - return this; - } - -} diff --git a/OOP2023_a22willi_a21liltr_assignment2/src/it401g/todo/StudyTask.java b/OOP2023_a22willi_a21liltr_assignment2/src/it401g/todo/StudyTask.java @@ -1,104 +0,0 @@ -package se.his.it401g.todo; - - -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.Dimension; - -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JTextField; -import javax.swing.border.TitledBorder; - -/** - * Implements a simple study task type, following the Task.java interface class. - * - * This file licensed under the <a href="https://creativecommons.org/licenses/by/4.0/">Creative Commons (CC) BY 4.0 license</a>. - * - * @author Dr. Erik Billing, University of Skovde - * - */ -public class StudyTask extends JPanel implements Task { - - /** - * The editable text field. - */ - private JTextField text; - - /** - * The non editable text label. - */ - private JLabel textLabel; - - /** - * Check box holding the completion status. - */ - JCheckBox completed = new JCheckBox(); - - /** - * The task listener used for reporting changes to the main application. - */ - private TaskListener listener; - - /** - * This is the constructor for the task, initiating the GUI component for the task. Several listeners are used to react to various events in the GUI. - */ - public StudyTask() { - super(new BorderLayout()); - this.text = new JTextField("New task",20); - this.textLabel = new JLabel(); - this.textLabel.setVisible(false); - JPanel center = new JPanel(); - center.add(text); - center.add(textLabel); - add(center); - - TaskInputListener inputListener = new TaskInputListener(this, text, textLabel); - this.text.addKeyListener(inputListener); - this.textLabel.addMouseListener(inputListener); - - JButton remove = new JButton("Remove"); - add(remove,BorderLayout.EAST); - remove.addActionListener(inputListener); - - add(completed,BorderLayout.WEST); - completed.addItemListener(inputListener); - - setMaximumSize(new Dimension(1000,50)); - setBorder(new TitledBorder(getTaskType())); - } - - @Override - public String getText() { - return text.getText(); - } - - @Override - public String getTaskType() { - return "Study"; - } - - @Override - public void setTaskListener(TaskListener t) { - listener = t; - } - - @Override - public TaskListener getTaskListener() { - return listener; - } - - @Override - public boolean isComplete() { - return completed.isSelected(); - } - - @Override - public Component getGuiComponent() { - // Since this class extends JPanel, it is itself a GUI component, and thus we can return "this". - return this; - } - -} diff --git a/OOP2023_a22willi_a21liltr_assignment2/src/it401g/todo/Task.java b/OOP2023_a22willi_a21liltr_assignment2/src/it401g/todo/Task.java @@ -1,46 +0,0 @@ -package se.his.it401g.todo; - - -import java.awt.Component; - -/** - * This interface class represents a task type. All communication between individual task objects and the main application should be made using method specified here, or in the related interface TaskListener. - * - * This file licensed under the <a href="https://creativecommons.org/licenses/by/4.0/">Creative Commons (CC) BY 4.0 license</a>. - * - * @author Dr. Erik Billing, University of Skovde - * - */ -public interface Task { - - /** - * @return a short description/title of the task - */ - public String getText(); - - /** - * @return the name of the task type, e.g., "Work" for work related tasks. - */ - public String getTaskType(); - - /** - * Sets the task listener on which this task reports various events. - * @param t the listener to use. - */ - public void setTaskListener(TaskListener t); - - /** - * @return the task listener currently used. - */ - public TaskListener getTaskListener(); - - /** - * @return true if the task has status "complete", otherwise false. - */ - public boolean isComplete(); - - /** - * @return the graphical user interface component representing this task. - */ - public Component getGuiComponent(); -} diff --git a/OOP2023_a22willi_a21liltr_assignment2/src/it401g/todo/TaskInputListener.java b/OOP2023_a22willi_a21liltr_assignment2/src/it401g/todo/TaskInputListener.java @@ -1,112 +0,0 @@ -package se.his.it401g.todo; - -import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.awt.event.ActionListener; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; - -import javax.swing.JLabel; -import javax.swing.JTextField; - -/** - * This class implements listeners for different input events on the task GUI. You may use this class for your custom task type, or create another listener. - * - * For example, when you change the test of a task and press enter, the keyPress method is called to switch from the input field to a JLabel displaying the text. - * - * This file licensed under the <a href="https://creativecommons.org/licenses/by/4.0/">Creative Commons (CC) BY 4.0 license</a>. - * - * @author Dr. Erik Billing, University of Skovde - * - */ -public class TaskInputListener implements KeyListener, MouseListener, ActionListener, ItemListener { - - private Task task; - private JLabel textLabel; - private JTextField text; - - /** - * @param task is the task object that this listener is responsible for. - * @param text is the text input field that this listener receives events from. - * @param textLabel is the text label that this listener receives events from. - */ - public TaskInputListener(Task task, JTextField text, JLabel textLabel) { - this.task = task; - this.text = text; - this.textLabel = textLabel; - } - - @Override - public void mouseClicked(MouseEvent e) { - // TODO Auto-generated method stub - - } - - @Override - public void mousePressed(MouseEvent e) { - textLabel.setVisible(false); - text.setVisible(true); - } - - @Override - public void mouseReleased(MouseEvent e) { - // TODO Auto-generated method stub - - } - - @Override - public void mouseEntered(MouseEvent e) { - // TODO Auto-generated method stub - - } - - @Override - public void mouseExited(MouseEvent e) { - // TODO Auto-generated method stub - - } - - @Override - public void keyTyped(KeyEvent e) { - // TODO Auto-generated method stub - - } - - @Override - public void keyPressed(KeyEvent e) { - if (e.getKeyCode() == KeyEvent.VK_ENTER) { - text.setVisible(false); - textLabel.setText(text.getText()); - textLabel.setVisible(true); - TaskListener listener = task.getTaskListener(); - if (listener != null) listener.taskChanged(task); - } - - } - - @Override - public void keyReleased(KeyEvent e) { - // TODO Auto-generated method stub - - } - - @Override - public void actionPerformed(ActionEvent e) { - TaskListener listener = task.getTaskListener(); - if (listener != null) listener.taskRemoved(task); - } - - @Override - public void itemStateChanged(ItemEvent e) { - TaskListener listener = task.getTaskListener(); - if (e.getStateChange() == 1 && listener != null) { - listener.taskCompleted(task); - } else if (listener != null) { - listener.taskUncompleted(task); - } - } - -} diff --git a/OOP2023_a22willi_a21liltr_assignment2/src/it401g/todo/TaskListener.java b/OOP2023_a22willi_a21liltr_assignment2/src/it401g/todo/TaskListener.java @@ -1,48 +0,0 @@ -package se.his.it401g.todo; - - -/** - * This is a listener interface where task objects can report changes to the main application. - * - * This file licensed under the <a href="https://creativecommons.org/licenses/by/4.0/">Creative Commons (CC) BY 4.0 license</a>. - * - * @author Dr. Erik Billing, University of Skovde - * - */ -public interface TaskListener { - /** - * Called when a task is modified. - * - * @param t is the modified task - */ - public void taskChanged(Task t); - - /** - * Called when a task is completed. - * - * @param t is the completed task - */ - public void taskCompleted(Task t); - - /** - * Called when completion status is removed. - * - * @param t is the modified task - */ - public void taskUncompleted(Task t); - - /** - * Called when a task is created. - * - * @param t is the new task - */ - public void taskCreated(Task t); - - /** - * Called when a task is removed. - * - * @param t is the removed task - */ - public void taskRemoved(Task t); - -} diff --git a/OOP2023_a22willi_a21liltr_assignment2/src/module-info.java b/OOP2023_a22willi_a21liltr_assignment2/src/module-info.java @@ -1,13 +1,7 @@ -/** - * - */ -/** - * @author Willi - * - */ module OOP2023_a22willi_a21liltr_assignment2 { requires java.base; requires java.se; requires it401g.todo; + requires java.desktop; exports assignment2; } \ No newline at end of file