ATM系统实现[4]——帐户选择窗口[00原创]

来源:互联网 发布:java 图片合成文字 编辑:程序博客网 时间:2024/05/04 03:01
package cn.edu.ynu.sei.atm.client.ui;

import cn.edu.ynu.sei.atm.interfaceDef.IAvailableAccount;
import cn.edu.ynu.sei.atm.interfaceDef.IBankAccount;
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.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.MessageBox;

/**
 * 帐号选择窗口容器
 * 
@author 88250
 
*/
public class AccountSelectComposite extends Composite
{
    
/**
     * 确定按钮
     
*/
    
private Button confirmBtn;

    
/**
     * 活期帐户选项
     
*/
    
private Button curAccountRadio;

    
/**
     * 信用卡帐户选项
     
*/
    
private Button credAccountRadio;

    
/**
     * 定期帐户选项
     
*/
    
private Button depAccountRadio;

    
/**
     * 提示选择帐户标签
     
*/
    
private Label pleaseSelectLbl;

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

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

    
/**
     * 服务选择窗口容器
     
*/
    
private ServiceSelectComposite ssc = null;

    
/**
     * 帐户操作实例
     
*/
    
public static IBankAccount account = null;

    
/**
     * 创建一个帐户选择框实例,初始化可用帐户信息
     * 
@param parent 父窗口容器
     * 
@param availableAccount 可用帐户信息
     
*/
    
public AccountSelectComposite(Composite parent,
        IAvailableAccount availableAccount)
    {
    
super(parent, SWT.NONE);
    
this.parent = parent;
    
this.availableAccount = availableAccount;
    createContents();
    }

    
/**
     * 创建帐号选择窗口容器的内含控件
     
*/
    
private void createContents()
    {
    depAccountRadio 
= new Button(parent, SWT.RADIO);
    depAccountRadio.setText(
"定期帐户");
    depAccountRadio.setBounds(
59949822);

    curAccountRadio 
= new Button(parent, SWT.RADIO);
    curAccountRadio.setText(
"活期帐户");
    curAccountRadio.setBounds(
59669822);

    credAccountRadio 
= new Button(parent, SWT.RADIO);
    credAccountRadio.setText(
"信用卡帐户");
    credAccountRadio.setBounds(
591209822);

    setAccountsEnabled();
    
    curAccountRadio.addSelectionListener(
new SelectionAdapter()
    {
        
public void widgetSelected(SelectionEvent e)
        {
        confirmBtn.setEnabled(
true);
        
try
        {
            account 
= (IBankAccount)Naming.lookup(
                LoginInterface.serviceAddr 
+ "CurrentAccount");
            account.setID(availableAccount.getCurID());
        }
        
catch (RemoteException re)
        {
            MessageBox exitDlg 
= new MessageBox(parent.getShell());
            exitDlg.setText(
"网络连接出现问题....");
            exitDlg.setMessage(
"不能连接到服务器!");
            exitDlg.open();
            System.exit(
0);
            re.printStackTrace();
        }
        
catch (Exception ex)
        {
            ex.printStackTrace();
        }
        }
    });
    credAccountRadio.addSelectionListener(
new SelectionAdapter()
    {
        
public void widgetSelected(SelectionEvent e)
        {
        confirmBtn.setEnabled(
true);
        
try
        {
            account 
= (IBankAccount)Naming.lookup(
                LoginInterface.serviceAddr 
+ "CreditAccount");
            account.setID(availableAccount.getCredID());
        }
        
catch (RemoteException re)
        {
            MessageBox exitDlg 
= new MessageBox(parent.getShell());
            exitDlg.setText(
"网络连接出现问题....");
            exitDlg.setMessage(
"不能连接到服务器,系统将退出!");
            exitDlg.open();
            System.exit(
0);
            re.printStackTrace();
        }
        
catch (Exception ex)
        {
            ex.printStackTrace();
        }

        }
    });
    depAccountRadio.addSelectionListener(
new SelectionAdapter()
    {
        
public void widgetSelected(SelectionEvent e)
        {
        confirmBtn.setEnabled(
true);
        
try
        {
            account 
= (IBankAccount)Naming.lookup(
                LoginInterface.serviceAddr 
+ "DepositAccount");
            account.setID(availableAccount.getDepID());
        }
        
catch (RemoteException re)
        {
            MessageBox exitDlg 
= new MessageBox(parent.getShell());
            exitDlg.setText(
"网络连接出现问题....");
            exitDlg.setMessage(
"不能连接到服务器,系统将退出!");
            exitDlg.open();
            System.exit(
0);
            re.printStackTrace();
        }
        
catch (Exception ex)
        {
            ex.printStackTrace();
        }

        }
    });
    pleaseSelectLbl 
= new Label(parent, SWT.NONE);
    pleaseSelectLbl.setText(
"请选择您的帐户类型:");
    pleaseSelectLbl.setBounds(
294113015);
    ssc 
= new ServiceSelectComposite(parent);
    confirmBtn 
= new Button(parent, SWT.NONE);
    confirmBtn.setEnabled(
false);
    confirmBtn.addMouseListener(
new MouseAdapter()
    {
        
public void mouseDown(MouseEvent arg0)
        {
// 单击确定按钮
        setContentsVisible(false);
        ssc.setContentsVisible(
true);
        }
    });
    ssc.getReturnBtn().addMouseListener(
new MouseAdapter()
    {
// 在服务选择窗口容器内单击了返回按按钮
            public void mouseDown(MouseEvent e)
            {
            ssc.setContentsVisible(
false);
            setContentsVisible(
true);
            }
        });
    confirmBtn.setText(
"确定");
    confirmBtn.setBounds(
1911355127);
    }

    
/**
     * 设置可用帐户选择窗口内含控件的可见性
     * 
@param b 可见性
     
*/
    
private void setContentsVisible(boolean b)
    {
    confirmBtn.setVisible(b);
    credAccountRadio.setVisible(b);
    curAccountRadio.setVisible(b);
    depAccountRadio.setVisible(b);
    pleaseSelectLbl.setVisible(b);
    }

    
/**
     * 设置可用帐户选择
     
*/
    
private void setAccountsEnabled()
    {
    
try
    {
        
if (availableAccount.getCurID() != 0)
        {
// 活期帐户可用
        curAccountRadio.setEnabled(true);
        }
        
else
        {
        curAccountRadio.setEnabled(
false);
        }
        
        
if (availableAccount.getDepID() != 0)
        {
// 定期帐户可用
        depAccountRadio.setEnabled(true);
        }
        
else
        {
        depAccountRadio.setEnabled(
false);
        }

        
if (availableAccount.getCredID() != 0)
        {
// 信用卡帐户可用
        credAccountRadio.setEnabled(true);
        }
        
else
        {
        credAccountRadio.setEnabled(
false);
        }
    }
    
catch (RemoteException re)
    {
        MessageBox exitDlg 
= new MessageBox(parent.getShell());
        exitDlg.setText(
"网络连接出现问题....");
        exitDlg.setMessage(
"不能连接到服务器,系统将退出!");
        exitDlg.open();
        System.exit(
0);
        re.printStackTrace();
    }
    
catch (Exception e)
    {
        e.printStackTrace();
    }
    }

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

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

}