📄 loginframe.java
字号:
package com.cownew.PIS.framework.client;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.util.prefs.Preferences;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import com.cownew.PIS.framework.common.exception.PISException;
import com.cownew.PIS.framework.common.services.ACInfo;
import com.cownew.PIS.framework.common.services.ILoginService;
import com.cownew.ctk.common.StringUtils;
import com.cownew.ctk.ui.swing.MsgBox;
public class LoginFrame extends JFrame
{
private static final String USER_NAME = "UserName";
private static final String ACINDEX = "ACIndex";
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JLabel jLabel = null;
private JLabel jLabel1 = null;
private JLabel jLabel2 = null;
private JComboBox comboACList = null;
private JTextField txtUserName = null;
private JPasswordField txtPassword = null;
private JButton btnLogin = null;
private JButton btnExit = null;
/**
* @param owner
* @
*/
public LoginFrame()
{
super();
initialize();
loadConfig();
}
/**
* This method initializes this
*
* @return void
* @
*/
private void initialize()
{
this.setSize(300, 200);
this.setTitle("登录");
this.setContentPane(getJContentPane());
ILoginService loginService = (ILoginService) RemoteServiceLocator
.getRemoteService(ILoginService.class);
//取得所有定义的帐套列表
ACInfo[] acInfos = loginService.getAllACInfo();
comboACList.removeAllItems();
//添加到帐套列表对话框中
for (int i = 0, n = acInfos.length; i < n; i++)
{
comboACList.addItem(acInfos[i]);
}
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane()
{
if (jContentPane == null)
{
jLabel2 = new JLabel();
jLabel2.setBounds(new Rectangle(26, 89, 64, 18));
jLabel2.setText("密码");
jLabel1 = new JLabel();
jLabel1.setBounds(new Rectangle(26, 59, 64, 18));
jLabel1.setText("用户名");
jLabel = new JLabel();
jLabel.setText("帐套");
jLabel.setBounds(new Rectangle(26, 28, 64, 18));
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(jLabel, null);
jContentPane.add(jLabel1, null);
jContentPane.add(jLabel2, null);
jContentPane.add(getComboACList(), null);
jContentPane.add(getTxtUserName(), null);
jContentPane.add(getTxtPassword(), null);
jContentPane.add(getBtnLogin(), null);
jContentPane.add(getBtnExit(), null);
}
return jContentPane;
}
/**
* This method initializes comboACList
*
* @return javax.swing.JComboBox
*/
private JComboBox getComboACList()
{
if (comboACList == null)
{
comboACList = new JComboBox();
comboACList.setBounds(new Rectangle(127, 28, 146, 19));
}
return comboACList;
}
/**
* This method initializes txtUserName
*
* @return javax.swing.JTextField
*/
private JTextField getTxtUserName()
{
if (txtUserName == null)
{
txtUserName = new JTextField();
txtUserName.setBounds(new Rectangle(127, 59, 146, 22));
}
return txtUserName;
}
/**
* This method initializes txtPassword
*
* @return javax.swing.JPasswordField
*/
private JPasswordField getTxtPassword()
{
if (txtPassword == null)
{
txtPassword = new JPasswordField();
txtPassword.setBounds(new Rectangle(127, 89, 146, 22));
}
return txtPassword;
}
/**
* This method initializes btnLogin
*
* @return javax.swing.JButton
*/
private JButton getBtnLogin()
{
if (btnLogin == null)
{
btnLogin = new JButton();
btnLogin.setBounds(new Rectangle(36, 132, 65, 23));
btnLogin.setText("登录");
btnLogin.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e)
{
btnLogin_actionPerformed(e);
}
});
}
return btnLogin;
}
protected void btnLogin_actionPerformed(ActionEvent e)
{
if (comboACList.getSelectedIndex() < 0)
{
MsgBox.showError(this, "请选择帐套!");
return;
}
if (StringUtils.isEmpty(txtUserName.getText()))
{
MsgBox.showError(this, "用户名不能为空!");
return;
}
ACInfo acInfo = (ACInfo) comboACList.getSelectedItem();
String userName = txtUserName.getText().trim();
String password = txtPassword.getText().trim();
try
{
ILoginService loginService = (ILoginService) RemoteServiceLocator
.getRemoteService(ILoginService.class);
//验证用户名密码
String sessionId = loginService.login(userName, password, acInfo
.getName());
if (!StringUtils.isEmpty(sessionId))
{
RemoteServiceLocator.initLocator(sessionId);
//保存配置
saveConfig();
dispose();
MainFrame mainFrame = MainFrame.getMainFrame();
mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
mainFrame.setLocationRelativeTo(null);
mainFrame.setVisible(true);
} else
{
MsgBox.showError(this, "用户名密码错误,无法登录!");
return;
}
} catch (PISException pe)
{
MsgBox.showError(this, pe.getMessage());
return;
}
}
/**
* This method initializes btnExit
*
* @return javax.swing.JButton
*/
private JButton getBtnExit()
{
if (btnExit == null)
{
btnExit = new JButton();
btnExit.setBounds(new Rectangle(151, 132, 65, 23));
btnExit.setText("退出");
btnExit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e)
{
btnExit_actionPerformed(e);
}
});
}
return btnExit;
}
protected void btnExit_actionPerformed(ActionEvent e)
{
System.exit(0);
}
protected void loadConfig()
{
Preferences pref = Preferences.userNodeForPackage(LoginFrame.class);
comboACList.setSelectedIndex(pref.getInt(ACINDEX, 0));
txtUserName.setText(pref.get(USER_NAME, ""));
}
protected void saveConfig()
{
Preferences pref = Preferences.userNodeForPackage(LoginFrame.class);
pref.putInt(ACINDEX, comboACList.getSelectedIndex());
pref.put(USER_NAME, txtUserName.getText());
}
} // @jve:decl-index=0:visual-constraint="146,14"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -