OOP-Projects-Java

Log | Files | Refs | README

commit fa8b2fd35311e27b4b4a9714065db04c2f49e0c0
parent 1f216e4d4bc83533ce9a433e5bc8c20d18c0fcac
Author: William Lindholm <william_lindholm@outlook.com>
Date:   Mon, 13 Feb 2023 15:08:30 +0100

Added sorting dialogue box

Diffstat:
MOOP2023_a22willi_a21liltr_assignment2/src/assignment2/GUI.java | 23++++++++++++++++-------
1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/OOP2023_a22willi_a21liltr_assignment2/src/assignment2/GUI.java b/OOP2023_a22willi_a21liltr_assignment2/src/assignment2/GUI.java @@ -3,7 +3,6 @@ package assignment2; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.event.*; -import java.util.ArrayList; import java.util.HashMap; import java.util.Map; @@ -35,10 +34,10 @@ public class GUI implements ActionListener { menu = new JPanel(); menu.setSize(menuBar); - createButton("study", "New StudyTask"); - createButton("home", "New HomeTask"); - createButton("work", "New WorkTask"); - createButton("sort", "Sort"); + createMenuButton("study", "New StudyTask"); + createMenuButton("home", "New HomeTask"); + createMenuButton("work", "New WorkTask"); + createMenuButton("sort", "Sort"); frame.add(menu, BorderLayout.NORTH); @@ -55,11 +54,21 @@ public class GUI implements ActionListener { * @param key Used for distinguishing buttons from each other, unique "name" * @param btnText Button text */ - private void createButton(String key, String btnText) { + private void createMenuButton(String key, String btnText) { buttons.put(key, new JButton(btnText)); //Create new button and add to Map using key value buttons.get(key).addActionListener(this); //add ActionListener to button menu.add(buttons.get(key)); // add button to GUI } + + private String selectSort() { + String[] sortingOptions = {"Alphabetical", "Type", "Completed"}; + + Object selected = JOptionPane.showInputDialog(null, "Choose sorting type", "Selection", JOptionPane.DEFAULT_OPTION, null, sortingOptions, "0"); + if ( selected != null ){//null if the user cancels. + return selected.toString(); + } + return ""; + } @Override public void actionPerformed(ActionEvent e) { @@ -69,7 +78,7 @@ public class GUI implements ActionListener { } if (e.getSource().equals(buttons.get("sort"))) { - taskHandler.Sort(); + taskHandler.Sort(selectSort()); } else { Task t;