/** * Prompts the user for input in a sheet where the initial selection, possible selections, and all * other options can be specified. The user will able to choose from {@code selectionValues}, * where {@code null} implies the user can input whatever they wish, usually by means of a {@code * JTextField}. {@code initialSelectionValue} is the initial value to prompt the user with. It is * up to the UI to decide how best to represent the {@code selectionValues}, but usually a {@code * JComboBox}, {@code JList}, or {@code JTextField} will be used. * * @param parentComponent the parent {@code Component} for the dialog * @param message the {@code Object} to display * @param messageType the type of message to be displayed: {@code JOptionPane.ERROR_MESSAGE}, * {@code JOptionPane.INFORMATION_MESSAGE}, {@code JOptionPane.WARNING_MESSAGE}, {@code * JOptionPane.QUESTION_MESSAGE}, or {@code JOptionPane.PLAIN_MESSAGE} * @param icon the {@code Icon} image to display * @param selectionValues an array of {@code Object}s that gives the possible selections * @param initialSelectionValue the value used to initialize the input field * @param listener The listener for SheetEvents. */ public static void showInputSheet( Component parentComponent, Object message, int messageType, Icon icon, Object[] selectionValues, Object initialSelectionValue, SheetListener listener) { JOptionPane pane = new JOptionPane(message, messageType, JOptionPane.OK_CANCEL_OPTION, icon, null, null); pane.setWantsInput(true); pane.setSelectionValues(selectionValues); pane.setInitialSelectionValue(initialSelectionValue); pane.setComponentOrientation( ((parentComponent == null) ? JOptionPane.getRootFrame() : parentComponent) .getComponentOrientation()); int style = styleFromMessageType(messageType); JSheet sheet = createSheet(pane, parentComponent, style); pane.selectInitialValue(); /* sheet.addWindowListener(new WindowAdapter() { public void windowClosed(WindowEvent evt) { sheet.dispose(); } });*/ sheet.addSheetListener(listener); sheet.show(); sheet.toFront(); }
/** * Method used by the SystemIO class to get interactive user input requested by a running MIPS * program (e.g. syscall #5 to read an integer). SystemIO knows whether simulator is being run at * command line by the user, or by the GUI. If run at command line, it gets input from System.in * rather than here. * * <p>This is an overloaded method. This version, with the String parameter, is used to get input * from a popup dialog. * * @param prompt Prompt to display to the user. * @return User input. */ public String getInputString(String prompt) { String input; JOptionPane pane = new JOptionPane(prompt, JOptionPane.QUESTION_MESSAGE, JOptionPane.DEFAULT_OPTION); pane.setWantsInput(true); JDialog dialog = pane.createDialog(Globals.getGui(), "MIPS Keyboard Input"); dialog.setVisible(true); input = (String) pane.getInputValue(); this.postRunMessage(Globals.userInputAlert + input + "\n"); return input; }
@Override public void actionPerformed(ActionEvent arg0) { for (Frame f : Frame.getFrames()) if (f.isActive()) parent_frame = (JFrame) f; if (arg0.getActionCommand().equalsIgnoreCase("Exit")) { parent_frame.dispatchEvent(new WindowEvent(parent_frame, WindowEvent.WINDOW_CLOSING)); } else if (arg0.getActionCommand().equalsIgnoreCase("NEWUSER")) { showNewUserDialog(parent_frame); } else if (arg0.getActionCommand().equals("START")) { TableUI this_game = games.get("MainGame"); if (this_game != null) { this_game.start(); game_start_menu.setEnabled(false); } } else if (arg0.getActionCommand().equals("HOST")) { game_host_menu.setEnabled(false); game_join_menu.setEnabled(false); game_start_menu.setEnabled(true); GUITable.this.hostGame("MainGame"); } else if (arg0.getActionCommand().equals("JOIN")) { Matcher m = null; Object options[] = {"Connect", "Cancel"}; String host_str = null; JOptionPane jp = new JOptionPane( "Enter host information", JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, options, options[0]); jp.setWantsInput(true); JDialog jd = jp.createDialog(parent_frame.getContentPane(), "Join Game"); do { jd.setVisible(true); Object selection = jp.getValue(); if ((selection == null) || (selection == options[1])) break; host_str = (String) jp.getInputValue(); for (int i = 0; i < connect_str.length; i++) { m = connect_str[i].matcher(host_str); if (m.matches()) break; } if ((m != null) && m.matches()) break; JOptionPane.showConfirmDialog( parent_frame.getContentPane(), "Enter valid format for host information", "Error", JOptionPane.OK_OPTION, JOptionPane.ERROR_MESSAGE); m = null; } while (m == null); if (m != null) { game_host_menu.setEnabled(false); game_join_menu.setEnabled(false); game_start_menu.setEnabled(true); GUITable.this.joinGame(host_str, "MainGame"); } } }