From c2089e5a3e604424c7cd00bbddcb03731ff5a0ea Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Sun, 21 Feb 2016 15:42:14 -0500 Subject: Added new control and some commenting --- .../src/main/java/bjc/utils/gui/SimpleDialogs.java | 92 +++++++++++----------- 1 file changed, 46 insertions(+), 46 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/gui/SimpleDialogs.java') diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleDialogs.java b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleDialogs.java index 85b9fa9..ea48977 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleDialogs.java +++ b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleDialogs.java @@ -48,6 +48,52 @@ public class SimpleDialogs { } , Integer::parseInt); } + /** + * Asks the user to pick an option from a series of choices. + * + * @param parent + * The parent frame for this dialog + * @param title + * The title of this dialog + * @param question + * The question being asked + * @param choices + * The available choices for the question + * @return The choice the user picked, or null if they didn't pick one + */ + @SuppressWarnings("unchecked") + public static E getChoice(Frame parent, String title, + String question, E... choices) { + JDialog jd = new JDialog(parent, title, true); + jd.setLayout(new VLayout(2)); + + JPanel questionPane = new JPanel(); + + JLabel questionText = new JLabel(question); + JComboBox questionChoices = new JComboBox<>(choices); + + questionPane.add(questionText); + questionPane.add(questionChoices); + + JPanel buttonPane = new JPanel(); + + JButton okButton = new JButton("Ok"); + okButton.addActionListener(e -> jd.dispose()); + JButton cancelButton = new JButton("Cancel"); + cancelButton.addActionListener(e -> jd.dispose()); + + buttonPane.add(cancelButton); + buttonPane.add(okButton); + + jd.add(questionPane); + jd.add(buttonPane); + + jd.pack(); + jd.setVisible(true); + + return (E) questionChoices.getSelectedItem(); + } + /** * Get a integer from the user * @@ -151,52 +197,6 @@ public class SimpleDialogs { return (res == JOptionPane.YES_OPTION ? true : false); } - /** - * Asks the user to pick an option from a series of choices. - * - * @param parent - * The parent frame for this dialog - * @param title - * The title of this dialog - * @param question - * The question being asked - * @param choices - * The availible choices for the question - * @return The choice the user picked, or null if they didn't pick one - */ - @SuppressWarnings("unchecked") - public static E getChoice(Frame parent, String title, - String question, E... choices) { - JDialog jd = new JDialog(parent, title, true); - jd.setLayout(new VLayout(2)); - - JPanel questionPane = new JPanel(); - - JLabel questionText = new JLabel(question); - JComboBox questionChoices = new JComboBox<>(choices); - - questionPane.add(questionText); - questionPane.add(questionChoices); - - JPanel buttonPane = new JPanel(); - - JButton okButton = new JButton("Ok"); - okButton.addActionListener(e -> jd.dispose()); - JButton cancelButton = new JButton("Cancel"); - cancelButton.addActionListener(e -> jd.dispose()); - - buttonPane.add(cancelButton); - buttonPane.add(okButton); - - jd.add(questionPane); - jd.add(buttonPane); - - jd.pack(); - jd.setVisible(true); - - return (E) questionChoices.getSelectedItem(); - } - /** * Show a error message to the user * -- cgit v1.2.3