List of usage examples for javax.swing JOptionPane showInputDialog
public static String showInputDialog(Component parentComponent, Object message, String title, int messageType) throws HeadlessException
parentComponent
with the dialog having the title title
and message type messageType
. From source file:io.github.jeremgamer.editor.panels.Others.java
public Others(final JFrame frame, final OtherPanel op, final PanelSave ps) { this.frame = frame; this.setBorder(BorderFactory.createTitledBorder("")); JButton add = null;//from w w w .ja v a 2 s. c o m try { add = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("add.png")))); } catch (IOException e) { e.printStackTrace(); } add.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { JOptionPane jop = new JOptionPane(); @SuppressWarnings("static-access") String name = jop.showInputDialog((JFrame) SwingUtilities.windowForComponent(otherList), "Nommez le composant :", "Crer un composant", JOptionPane.QUESTION_MESSAGE); if (name != null) { for (int i = 0; i < data.getSize(); i++) { if (data.get(i).equals(name)) { name += "1"; } } data.addElement(name); new OtherSave(name); ActionPanel.updateLists(); PanelsPanel.updateLists(); } } catch (IOException e) { e.printStackTrace(); } } }); JButton remove = null; try { remove = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); } catch (IOException e) { e.printStackTrace(); } remove.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { if (otherList.getSelectedValue() != null) { File file = new File("projects/" + Editor.getProjectName() + "/others/" + otherList.getSelectedValue() + ".rbd"); JOptionPane jop = new JOptionPane(); @SuppressWarnings("static-access") int option = jop.showConfirmDialog((JFrame) SwingUtilities.windowForComponent(otherList), "tes-vous sr de vouloir supprimer ce composant?", "Avertissement", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (option == JOptionPane.OK_OPTION) { File dir = new File("projects/" + Editor.getProjectName() + "/panels"); for (File f : FileUtils.listFilesAndDirs(dir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)) { if (!f.isDirectory()) { try { ps.load(f); } catch (IOException e) { e.printStackTrace(); } OtherSave os = new OtherSave(); try { os.load(file); } catch (IOException e1) { e1.printStackTrace(); } String type = null; switch (os.getInt("type")) { case 0: type = "Zone de saisie"; break; case 1: type = "Zone de saisie de mot de passe"; break; case 2: type = "Zone de saisie (Grande)"; break; case 3: type = "Case cocher"; break; case 4: type = "Menu droulant"; break; case 5: type = "Barre de progression"; break; case 6: type = "Slider"; break; case 7: type = "Spinner"; break; } for (String section : ps.getSectionsContaining( otherList.getSelectedValue() + " (" + type + ")")) { ps.removeSection(section); try { ps.save(f); } catch (IOException e) { e.printStackTrace(); } } } } if (otherList.getSelectedValue().equals(op.getFileName())) { op.setFileName(""); } op.hide(); file.delete(); data.remove(otherList.getSelectedIndex()); ActionPanel.updateLists(); OtherPanel.updateLists(); PanelsPanel.updateLists(); } } } catch (NullPointerException npe) { npe.printStackTrace(); } } }); JPanel buttons = new JPanel(); buttons.setLayout(new BoxLayout(buttons, BoxLayout.LINE_AXIS)); buttons.add(add); buttons.add(remove); updateList(); otherList.addMouseListener(new MouseAdapter() { @SuppressWarnings("unchecked") public void mouseClicked(MouseEvent evt) { JList<String> list = (JList<String>) evt.getSource(); if (evt.getClickCount() == 2) { int index = list.locationToIndex(evt.getPoint()); if (isOpen == false) { op.show(); op.load(new File("projects/" + Editor.getProjectName() + "/others/" + list.getModel().getElementAt(index) + ".rbd")); previousSelection = list.getSelectedValue(); isOpen = true; } else { try { if (previousSelection.equals(list.getModel().getElementAt(index))) { op.hide(); previousSelection = list.getSelectedValue(); list.clearSelection(); isOpen = false; } else { op.hideThenShow(); previousSelection = list.getSelectedValue(); op.load(new File("projects/" + Editor.getProjectName() + "/others/" + list.getModel().getElementAt(index) + ".rbd")); } } catch (NullPointerException npe) { op.hide(); list.clearSelection(); } } } else if (evt.getClickCount() == 3) { int index = list.locationToIndex(evt.getPoint()); if (isOpen == false) { op.show(); op.load(new File("projects/" + Editor.getProjectName() + "/others/" + list.getModel().getElementAt(index) + ".rbd")); previousSelection = list.getSelectedValue(); isOpen = true; } else { try { if (previousSelection.equals(list.getModel().getElementAt(index))) { op.hide(); previousSelection = list.getSelectedValue(); list.clearSelection(); isOpen = false; } else { op.hideThenShow(); previousSelection = list.getSelectedValue(); op.load(new File("projects/" + Editor.getProjectName() + "/others/" + list.getModel().getElementAt(index) + ".rbd")); } } catch (NullPointerException npe) { op.hide(); list.clearSelection(); } } } } }); JScrollPane listPane = new JScrollPane(otherList); listPane.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED); this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); this.add(buttons); this.add(listPane); OtherPanel.updateLists(); }
From source file:oct.util.Util.java
public static OCT getOCT(BufferedImage octImage, OCTAnalysisUI octAnalysisUI, String octFileName) { boolean exit = false; //ask the user for the x-scale double xscale = 0; do {/* w w w . ja va 2 s . co m*/ String res = JOptionPane.showInputDialog(octAnalysisUI, "Enter OCT X-axis scale (microns per pixel):", "X-Scale input", JOptionPane.QUESTION_MESSAGE); if (!(res == null || res.isEmpty())) { xscale = Util.parseNumberFromInput(res); } if (res == null || res.isEmpty() || xscale <= 0) { exit = JOptionPane.showConfirmDialog(octAnalysisUI, "Bad scale value. Would you like to enter it again?\nNOTE: OCT won't load without the scale data.", "Input Error", JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE) != JOptionPane.YES_OPTION; } } while (!exit && xscale <= 0); if (exit) { return null; } //ask the user for the y-scale double yscale = 0; do { String res = JOptionPane.showInputDialog(octAnalysisUI, "Enter OCT Y-axis scale (microns per pixel):", "Y-Scale input", JOptionPane.QUESTION_MESSAGE); if (!(res == null || res.isEmpty())) { yscale = Util.parseNumberFromInput(res); } if (res == null || res.isEmpty() || yscale <= 0) { exit = JOptionPane.showConfirmDialog(octAnalysisUI, "Bad scale value. Would you like to enter it again?\nNOTE: OCT won't load without the scale data.", "Input Error", JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE) != JOptionPane.YES_OPTION; } } while (!exit && yscale <= 0); if (exit) { return null; } //store values and return OCT object OCTAnalysisManager octMngr = OCTAnalysisManager.getInstance(); octMngr.setXscale(xscale); octMngr.setYscale(yscale); return new OCT(octImage, octFileName); }
From source file:net.itransformers.topologyviewer.menu.handlers.graphTools.searchMenuHandlers.SearchByIpMenuHandler.java
@Override public void actionPerformed(ActionEvent e) { // Map<String, Map<String, GraphMLMetadata<G>>> test1 = graphmlLoader(); // String key = JOptionPane.showInputDialog(frame, "Choose IP", JOptionPane.QUESTION_MESSAGE); final String ip = JOptionPane.showInputDialog(frame, "Enter IP", "Value", JOptionPane.QUESTION_MESSAGE); GraphViewerPanel viewerPanel = (GraphViewerPanel) frame.getTabbedPane().getSelectedComponent(); Set<String> foundVertexes; foundVertexes = viewerPanel.FindNodeByKey("RoutePrefixes", new Object() { @Override//from www .j ava2s. c o m public boolean equals(Object obj) { String s = (String) obj; String[] ipRanges = s.split(","); for (String ipRangeNotTrimmed : ipRanges) { String ipRange = ipRangeNotTrimmed.trim(); if (ipRange.equals("") || ipRange.equals("0.0.0.0/0")) continue; try { SubnetUtils subnet = new SubnetUtils(ipRange); if (subnet.getInfo().isInRange(ip)) { return true; } } catch (IllegalArgumentException iae) { logger.error("Can not parse ip or ip range:" + ipRange + ", ip:" + ip); System.out.println("Can not parse ip or ip range:" + ipRange + ", ip:" + ip); iae.printStackTrace(); continue; } } return false; } }); if (!foundVertexes.isEmpty()) { Iterator it = foundVertexes.iterator(); if (foundVertexes.size() == 1) { Object element = it.next(); System.out.println("Redrawing around " + element.toString()); viewerPanel.SetPickedState(element.toString()); viewerPanel.Animator(element.toString()); } else { JOptionPane.showMessageDialog(frame, "Multiple Nodes with ip " + ip + " found :\n" + foundVertexes, "Error", JOptionPane.ERROR_MESSAGE); } } else { JOptionPane.showMessageDialog(frame, "Can not find node with ip " + ip, "Error", JOptionPane.ERROR_MESSAGE); } }
From source file:me.mayo.telnetkek.player.PlayerCommandEntry.java
public String buildOutput(PlayerInfo player, boolean useReasonPrompt) { String output = StringUtils.replaceEach(getFormat(), new String[] { "$TARGET_NAME", "$TARGET_IP", "$TARGET_UUID", }, new String[] { player.getName(), player.getIp(), player.getUuid() }); if (useReasonPrompt && output.contains("$REASON")) { final String reason = StringUtils.trimToEmpty(JOptionPane.showInputDialog(null, "Input reason:\n" + output, "Input Reason", JOptionPane.PLAIN_MESSAGE)); output = StringUtils.replace(output, "$REASON", reason); }//from ww w . ja v a 2 s . c o m return StringUtils.trimToEmpty(output); }
From source file:de.dakror.virtualhub.client.dialog.ChooseCatalogDialog.java
public static void show(ClientFrame frame, final JSONArray data) { final JDialog dialog = new JDialog(frame, "Katalog whlen", true); dialog.setSize(400, 300);//from ww w . j ava 2s . c o m dialog.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); dialog.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { Client.currentClient.disconnect(); System.exit(0); } }); JPanel contentPane = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0)); dialog.setContentPane(contentPane); DefaultListModel dlm = new DefaultListModel(); for (int i = 0; i < data.length(); i++) { try { dlm.addElement(data.getJSONObject(i).getString("name")); } catch (JSONException e) { e.printStackTrace(); } } final JList catalogs = new JList(dlm); catalogs.setDragEnabled(false); catalogs.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane jsp = new JScrollPane(catalogs, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); jsp.setPreferredSize(new Dimension(396, 200)); contentPane.add(jsp); JPanel mods = new JPanel(new GridLayout(1, 2)); mods.setPreferredSize(new Dimension(50, 22)); mods.add(new JButton(new AbstractAction("+") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { String name = JOptionPane.showInputDialog(dialog, "Bitte geben Sie den Namen des neuen Katalogs ein.", "Katalog hinzufgen", JOptionPane.PLAIN_MESSAGE); if (name != null && name.length() > 0) { DefaultListModel dlm = (DefaultListModel) catalogs.getModel(); for (int i = 0; i < dlm.getSize(); i++) { if (dlm.get(i).toString().equals(name)) { JOptionPane.showMessageDialog(dialog, "Es existert bereits ein Katalog mit diesem Namen!", "Katalog bereits vorhanden!", JOptionPane.ERROR_MESSAGE); actionPerformed(e); return; } } try { dlm.addElement(name); JSONObject o = new JSONObject(); o.put("name", name); o.put("sources", new JSONArray()); o.put("tags", new JSONArray()); data.put(o); Client.currentClient.sendPacket(new Packet0Catalogs(data)); } catch (Exception e1) { e1.printStackTrace(); } } } })); mods.add(new JButton(new AbstractAction("-") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { if (catalogs.getSelectedIndex() != -1) { if (JOptionPane.showConfirmDialog(dialog, "Sind Sie sicher, dass Sie diesen\r\nKatalog unwiderruflich lschen wollen?", "Katalog lschen", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { DefaultListModel dlm = (DefaultListModel) catalogs.getModel(); data.remove(catalogs.getSelectedIndex()); dlm.remove(catalogs.getSelectedIndex()); try { Client.currentClient.sendPacket(new Packet0Catalogs(data)); } catch (IOException e1) { e1.printStackTrace(); } } } } })); contentPane.add(mods); JLabel l = new JLabel(""); l.setPreferredSize(new Dimension(396, 14)); contentPane.add(l); JSeparator sep = new JSeparator(JSeparator.HORIZONTAL); sep.setPreferredSize(new Dimension(396, 10)); contentPane.add(sep); JPanel buttons = new JPanel(new GridLayout(1, 2)); buttons.setPreferredSize(new Dimension(396, 22)); buttons.add(new JButton(new AbstractAction("Abbrechen") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { Client.currentClient.disconnect(); System.exit(0); } })); buttons.add(new JButton(new AbstractAction("Katalog whlen") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { if (catalogs.getSelectedIndex() != -1) { try { Client.currentClient .setCatalog(new Catalog(data.getJSONObject(catalogs.getSelectedIndex()))); Client.currentClient.frame.setTitle("- " + Client.currentClient.getCatalog().getName()); dialog.dispose(); } catch (JSONException e1) { e1.printStackTrace(); } } } })); dialog.add(buttons); dialog.setLocationRelativeTo(frame); dialog.setResizable(false); dialog.setVisible(true); }
From source file:OptPaneComparison.java
public OptPaneComparison(final String message) { setDefaultCloseOperation(EXIT_ON_CLOSE); final int msgType = JOptionPane.QUESTION_MESSAGE; final int optType = JOptionPane.OK_CANCEL_OPTION; final String title = message; setSize(350, 200);//from w w w . j a v a 2 s . c o m // Create a desktop for internal frames final JDesktopPane desk = new JDesktopPane(); setContentPane(desk); // Add a simple menu bar JMenuBar mb = new JMenuBar(); setJMenuBar(mb); JMenu menu = new JMenu("Dialog"); JMenu imenu = new JMenu("Internal"); mb.add(menu); mb.add(imenu); final JMenuItem construct = new JMenuItem("Constructor"); final JMenuItem stat = new JMenuItem("Static Method"); final JMenuItem iconstruct = new JMenuItem("Constructor"); final JMenuItem istat = new JMenuItem("Static Method"); menu.add(construct); menu.add(stat); imenu.add(iconstruct); imenu.add(istat); // Create our JOptionPane. We're asking for input, so we call // setWantsInput. // Note that we cannot specify this via constructor parameters. optPane = new JOptionPane(message, msgType, optType); optPane.setWantsInput(true); // Add a listener for each menu item that will display the appropriate // dialog/internal frame construct.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { // Create and display the dialog JDialog d = optPane.createDialog(desk, title); d.setVisible(true); respond(getOptionPaneValue()); } }); stat.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { String s = JOptionPane.showInputDialog(desk, message, title, msgType); respond(s); } }); iconstruct.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { // Create and display the dialog JInternalFrame f = optPane.createInternalFrame(desk, title); f.setVisible(true); // Listen for the frame to close before getting the value from // it. f.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent ev) { if ((ev.getPropertyName().equals(JInternalFrame.IS_CLOSED_PROPERTY)) && (ev.getNewValue() == Boolean.TRUE)) { respond(getOptionPaneValue()); } } }); } }); istat.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { String s = JOptionPane.showInternalInputDialog(desk, message, title, msgType); respond(s); } }); }
From source file:ProfileManager.java
/** * <p>Lists identified characters, and asks the user to give a name of a yet * to be identified character.</p> * /*from w w w .j av a2s. c o m*/ * <p> Then searches the folder of each <code>Character</code> object whose * <code>identified</code> flag is <code>false</code>, until one is * identified as being correct, none are found (error).</p> * * <p>OLD: Then searches the folder of each entry in * <code>unidentifiedCharacters</code> until one is identified as being * correct, or none are found (error).</p> */ private static void identifyCharacter() { System.out.println("\nIdentifying Character..."); //unidentifiedCharactersFrame = new UnidentifiedCharactersFrame(); String unidentifiedCharacterNames = "Identified Characters:\n"; for (Character character : characters) { if (character.identified()) { System.out.println("\nAdding identified character name to list..."); unidentifiedCharacterNames += character.getName() + "\n"; } // if character is identified } // for each character in characters String nameInput = JOptionPane.showInputDialog(null, unidentifiedCharacterNames, "Identify New Character", QUESTION_MESSAGE); }
From source file:com.qspin.qtaste.ui.testcampaign.TestCampaignMainPanel.java
public void genUI() { TestCampaignTreeModel model = new TestCampaignTreeModel("Test Campaign"); treeTable = new JTreeTable(model); FormLayout layout = new FormLayout("6px, pref, 6px, pref, 6px, pref, 6px, pref, 6px, pref, 6px:grow", "6px, fill:pref, 6px"); PanelBuilder builder = new PanelBuilder(layout); CellConstraints cc = new CellConstraints(); int colIndex = 2; JLabel label = new JLabel("Campaign:"); saveMetaCampaignButton.setIcon(ResourceManager.getInstance().getImageIcon("icons/save_32")); saveMetaCampaignButton.setToolTipText("Save campaign"); saveMetaCampaignButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (selectedCampaign == null) { logger.warn("No Campaign created"); return; }// w w w . j av a 2 s. c o m treeTable.save(selectedCampaign.getFileName(), selectedCampaign.getCampaignName()); } }); addNewMetaCampaignButton.setIcon(ResourceManager.getInstance().getImageIcon("icons/add")); addNewMetaCampaignButton.setToolTipText("Define a new campaign"); addNewMetaCampaignButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String newCampaign = JOptionPane.showInputDialog(null, "New campaign creation:", "Campaign name:", JOptionPane.QUESTION_MESSAGE); if (newCampaign != null && newCampaign.length() > 0) { int index = addTestCampaign(newCampaign); metaCampaignComboBox.setSelectedIndex(index); MetaCampaignFile currentSelectedCampaign = (MetaCampaignFile) metaCampaignComboBox .getSelectedItem(); selectedCampaign = currentSelectedCampaign; if (selectedCampaign != null) { treeTable.save(selectedCampaign.getFileName(), selectedCampaign.getCampaignName()); } metaCampaignComboBox.validate(); metaCampaignComboBox.repaint(); } } }); // get last selected campaign GUIConfiguration guiConfiguration = GUIConfiguration.getInstance(); String lastSelectedCampaign = guiConfiguration.getString(LAST_SELECTED_CAMPAIGN_PROPERTY); // add campaigns found in the list MetaCampaignFile[] campaigns = populateCampaignList(); builder.add(label, cc.xy(colIndex, 2)); colIndex += 2; builder.add(metaCampaignComboBox, cc.xy(colIndex, 2)); colIndex += 2; // add test campaign mouse listener, for the Rename and Remove actions TestcampaignMouseListener testcampaignMouseListener = new TestcampaignMouseListener(); java.awt.Component[] mTestcampaignListComponents = metaCampaignComboBox.getComponents(); for (int i = 0; i < mTestcampaignListComponents.length; i++) { mTestcampaignListComponents[i].addMouseListener(testcampaignMouseListener); } metaCampaignComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { MetaCampaignFile currentSelectedCampaign = (MetaCampaignFile) metaCampaignComboBox .getSelectedItem(); if (currentSelectedCampaign != selectedCampaign) { selectedCampaign = currentSelectedCampaign; if (selectedCampaign != null) { treeTable.removeAll(); if (new File(selectedCampaign.getFileName()).exists()) { treeTable.load(selectedCampaign.getFileName()); } GUIConfiguration guiConfiguration = GUIConfiguration.getInstance(); guiConfiguration.setProperty(LAST_SELECTED_CAMPAIGN_PROPERTY, selectedCampaign.getCampaignName()); try { guiConfiguration.save(); } catch (ConfigurationException ex) { logger.error("Error while saving GUI configuration: " + ex.getMessage(), ex); } } else { treeTable.removeAll(); } } } }); boolean setLastSelectedCampaign = false; if (lastSelectedCampaign != null) { // select last selected campaign for (int i = 0; i < campaigns.length; i++) { if (campaigns[i].getCampaignName().equals(lastSelectedCampaign)) { metaCampaignComboBox.setSelectedIndex(i); setLastSelectedCampaign = true; break; } } } if (!setLastSelectedCampaign && metaCampaignComboBox.getItemCount() > 0) { metaCampaignComboBox.setSelectedIndex(0); } runMetaCampaignButton.setIcon(ResourceManager.getInstance().getImageIcon("icons/running_32")); runMetaCampaignButton.setToolTipText("Run campaign"); runMetaCampaignButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { if (selectedCampaign == null) { logger.warn("No Campaign created"); return; } // first save the current campaign if needed if (treeTable.hasChanged()) { treeTable.save(selectedCampaign.getFileName(), selectedCampaign.getCampaignName()); } // set SUT version TestBedConfiguration.setSUTVersion(parent.getSUTVersion()); testExecutionHandler = new CampaignExecutionThread(selectedCampaign.getFileName()); Thread t = new Thread(testExecutionHandler); t.start(); // set the window to test result // TO DO } catch (Exception ex) { // logger.error(ex.getMessage(), ex); } } }); builder.add(addNewMetaCampaignButton, cc.xy(colIndex, 2)); colIndex += 2; builder.add(saveMetaCampaignButton, cc.xy(colIndex, 2)); colIndex += 2; builder.add(runMetaCampaignButton, cc.xy(colIndex, 2)); colIndex += 2; JScrollPane sp = new JScrollPane(treeTable); this.add(builder.getPanel(), BorderLayout.NORTH); this.add(sp); }
From source file:me.ryandowling.allmightybot.AllmightyBot.java
public AllmightyBot() { if (Files.exists(Utils.getSettingsFile())) { try {/*from www .j a v a2 s . co m*/ this.settings = GSON.fromJson(FileUtils.readFileToString(Utils.getSettingsFile().toFile()), Settings.class); } catch (IOException e) { e.printStackTrace(); } } else { this.settings = new Settings(); } if (!this.settings.hasInitialSetupBeenCompleted()) { String input = null; input = JOptionPane.showInputDialog(null, "Please enter the username of the Twitch user " + "to act " + "as the bot", "Twitch Username", JOptionPane.QUESTION_MESSAGE); if (input == null) { logger.error("Failed to input proper things when setting up! Do it properly next time!"); System.exit(0); } settings.setTwitchUsername(input); input = JOptionPane.showInputDialog(null, "Please enter the IRC oauth token of the Twitch user " + "acting as the bot", "Twitch Token", JOptionPane.QUESTION_MESSAGE); if (input == null) { logger.error("Failed to input proper things when setting up! Do it properly next time!"); System.exit(0); } settings.setTwitchToken(input); input = JOptionPane.showInputDialog(null, "Please enter the API token of the Twitch user " + "acting " + "as the bot", "Twitch API Token", JOptionPane.QUESTION_MESSAGE); if (input == null) { logger.error("Failed to input proper things when setting up! Do it properly next time!"); System.exit(0); } settings.setTwitchApiToken(input); input = JOptionPane.showInputDialog(null, "Please enter the API client ID of the application using " + "the Twitch API", "Twitch API Client ID", JOptionPane.QUESTION_MESSAGE); if (input == null) { logger.error("Failed to input proper things when setting up! Do it properly next time!"); System.exit(0); } settings.setTwitchApiClientID(input); input = JOptionPane.showInputDialog(null, "Please enter the username of the Twitch user whose " + "channel you wish to join! Must be in all lowercase", "User To Join", JOptionPane.QUESTION_MESSAGE); if (input == null) { logger.error("Failed to input proper things when setting up! Do it properly next time!"); System.exit(0); } settings.setTwitchChannel(input); input = JOptionPane.showInputDialog(null, "Please enter the name of the caster to display when " + "referencing them", "Casters Name", JOptionPane.QUESTION_MESSAGE); if (input == null) { logger.error("Failed to input proper things when setting up! Do it properly next time!"); System.exit(0); } settings.setCastersName(input); input = JOptionPane.showInputDialog(null, "How often do you want to run the timed messages (in " + "minutes)?", "Timed Messages", JOptionPane.QUESTION_MESSAGE); try { settings.setTimedMessagesInterval(Integer.parseInt(input) * 60); } catch (NumberFormatException e) { input = null; } input = JOptionPane.showInputDialog(null, "How long do you want to time people out for when they post " + "links after 1 warning (in minutes)?", "Spam Timeouts", JOptionPane.QUESTION_MESSAGE); try { settings.setLinkTimeoutLength1(Integer.parseInt(input) * 60); } catch (NumberFormatException e) { input = null; } input = JOptionPane.showInputDialog(null, "How long do you want to time people out for when they post " + "links after 2 and more warnings (in minutes)?", "Spam Timeouts", JOptionPane.QUESTION_MESSAGE); try { settings.setLinkTimeoutLength2(Integer.parseInt(input) * 60); } catch (NumberFormatException e) { input = null; } if (input == null) { logger.error("Failed to input proper things when setting up! Do it properly next time!"); System.exit(0); } int reply = JOptionPane.showConfirmDialog(null, "Do you want the bot to announce itself on join " + "(message " + "customisable in the lang.json file after startup)?", "Self Announce", JOptionPane.YES_NO_OPTION); if (reply != JOptionPane.YES_OPTION) { settings.setAnnounceOnJoin(false); } this.settings.initialSetupComplete(); this.firstTime = true; } }
From source file:backend.SoftwareSecurity.java
private String getKeyFromUser() { //prompts user for key boolean ready = false; String keyRes = null;//from w w w .ja v a 2 s. co m while (!ready) { keyRes = JOptionPane.showInputDialog(null, "Enter Activation Key (Requires Internet Connection):", "Activate Supreme Shark Bot", 3); if (null == keyRes) { //they clicked x or cancel to activation prompt System.out.println("Activation Prompted Exited, Software Quitting"); System.exit(0); } else if (!keyRes.isEmpty()) { //the keyRes wasn't blank ready = true; System.out.println("Activation Key Entered: " + keyRes); } } return keyRes; }