📄 loginpanel.java
字号:
/* * Copyright (c) 2000 Lyrisoft Solutions, Inc. * Used by permission */package com.lyrisoft.chat.client.gui.awt102;import java.awt.*;import com.lyrisoft.chat.Translator;import com.lyrisoft.chat.client.gui.IChatClientInputReceiver;import com.lyrisoft.chat.client.gui.ILogin;public class LoginPanel extends Panel implements ILogin { TextField txtLogin = new TextField(25); TextField txtPassword = new TextField(25); GridBagLayout gridBag = new GridBagLayout(); Label lblLogin = null; Label lblPassword = null; Label lblStatus = null; Button btnLogin = null; Button btnCancel = null; private IChatClientInputReceiver _inputReceiver; boolean showPassword; public LoginPanel(IChatClientInputReceiver client) { this(client, Translator.getMessage("label.loginwindow"), Translator.getMessage("label.login"), Translator.getMessage("label.password"), Translator.getMessage("label.login"), Translator.getMessage("label.cancel"), true); } public LoginPanel(IChatClientInputReceiver client, String label, String loginLabel, String passwordLabel, String loginButtonLabel, String cancelButtonLabel, boolean showPassword) { _inputReceiver = client; lblStatus = new Label(label); lblLogin = new Label(loginLabel); lblPassword = new Label(passwordLabel); btnLogin = new Button(loginButtonLabel); btnCancel = new Button(cancelButtonLabel); this.showPassword = showPassword; txtLogin.setBackground(Color.white); txtPassword.setBackground(Color.white); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } public void setStatus(String txt) { lblStatus.setText(txt); } public boolean action(Event e, Object arg) { if (e.id == Event.ACTION_EVENT) { if (e.target == btnCancel) { _inputReceiver.loginCancelEvent(); return true; } if (e.target == btnLogin || (showPassword && e.target == txtPassword) || (!showPassword && e.target == txtLogin)) { _inputReceiver.loginEvent(txtLogin.getText(), txtPassword.getText()); return true; } else if (e.target == txtLogin) { txtPassword.requestFocus(); return true; } } return super.action(e, arg); } public void requestFocus() { txtLogin.requestFocus(); } private void jbInit() throws Exception { setLayout(gridBag); txtPassword.setEchoCharacter('*'); gridBag.setConstraints(lblLogin, Constraints.create(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 0, 0), 0, 0)); gridBag.setConstraints(txtLogin, Constraints.create(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 0), 0, 5)); gridBag.setConstraints(lblPassword, Constraints.create(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 0, 0), 0, 0)); gridBag.setConstraints(txtPassword, Constraints.create(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 0), 0, 5)); gridBag.setConstraints(btnLogin, Constraints.create(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 0, 0), 0, 0)); gridBag.setConstraints(btnCancel, Constraints.create(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 0, 0), 0, 0)); gridBag.setConstraints(lblStatus, Constraints.create(0, 3, 2, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 0), 0, 0)); add(txtLogin); add(lblLogin); if (showPassword) { add(txtPassword); add(lblPassword); } add(btnLogin); add(btnCancel); add(lblStatus); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -