本文整理汇总了Java中javax.security.auth.callback.NameCallback.notify方法的典型用法代码示例。如果您正苦于以下问题:Java NameCallback.notify方法的具体用法?Java NameCallback.notify怎么用?Java NameCallback.notify使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.security.auth.callback.NameCallback
的用法示例。
在下文中一共展示了NameCallback.notify方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleName
import javax.security.auth.callback.NameCallback; //导入方法依赖的package包/类
protected void handleName (final NameCallback callback)
throws IOException
{
final JDialog dialog = new JDialog ();
Container content = dialog.getContentPane ();
content.setLayout (new GridBagLayout ());
content.add (new JLabel (callback.getPrompt ()),
new GridBagConstraints (0, 0, 1, 1, 0, 0,
GridBagConstraints.NORTHEAST,
GridBagConstraints.VERTICAL,
new Insets (10, 10, 15, 5), 0, 0));
final JTextField name = new JTextField ();
name.setColumns (20);
String _name;
if ((_name = callback.getDefaultName ()) != null)
name.setText (_name);
content.add (name, new GridBagConstraints (1, 0, 1, 1, 1, 1,
GridBagConstraints.NORTHWEST,
GridBagConstraints.BOTH,
new Insets (10, 5, 15, 10), 0, 0));
ActionListener listener = new ActionListener ()
{
public void actionPerformed (ActionEvent ae)
{
String cmd = ae.getActionCommand ();
if (cmd.equals ("okay"))
callback.setName (name.getText ());
dialog.setVisible (false);
synchronized (callback)
{
callback.notify ();
}
}
};
JPanel buttons = new JPanel ();
buttons.setLayout (new FlowLayout (FlowLayout.RIGHT));
JButton cancel = new JButton (messages.getString ("callback.cancel"));
JButton okay = new JButton (messages.getString ("callback.ok"));
cancel.setActionCommand ("cancel");
cancel.addActionListener (listener);
buttons.add (cancel);
okay.setActionCommand ("okay");
okay.addActionListener (listener);
buttons.add (okay);
content.add (buttons, new GridBagConstraints (0, 1, 2, 1, 0, 0,
GridBagConstraints.SOUTHEAST,
GridBagConstraints.NONE,
new Insets (0, 10, 10, 10), 0, 0));
dialog.setResizable (false);
dialog.pack ();
dialog.setVisible (true);
dialog.getRootPane ().setDefaultButton (okay);
waitForInput (dialog, callback);
}