下面列出了javax.swing.JPasswordField#addActionListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public CancelOrderDialog(JFrame owner, Market market, AssetOrder order, ContractState state) {
super(owner, ModalityType.APPLICATION_MODAL);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setTitle(tr("canc_cancel_order"));
isToken = market.getTokenID()!=null;
this.market = market;
this.order = order;
this.state = state;
conditions = new JTextPane();
conditions.setContentType("text/html");
conditions.setPreferredSize(new Dimension(80, 160));
conditions.setEditable(false);
acceptBox = new JCheckBox(tr("dlg_accept_terms"));
// Create a button
JPanel buttonPane = new JPanel(new FlowLayout(FlowLayout.RIGHT));
pin = new JPasswordField(12);
pin.addActionListener(this);
calcelButton = new JButton(tr("dlg_cancel"));
okButton = new JButton(tr("dlg_ok"));
getRootPane().setDefaultButton(okButton);
calcelButton.addActionListener(this);
okButton.addActionListener(this);
if(Globals.getInstance().usingLedger()) {
ledgerStatus = new JTextField(26);
ledgerStatus.setEditable(false);
buttonPane.add(new Desc(tr("ledger_status"), ledgerStatus));
LedgerService.getInstance().setCallBack(this);
}
else
buttonPane.add(new Desc(tr("dlg_pin"), pin));
buttonPane.add(new Desc(" ", calcelButton));
buttonPane.add(new Desc(" ", okButton));
// set action listener on the button
JPanel content = (JPanel)getContentPane();
content.setBorder(new EmptyBorder(4, 4, 4, 4));
JPanel conditionsPanel = new JPanel(new BorderLayout());
conditionsPanel.setBorder(BorderFactory.createTitledBorder(tr("dlg_terms_and_conditions")));
conditionsPanel.add(new JScrollPane(conditions), BorderLayout.CENTER);
conditionsPanel.add(acceptBox, BorderLayout.PAGE_END);
JPanel centerPanel = new JPanel(new BorderLayout());
centerPanel.add(conditionsPanel, BorderLayout.PAGE_END);
content.add(centerPanel, BorderLayout.CENTER);
content.add(buttonPane, BorderLayout.PAGE_END);
suggestedFee = Globals.getInstance().getNS().suggestFee().blockingGet();
boolean isBuy = false;
if(order!=null && order.getType() == AssetOrder.OrderType.BID)
isBuy = true;
if(state!=null && state.getType() == ContractType.BUY)
isBuy = true;
StringBuilder terms = new StringBuilder();
terms.append(PlaceOrderDialog.HTML_STYLE);
terms.append("<h3>").append(tr("canc_terms_brief", isBuy ? tr("token_buy") : tr("token_sell"), market,
isToken ? order.getId() : state.getAddress().getRawAddress())).append("</h3>");
if(isToken) {
terms.append("<p>").append(tr("canc_terms_token",
NumberFormatting.BURST.format(suggestedFee.getPriorityFee().longValue()))).append("</p>");
}
else {
terms.append("<p>").append(tr("canc_terms_contract",
state.getBalance().toUnformattedString(),
NumberFormatting.BURST.format(state.getActivationFee() + suggestedFee.getPriorityFee().longValue()))
).append("</p>");
}
conditions.setText(terms.toString());
conditions.setCaretPosition(0);
pack();
}
public SendDialog(JFrame owner, Market token) {
super(owner, ModalityType.APPLICATION_MODAL);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.token = token;
setTitle(tr("main_send", token==null ? "BURST" : token));
JPanel topPanel = new JPanel(new GridLayout(0, 1, 4, 4));
JPanel panel = new JPanel(new GridLayout(0, 2, 4, 4));
recipient = new JTextField(26);
message = new JTextField(26);
pin = new JPasswordField(12);
pin.addActionListener(this);
amount = new JFormattedTextField(token==null ? NumberFormatting.BURST.getFormat() : token.getNumberFormat().getFormat());
fee = new JSlider(1, 4);
topPanel.add(new Desc(tr("send_recipient"), recipient));
topPanel.add(new Desc(tr("send_message"), message));
message.setToolTipText(tr("send_empty_for_no_message"));
panel.add(new Desc(tr("send_amount", token==null ? "BURST" : token), amount));
Desc feeDesc = new Desc("", fee);
panel.add(feeDesc);
FeeSuggestion suggestedFee = BurstNode.getInstance().getSuggestedFee();
fee.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent evt) {
String feeType;
switch (fee.getValue()) {
case 1:
feeType = tr("fee_minimum");
selectedFee = BurstValue.fromPlanck(Constants.FEE_QUANT);
break;
case 2:
feeType = tr("fee_cheap");
selectedFee = suggestedFee.getCheapFee();
break;
case 3:
feeType = tr("fee_standard");
selectedFee = suggestedFee.getStandardFee();
break;
default:
feeType = tr("fee_priority");
selectedFee = suggestedFee.getPriorityFee();
break;
}
feeDesc.setDesc(tr("send_fee", feeType, selectedFee.toUnformattedString()));
}
});
// Create a button
JPanel buttonPane = new JPanel(new FlowLayout(FlowLayout.RIGHT));
calcelButton = new JButton(tr("dlg_cancel"));
okButton = new JButton(tr("dlg_ok"));
calcelButton.addActionListener(this);
okButton.addActionListener(this);
if(Globals.getInstance().usingLedger()) {
ledgerStatus = new JTextField(26);
ledgerStatus.setEditable(false);
buttonPane.add(new Desc(tr("ledger_status"), ledgerStatus));
LedgerService.getInstance().setCallBack(this);
}
else
buttonPane.add(new Desc(tr("dlg_pin"), pin));
buttonPane.add(new Desc(" ", calcelButton));
buttonPane.add(new Desc(" ", okButton));
// set action listener on the button
JPanel content = (JPanel)getContentPane();
content.setBorder(new EmptyBorder(4, 4, 4, 4));
content.add(topPanel, BorderLayout.PAGE_START);
content.add(panel, BorderLayout.CENTER);
content.add(buttonPane, BorderLayout.PAGE_END);
pack();
fee.getModel().setValue(4);
}
public RegisterContractDialog(Window owner, boolean isBuy) {
super(owner, ModalityType.APPLICATION_MODAL);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.isBuy = isBuy;
setTitle(tr("reg_register"));
conditions = new JTextPane();
conditions.setPreferredSize(new Dimension(240, 220));
acceptBox = new JCheckBox(tr("dlg_accept_terms"));
// The number of contracts to register
SpinnerNumberModel numModel = new SpinnerNumberModel(1, 1, 10, 1);
numOfContractsSpinner = new JSpinner(numModel);
JPanel numOfContractsPanel = new Desc(tr("reg_num_contracts"), numOfContractsSpinner);
numOfContractsSpinner.addChangeListener(this);
// Create a button
JPanel buttonPane = new JPanel(new FlowLayout(FlowLayout.RIGHT));
pin = new JPasswordField(12);
pin.addActionListener(this);
cancelButton = new JButton(tr("dlg_cancel"));
okButton = new JButton(tr("dlg_ok"));
cancelButton.addActionListener(this);
okButton.addActionListener(this);
buttonPane.add(new Desc(tr("dlg_pin"), pin));
buttonPane.add(new Desc(" ", cancelButton));
buttonPane.add(new Desc(" ", okButton));
JPanel content = (JPanel)getContentPane();
content.setBorder(new EmptyBorder(4, 4, 4, 4));
JPanel conditionsPanel = new JPanel(new BorderLayout());
conditionsPanel.setBorder(BorderFactory.createTitledBorder(tr("dlg_terms_and_conditions")));
JScrollPane scroll = new JScrollPane(conditions);
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
scroll.setPreferredSize(conditions.getPreferredSize());
conditionsPanel.add(scroll, BorderLayout.CENTER);
conditionsPanel.add(acceptBox, BorderLayout.PAGE_END);
JPanel centerPanel = new JPanel(new BorderLayout());
centerPanel.add(conditionsPanel, BorderLayout.CENTER);
content.add(numOfContractsPanel, BorderLayout.PAGE_START);
content.add(centerPanel, BorderLayout.CENTER);
content.add(buttonPane, BorderLayout.PAGE_END);
contract = Contracts.getCompiler(isBuy ? ContractType.BUY : ContractType.SELL);
stateChanged(null);
pack();
}
public ChatPanel() {
super(new BorderLayout());
JPanel addressPanel = new JPanel(new BorderLayout());
addressPanel.setBorder(BorderFactory.createTitledBorder("Your contacts"));
addressList = new JList<>();
addressList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
addressList.setPreferredSize(new Dimension(300, 300));
addressPanel.add(addressList, BorderLayout.CENTER);
add(addressPanel, BorderLayout.LINE_START);
addressList.addListSelectionListener(this);
pinField = new JPasswordField(12);
pinField.addActionListener(this);
JPanel panelSendMessage = new JPanel(new BorderLayout());
inputField = new JTextField();
inputField.setToolTipText("Enter your message");
panelSendMessage.add(new Desc("Enter your message", inputField), BorderLayout.CENTER);
inputField.addActionListener(this);
inputField.setEnabled(false);
btnSend = new JButton("");
Icon sendIcon = IconFontSwing.buildIcon(FontAwesome.PAPER_PLANE_O, 24, btnSend.getForeground());
btnSend.setIcon(sendIcon);
btnSend.setToolTipText("Send your message");
btnSend.addActionListener(this);
btnSend.setEnabled(false);
panelSendMessage.add(new Desc(" ", btnSend), BorderLayout.EAST);
displayField = new JTextPane();
displayField.setContentType("text/html");
displayField.setEditable(false);
displayField.setText(HTML_FORMAT);
scrollPane = new JScrollPane(displayField);
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
JPanel panelCenter = new JPanel(new BorderLayout());
panelCenter.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
add(panelCenter, BorderLayout.CENTER);
panelCenter.add(scrollPane, BorderLayout.CENTER);
panelCenter.add(panelSendMessage, BorderLayout.SOUTH);
setSize(280, 400);
}
@Override
protected JPanel assemble() {
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
username = new JTextField(20);
username.setMargin(new Insets(2, 2, 2, 2));
password = new JPasswordField(20);
password.setMargin(new Insets(2, 2, 2, 2));
server = new JTextField(20);
server.setMargin(new Insets(2, 2, 2, 2));
port = new JSpinner(new SpinnerNumberModel(3218, 1, 65535, 1));
port.setEditor(new JSpinner.NumberEditor(port, "#"));
HyperTextPane about = new HyperTextPane(
Messages.getString("ProxyLogic.about")).withWidth(500)
.withTransparency();
username.addActionListener(this);
password.addActionListener(this);
username.addCaretListener(this);
password.addCaretListener(this);
server.addCaretListener(this);
GridBagConstraints gbc = new GridBagConstraints();
JPanel container = new JPanel();
container.setLayout(new GridBagLayout());
gbc.gridx = 0;
gbc.gridy = 0;
gbc.anchor = GridBagConstraints.WEST;
gbc.insets.left = 5;
gbc.insets.bottom = 3;
container.add(new JLabel(Messages.getString("ProxyLogic.server")), gbc);
gbc.gridx = 1;
gbc.gridy = 0;
container.add(server, gbc);
gbc.gridx = 0;
gbc.gridy = 1;
gbc.anchor = GridBagConstraints.WEST;
gbc.insets.left = 5;
gbc.insets.bottom = 3;
container.add(new JLabel(Messages.getString("ProxyLogic.port")), gbc);
gbc.gridx = 1;
gbc.gridy = 1;
container.add(port, gbc);
gbc.gridx = 0;
gbc.gridy = 2;
gbc.anchor = GridBagConstraints.WEST;
gbc.insets.left = 5;
gbc.insets.bottom = 3;
container.add(new JLabel(Messages.getString("ProxyLogic.username")), gbc);
gbc.gridx = 1;
gbc.gridy = 2;
container.add(username, gbc);
gbc.gridx = 0;
gbc.gridy = 3;
container.add(new JLabel(Messages.getString("ProxyLogic.password")), gbc);
gbc.gridx = 1;
gbc.gridy = 3;
container.add(password, gbc);
panel.add(about);
panel.add(Box.createVerticalStrut(20));
panel.add(container);
panel.add(Box.createVerticalStrut(20));
return panel;
}
@Override
protected JPanel assemble() {
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
username = new JTextField(20);
username.setMargin(new Insets(2, 2, 2, 2));
password = new JPasswordField(20);
password.setMargin(new Insets(2, 2, 2, 2));
proxy = new JCheckBox(Messages.getString("AccountLogic.proxy"));
proxy.setSelected(false);
HyperTextPane about = new HyperTextPane(
Messages.getString("AccountLogic.about")).withWidth(500)
.withTransparency();
username.addActionListener(this);
password.addActionListener(this);
username.addCaretListener(this);
password.addCaretListener(this);
GridBagConstraints gbc = new GridBagConstraints();
JPanel container = new JPanel();
container.setLayout(new GridBagLayout());
gbc.gridx = 0;
gbc.gridy = 0;
gbc.anchor = GridBagConstraints.WEST;
gbc.insets.left = 5;
gbc.insets.bottom = 3;
container.add(new JLabel(Messages.getString("AccountLogic.username")), gbc);
gbc.gridx = 1;
gbc.gridy = 0;
container.add(username, gbc);
gbc.gridx = 0;
gbc.gridy = 1;
container.add(new JLabel(Messages.getString("AccountLogic.password")), gbc);
gbc.gridx = 1;
gbc.gridy = 1;
container.add(password, gbc);
gbc.gridx = 1;
gbc.gridy = 2;
container.add(proxy, gbc);
panel.add(about);
panel.add(Box.createVerticalStrut(20));
panel.add(container);
panel.add(Box.createVerticalStrut(20));
return panel;
}
/**
* Create a single-line password box with the specified name, label, and
* default value. To control the width of the box, call setTextWidth()
* first. To get the value, call getCharArrayValue(). Calling
* getStringValue() on a password entry will result in an error because it
* is less secure to pass around passwords as Strings than as arrays of
* characters.
* <p>
* The underlying class that is used to implement the password facility is
* javax.swing.JPasswordField. For details about how to use JPasswordField,
* see the <a href=
* "http://java.sun.com/docs/books/tutorial/uiswing/components/passwordfield.html"
* target="_top">Java Tutorial</a>
*
* @param name
* The name used to identify the entry (when accessing the
* entry).
* @param label
* The label to attach to the entry.
* @param defaultValue
* Default value to appear in the entry box.
* @param background
* The background color.
* @param foreground
* The foreground color.
* @since Ptolemy II 3.1
*/
public void addPassword(String name, String label, String defaultValue, Color background, Color foreground) {
JLabel lbl = new JLabel(label + ": ");
lbl.setBackground(_background);
JPasswordField entryBox = new JPasswordField(defaultValue, _width);
entryBox.setBackground(background);
entryBox.setForeground(foreground);
_addPair(name, lbl, entryBox, entryBox);
// Add the listener last so that there is no notification
// of the first value.
entryBox.addActionListener(new QueryActionListener(name));
// Add a listener for loss of focus. When the entry gains
// and then loses focus, listeners are notified of an update,
// but only if the value has changed since the last notification.
// FIXME: Unfortunately, Java calls this listener some random
// time after the window has been closed. It is not even a
// a queued event when the window is closed. Thus, we have
// a subtle bug where if you enter a value in a line, do not
// hit return, and then click on the X to close the window,
// the value is restored to the original, and then sometime
// later, the focus is lost and the entered value becomes
// the value of the parameter. I don't know of any workaround.
entryBox.addFocusListener(new QueryFocusListener(name));
}