您的位置:首页 > 其它

ATM系统实现[1]——用户登录界面[00原创]

2007-07-23 20:07 696 查看
系统的需求文档和最终报告文档:

ATM系统的需求

ATM系统设计报告

package cn.edu.ynu.sei.atm.client.ui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

/**
* 登录界面
* @author 88250
*/
public class LoginInterface
{
/**
* 服务端地址
*/
public static final String serviceAddr = "rmi://192.168.0.32:1099/";

/**
* 提示卡号标签
*/
private Label cardIDLbl;

/**
* 卡号显示
*/
private Text cardIDTxt;

/**
* 登录卡号<br>
* <b>注意:</b>这里假定了一个卡号,该卡号应该是ATM自动识别出来的, 所以直接设置成{@code}public了
*/
public static String loginCardID = "88250";

/**
* 登录按钮
*/
private Button loginBtn;

/**
* "注意"按钮
*/
private Button noticeBtn;

/**
* 窗口实例
*/
protected Shell shell;

/**
* 主界面位置与大小
*/
private final Rectangle guiSize = new Rectangle(600, 300, 300, 300);

/**
* 注意事项容器
*/
private NoticeComposite nc = null;

/**
* 创建一个欢迎窗口
*/
public LoginInterface()
{
shell = new Shell();
shell.setBounds(guiSize);
shell.setText("ATM Application");
}

/**
* 主程序入口
*
* @param args
* {@code}null
*/
public static void main(String[] args)
{
try
{
LoginInterface window = new LoginInterface();
window.open();
}
catch (Exception e)
{
e.printStackTrace();
}
}

/**
* 打开欢迎界面
*/
public void open()
{
final Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();

while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
}

/**
* 创建欢迎界面内含控件
*/
protected void createContents()
{
loginBtn = new Button(shell, SWT.NONE);
loginBtn.addMouseListener(new MouseAdapter()
{
public void mouseDown(MouseEvent arg0)
{// 以当前卡号登录
new LoginComposite(shell);
setContentsVisible(false);
}
});

loginBtn.setText("登录");
loginBtn.setBounds(158, 125, 69, 27);

noticeBtn = new Button(shell, SWT.NONE);
noticeBtn.addMouseListener(new MouseAdapter()
{
public void mouseDown(MouseEvent arg0)
{// 单击注意事项按钮
setContentsVisible(false); // 设置欢迎窗口控件为不可见
nc = new NoticeComposite(shell);
nc.getReturnBtn().addMouseListener(new MouseAdapter()
{// 在注意事项窗口容器内单击了返回按按钮
public void mouseDown(MouseEvent e)
{
nc.setContentsVisible(false); // 设置注意事项容器内的控件不可见
setContentsVisible(true); // 设置欢迎窗口控件可见
}
});
}
});

noticeBtn.setText("注意事项");
noticeBtn.setBounds(58, 125, 69, 27);

cardIDTxt = new Text(shell, SWT.BORDER);
cardIDTxt.setEditable(false);

cardIDTxt.setText(loginCardID);
cardIDTxt.setBounds(57, 80, 168, 25);

cardIDLbl = new Label(shell, SWT.NONE);
cardIDLbl.setText("您的卡号:");
cardIDLbl.setBounds(59, 46, 60, 15);
}

/**
* 设置欢迎界面内含控件的可见性
*
* @param b
* 可见性
*/
public void setContentsVisible(boolean b)
{
loginBtn.setVisible(b);
noticeBtn.setVisible(b);
cardIDLbl.setVisible(b);
cardIDTxt.setVisible(b);
}
}



package cn.edu.ynu.sei.atm.client.ui;

import cn.edu.ynu.sei.atm.interfaceDef.IAvailableAccount;
import cn.edu.ynu.sei.atm.interfaceDef.IVerification;
import java.rmi.Naming;
import java.rmi.RemoteException;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.MessageBox;

/**
* 登录界面
* @author 88250
*/
public class LoginComposite extends Composite
{
/**
* 登录状态显示
*/
private Label loginStateShowLbl;

/**
* 登录状态标签
*/
private Label loginStateLbl;

/**
* 提示输入密码标签
*/
private Label pleaseInputPwdLbl;

/**
* 密码验证面板容器
*/
private PwdInputComposite pwdInputCmpst = null;

/**
* 父窗口容器
*/
private Composite parent = null;

/**
* 验证身份接口实例
*/
private IVerification verification = null;

/**
* 可用帐户接口实例
*/
private IAvailableAccount availableAccount = null;

/**
* 创建登录窗口容器
* @param parent 父窗口容器
*/
public LoginComposite(Composite parent)
{
super(parent, SWT.NONE);
this.parent = parent;
createContents();
}

/**
* 创建登录对话窗口内含控件
*/
private void createContents()
{
pleaseInputPwdLbl = new Label(parent, SWT.NONE);
pleaseInputPwdLbl.setBounds(10, 10, 105, 20);
pleaseInputPwdLbl.setText("请输入您的密码:");

loginStateLbl = new Label(parent, SWT.NONE);
loginStateLbl.setLocation(10, 220);
loginStateLbl.setSize(65, 20);
loginStateLbl.setText("登录状态:");

loginStateShowLbl = new Label(parent, SWT.NONE);
loginStateShowLbl.setLocation(80, 220);
loginStateShowLbl.setSize(60, 20);

pwdInputCmpst = new PwdInputComposite(parent);
// 确定按钮监听
pwdInputCmpst.getConfirmLbl().addMouseListener(new MouseAdapter()
{
public void mouseDown(MouseEvent arg0)
{
// 取得远程服务对象
try
{
verification = (IVerification) Naming.lookup(
LoginInterface.serviceAddr + "Verification");
}
catch (RemoteException re)
{
re.printStackTrace();
MessageBox exitDlg = new MessageBox(parent.getShell());
exitDlg.setText("网络连接出现问题....");
exitDlg.setMessage("不能连接到服务器,系统将退出!");
exitDlg.open();
System.exit(0);
}
catch (Exception e)
{
e.printStackTrace();
}

try
{
if (verification.verify(LoginInterface.loginCardID,
pwdInputCmpst.getPwdText()))
{// 验证身份成功
setConentsVisible(false);
availableAccount = (IAvailableAccount) Naming.lookup(
LoginInterface.serviceAddr + "AvailableAccount");
// 设置对应帐号
availableAccount.setAvailableAccountID(LoginInterface.loginCardID);
new AccountSelectComposite(parent, availableAccount);
}
else
{// 登录失败
loginStateShowLbl.setText("密码错误!");
pwdInputCmpst.clearPwdText();
}
}
catch (RemoteException re)
{
re.printStackTrace();
MessageBox exitDlg = new MessageBox(parent.getShell());
exitDlg.setText("网络连接出现问题....");
exitDlg.setMessage("不能连接到服务器,系统将退出!");
exitDlg.open();
System.exit(0);
}
catch (Exception e)
{
e.printStackTrace();
}
}
});
pwdInputCmpst.setBounds(70, 30, 294, 185);

}

/**
* 设置登录界面容器内控件的可见性
* @param b 可见性
*/
public void setConentsVisible(boolean b)
{
loginStateLbl.setVisible(b);
loginStateShowLbl.setVisible(b);
pleaseInputPwdLbl.setVisible(b);
pwdInputCmpst.setVisible(b);
}

@Override
public void dispose()
{
super.dispose();
}

@Override
protected void checkSubclass()
{
// Disable the check that prevents subclassing of SWT components
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: