当前位置: 首页>>代码示例>>Java>>正文


Java JOptionPane.getValue方法代码示例

本文整理汇总了Java中javax.swing.JOptionPane.getValue方法的典型用法代码示例。如果您正苦于以下问题:Java JOptionPane.getValue方法的具体用法?Java JOptionPane.getValue怎么用?Java JOptionPane.getValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JOptionPane的用法示例。


在下文中一共展示了JOptionPane.getValue方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: show

import javax.swing.JOptionPane; //导入方法依赖的package包/类
/** Helper method for constructing an always-on-top modal dialog. */
private static Object show(String title, int type, Object message, Object[] options, Object initialOption) {
	if (options == null) {
		options = new Object[] {
				"Ok"
		};
		initialOption = "Ok";
	}
	JOptionPane p = new JOptionPane(message, type, JOptionPane.DEFAULT_OPTION, null, options, initialOption);
	p.setInitialValue(initialOption);
	JDialog d = p.createDialog(null, title);
	p.selectInitialValue();
	d.setAlwaysOnTop(true);
	d.setVisible(true);
	d.dispose();
	return p.getValue();
}
 
开发者ID:AlloyTools,项目名称:org.alloytools.alloy,代码行数:18,代码来源:OurDialog.java

示例2: actionPerformed

import javax.swing.JOptionPane; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent e) {
    if (!isEnabled())
        return;

    TermOptions clonedTermOptions = termOptions.makeCopy();
    TermOptionsPanel subPanel = new TermOptionsPanel();
    subPanel.setTermOptions(clonedTermOptions);

    JOptionPane optionPane = new JOptionPane(subPanel,
                                             JOptionPane.PLAIN_MESSAGE,
                                             JOptionPane.OK_CANCEL_OPTION
                                             );
        JDialog dialog = optionPane.createDialog(Terminal.this,
                                                 "NBTerm Options");
        dialog.setVisible(true);      // WILL BLOCK!

        if (optionPane.getValue() == null)
            return;     // was closed at the window level

        switch ((Integer) optionPane.getValue()) {
            case JOptionPane.OK_OPTION:
                System.out.printf("Dialog returned OK\n");
                termOptions.assign(clonedTermOptions);
                applyTermOptions(false);
                termOptions.storeTo(prefs);
                break;
            case JOptionPane.CANCEL_OPTION:
                System.out.printf("Dialog returned CANCEL\n");
                break;
            case JOptionPane.CLOSED_OPTION:
                System.out.printf("Dialog returned CLOSED\n");
                break;
            default:
                System.out.printf("Dialog returned OTHER: %s\n",
                                  optionPane.getValue());
                break;
        }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:Terminal.java

示例3: inputPassword

import javax.swing.JOptionPane; //导入方法依赖的package包/类
@Override
public String inputPassword(String messageText) {
	final JPasswordField passwordField = new JPasswordField();
	JOptionPane jop = new JOptionPane(new Object[] { messageText, passwordField }, JOptionPane.QUESTION_MESSAGE,
			JOptionPane.OK_CANCEL_OPTION);
	JDialog dialog = jop.createDialog("Auhtentication required");
	dialog.addComponentListener(new ComponentAdapter() {

		@Override
		public void componentShown(ComponentEvent e) {
			SwingUtilities.invokeLater(new Runnable() {

				@Override
				public void run() {
					passwordField.requestFocusInWindow();
					passwordField.requestFocus();
				}
			});
		}
	});
	dialog.setVisible(true);
	int result = (Integer) jop.getValue();
	if (result == JOptionPane.OK_OPTION) {
		return new String(passwordField.getPassword());
	} else {
		return null;
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:29,代码来源:GUIInputHandler.java

示例4: show

import javax.swing.JOptionPane; //导入方法依赖的package包/类
/** Helper method for constructing an always-on-top modal dialog. */
private static Object show(String title, int type, Object message, Object[] options, Object initialOption) {
   if (options == null) { options = new Object[]{"Ok"};  initialOption = "Ok"; }
   JOptionPane p = new JOptionPane(message, type, JOptionPane.DEFAULT_OPTION, null, options, initialOption);
   p.setInitialValue(initialOption);
   JDialog d = p.createDialog(null, title);
   p.selectInitialValue();
   d.setAlwaysOnTop(true);
   d.setVisible(true);
   d.dispose();
   return p.getValue();
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:13,代码来源:OurDialog.java

示例5: readFromGUI

import javax.swing.JOptionPane; //导入方法依赖的package包/类
/**
 * Ask using a GUI for the username and password.
 */
private void readFromGUI() {
   // Create fields for user name.
   final JTextField usernameField = new JTextField(20);
   usernameField.setText(this.username);
   final JLabel usernameLabel = new JLabel("Username: ");
   usernameLabel.setLabelFor(usernameField);
   final JPanel usernamePane = new JPanel(new FlowLayout(FlowLayout.TRAILING));
   usernamePane.add(usernameLabel);
   usernamePane.add(usernameField);

   // Create fields for password.
   final JPasswordField passwordField = new JPasswordField(20);
   passwordField.setText(this.password);
   final JLabel passwordLabel = new JLabel("Password: ");
   passwordLabel.setLabelFor(passwordField);
   final JPanel passwordPane = new JPanel(new FlowLayout(FlowLayout.TRAILING));
   passwordPane.add(passwordLabel);
   passwordPane.add(passwordField);

   // Create panel
   final JPanel main = new JPanel();
   main.setLayout(new BoxLayout(main, BoxLayout.PAGE_AXIS));
   main.add(usernamePane);
   main.add(passwordPane);

   // Create and handle dialog
   final JOptionPane jop = new JOptionPane(main, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
   final JDialog dialog = jop.createDialog("User name and password");
   dialog.addComponentListener(new ComponentAdapter() {
      
      public void componentShown(ComponentEvent e) {
         SwingUtilities.invokeLater(new Runnable() {
            
            public void run() {
               if (usernameField.getText().isEmpty())
               {
                  usernameField.requestFocusInWindow();
               }
               else
               {
                  passwordField.requestFocusInWindow();
               }
            }
         });
      }
   });
   dialog.setVisible(true);
   final Integer result = (Integer) jop.getValue();
   dialog.dispose();
   if (result.intValue() == JOptionPane.OK_OPTION) {
      this.username = usernameField.getText();

      final char[] pwd = passwordField.getPassword();
      this.password = new String(pwd);
   }
}
 
开发者ID:OpenDA-Association,项目名称:OpenDA,代码行数:60,代码来源:UsernamePassword.java


注:本文中的javax.swing.JOptionPane.getValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。