-----------------------------------------------------
package minibank;
import java.awt.Toolkit;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import java.awt.Dimension;
import javax.swing.plaf.metal.*;
import java.awt.*;
import minibank.Utility.*;
import minibank.Data.*;
import minibank.Custom.*;
import minibank.Exception.*;
import javax.swing.JFrame;
import minibank.GUI.*;
public class Entry
{
private boolean packFrame = false;
public Entry()
{
MainFrame
frame;
frame =
new MainFrame();
//
Validate frames that have preset sizes
// Pack
frames that have useful preferred size info, e.g. from their
layout
if
(packFrame)
{
frame.pack();
}
else
{
frame.validate();
}
try
{
// Center and size the window
DecideFrameLocal(frame);
frame.Initi();
SwingUtilities.updateComponentTreeUI(frame);
}
catch
(Exception ex)
{
ExceptionLog.Instance().ReportException(ex);
}
frame.setVisible(true);
}
private static void DecideFrameLocal(JFrame
frame) throws HeadlessException
{
Dimension
screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension
frameSize = frame.getSize();
frame.setLocation( (screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
}
public static void main(String[] args) throws
InterruptedException
{
SplashFrame
splash;
SystemLoginFrame login;
DialogResult
res;
splash =
new SplashFrame();
splash.pack();
DecideFrameLocal(splash);
splash.setVisible(true);
// Thread.sleep(1500);
login =
new SystemLoginFrame();
login.setAlwaysOnTop(true);
res =
login.Show();
//Create
application
if (res ==
DialogResult.Ok)
{
login.dispose();
splash.toFront();
RunApplication();
}
else
{
System.exit(0);
}
splash.dispose();
}
private static void RunApplication()
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
try
{
PropertyService ps;
ps = PropertyService.Instance();
//Select theme.
if (ps.GetProperty("gui.theme.theme").equals("ocean"))
{
MetalLookAndFeel.setCurrentTheme(new OceanTheme());
}
else
{
MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
}
//Select look
UIManager.setLookAndFeel(ps.GetProperty("gui.theme.look"));
}
catch (Exception ex)
{
ex.printStackTrace();
ExceptionLog.Instance().ReportException(ex);
}
new Entry();
}
});
}
}
---------------------------------------------------------------------------------
package minibank;
import java.awt.event.ActionEvent;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameAdapter;
import javax.swing.JInternalFrame;
import java.awt.event.ActionListener;
import java.util.Hashtable;
class MainFrame_jMenuFileExit_ActionAdapter
implements
ActionListener
{
MainFrame adaptee;
MainFrame_jMenuFileExit_ActionAdapter(MainFrame adaptee)
{
this.adaptee
= adaptee;
}
public void actionPerformed(ActionEvent
actionEvent)
{
adaptee.jMenuFileExit_actionPerformed(actionEvent);
}
}
class MainFrame_jMenuHelpAbout_ActionAdapter
implements
ActionListener
{
MainFrame adaptee;
MainFrame_jMenuHelpAbout_ActionAdapter(MainFrame adaptee)
{
this.adaptee
= adaptee;
}
public void actionPerformed(ActionEvent
actionEvent)
{
adaptee.jMenuHelpAbout_actionPerformed(actionEvent);
}
}
class MainFrame_jMenuItemLogout_actionAdapter
implements
ActionListener
{
private MainFrame adaptee;
MainFrame_jMenuItemLogout_actionAdapter(MainFrame adaptee)
{
this.adaptee
= adaptee;
}
public void actionPerformed(ActionEvent
e)
{
adaptee.jMenuItemLogout_actionPerformed(e);
}
}
---------------------------------------------------------------------------------------
package minibank;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import minibank.Utility.*;
import minibank.GUI.*;
import minibank.Custom.*;
import minibank.Exception.*;
import javax.swing.event.InternalFrameListener;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameAdapter;
import java.util.*;
import minibank.Custom.ICustomer;
public class MainFrame
extends
JFrame implements ICustomerStatusListener
{
private InnerFrameManager _deskContainer;
//
JPanel contentPane;
BorderLayout borderLayout1 = new
BorderLayout();
JMenuBar jMenuBar1 = new JMenuBar();
JMenu jMenuFile = new JMenu();
JMenuItem jMenuFileExit = new JMenuItem();
JMenu jMenuHelp = new JMenu();
JMenuItem jMenuHelpAbout = new
JMenuItem();
JLabel statusBar = new JLabel();
JLabel labStatus = new JLabel();
JMenuItem jMenuItemLogout = new JMenuItem();
public MainFrame()
{
try
{
jbInit();
}
catch
(Exception exception)
{
exception.printStackTrace();
}
}
private void jbInit() throws Exception
{
contentPane
= (JPanel) getContentPane();
contentPane.setLayout(borderLayout1);
setSize(new
Dimension(800, 600));
setTitle(PropertyService.Instance().GetProperty("gui.title"));
statusBar.setText(" ");
jMenuFile.setText("系统");
jMenuFileExit.setText("退出");
jMenuFileExit.addActionListener(new
MainFrame_jMenuFileExit_ActionAdapter(this));
jMenuHelp.setText("帮助");
jMenuHelpAbout.setText("关于..");
jMenuHelpAbout.addActionListener(new
MainFrame_jMenuHelpAbout_ActionAdapter(this));
labStatus.setText("jLabel1");
jMenuItemLogout.addActionListener(new
MainFrame_jMenuItemLogout_actionAdapter(this));
jMenuItemLogout.setText("注销");
jMenuBar1.add(jMenuFile);
jMenuFile.add(jMenuItemLogout);
jMenuFile.add(jMenuFileExit);
jMenuBar1.add(jMenuHelp);
jMenuHelp.add(jMenuHelpAbout);
setJMenuBar(jMenuBar1);
contentPane.add(statusBar, java.awt.BorderLayout.CENTER);
contentPane.add(labStatus, java.awt.BorderLayout.SOUTH);
}
//Todo: Event listener.
public void Initi()
{
ButtonBar
_btnBar;
setDefaultCloseOperation(EXIT_ON_CLOSE);
this.enableEvents(AWTEvent.WINDOW_EVENT_MASK);
InitiIcon();
//Initi
buttonBar.
InitiButtonBar();
//Initi
MDI container.
InitiMDI();
//Status.
this.labStatus.setText(PropertyService.Instance().GetProperty(
"gui.labStatus"));
CustomerManagerSingleton.Instance().AddCustomStatusListener(this);
}
private void InitiMDI()
{
_deskContainer = new InnerFrameManager(this);
this.add(_deskContainer.DeskContainer(),
BorderLayout.CENTER);
}
private void InitiButtonBar()
{
ButtonBar
_btnBar;
_btnBar =
new ButtonBar();
_btnBar.Initialize(this,
XmlManagerSingleton.Instance().LoadXmlDocument(
"BBar.xml"));
this.add(_btnBar, BorderLayout.WEST);
}
private void InitiIcon()
{
PropertyService ps = PropertyService.Instance();
jMenuFileExit.setIcon(ps.LoadImageIcon("res\\exit.png"));
jMenuItemLogout.setIcon(ps.LoadImageIcon("res\\switch.png"));
this.setIconImage(ps.LoadImageIcon(ps.GetProperty("gui.myicon")).getImage());
}
void jMenuFileExit_actionPerformed(ActionEvent
actionEvent)
{
OnClose();
}
protected void processWindowEvent(WindowEvent
e)
{
if
(e.getID() == WindowEvent.WINDOW_CLOSING)
{
OnClose();
}
super.processWindowEvent(e);
}
private void OnClose()
{
ExceptionLog.Instance().Disopse();
System.exit(0);
}
void jMenuHelpAbout_actionPerformed(ActionEvent
actionEvent)
{
MainFrame_AboutBox dlg = new MainFrame_AboutBox(this,
getSize(),
getLocation());
dlg.show();
}
public void ButtonBar_Action(ActionEvent
e)
{
ButtonExtend
btn = (ButtonExtend) e.getSource();
//Todo:
Is not good.
if
(btn.FrameDescribe().ClassName().equals("minibank.GUI.CustomerLoginPanel"))
{
if (SwitchCustomer())
_deskContainer.Inside(btn.FrameDescribe());
}
else
{
if (IsLogin())
_deskContainer.Inside(btn.FrameDescribe());
else
{
MessageBox.Show("请先登陆帐户.", "当前没有帐户登陆.", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
}
}
private boolean SwitchCustomer()
{
DialogResult
res;
if
(!IsLogin())
return true;
//Show
messageBox.
res =
MessageBox.Show(SwitchMessage(), "切换帐户",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if (res
== DialogResult.No)
return false;
CustomerManagerSingleton.Instance().AccountLogout();
return
true;
}
private String SwitchMessage()
{
return "帐户:
" +
CustomerManagerSingleton.Instance().CurrentCustomer().CurrentActiveAccount().
ID() + " 已登陆. \r\n 是否切换帐户.";
}
private boolean IsLogin()
{
return
CustomerManagerSingleton.Instance().IsLogin();
}
public void
CustomerStatusChanged(CustomUpdateEvent e)
{
UpdateStatusBar();
}
private void UpdateStatusBar()
{
this.labStatus.setText(CustomerManagerSingleton.Instance().ToString());
}
public void
jMenuItemLogout_actionPerformed(ActionEvent e)
{
this.SwitchCustomer();
}
}
-----
-------------------------------------------------------------------
package minibank;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import minibank.Utility.*;
public class MainFrame_AboutBox
extends
JDialog implements ActionListener
{
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
JPanel insetsPanel1 = new JPanel();
JPanel insetsPanel2 = new JPanel();
JPanel insetsPanel3 = new JPanel();
JButton button1 = new JButton();
JLabel imageLabel = new JLabel();
JLabel label1 = new JLabel();
JLabel label2 = new JLabel();
JLabel label3 = new JLabel();
JLabel label4 = new JLabel();
ImageIcon image1 = new ImageIcon();
BorderLayout borderLayout1 = new
BorderLayout();
BorderLayout borderLayout2 = new
BorderLayout();
FlowLayout flowLayout1 = new FlowLayout();
GridLayout gridLayout1 = new GridLayout();
String product = "MiniBank";
String version = "0.1";
String copyright = "Copyright (c) 2005
Occur.org";
String comments = "";
public MainFrame_AboutBox(Frame parent,
Dimension parentSize, Point parentLoc)
{
super(parent);
try
{
PropertyService ser;
ser = PropertyService.Instance();
copyright = "Copyright (c) 2005 Occur.org";
setTitle(ser.GetProperty("about.title"));
product = ser.GetProperty("gui.title");
version = ser.GetProperty("about.version");
comments = ser.GetProperty("about.comments");
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
jbInit();
Dimension dlgSize = this.getPreferredSize();
Dimension frmSize = getSize();
Point loc = getLocation();
this.setLocation(parentLoc.x * 2,
parentLoc.y * 2);
this.setModal(true);
this.pack();
}
catch
(Exception exception)
{
exception.printStackTrace();
}
button1.setText("OK");
}
private void jbInit() throws Exception
{
image1 =
PropertyService.Instance().LoadImageIcon("res\\logo.png");
imageLabel.setIcon(image1);
panel1.setLayout(borderLayout1);
panel2.setLayout(borderLayout2);
insetsPanel1.setLayout(flowLayout1);
insetsPanel2.setLayout(flowLayout1);
insetsPanel2.setBorder(BorderFactory.createEmptyBorder(10, 10, 10,
10));
gridLayout1.setRows(4);
gridLayout1.setColumns(1);
label1.setText(product);
label2.setText(version);
label3.setText(copyright);
label4.setText(comments);
insetsPanel3.setLayout(gridLayout1);
insetsPanel3.setBorder(BorderFactory.createEmptyBorder(10, 60, 10,
10));
button1.addActionListener(this);
insetsPanel2.add(imageLabel, null);
panel2.add(insetsPanel2, BorderLayout.WEST);
getContentPane().add(panel1, null);
insetsPanel3.add(label1, null);
insetsPanel3.add(label2, null);
insetsPanel3.add(label3, null);
insetsPanel3.add(label4, null);
panel2.add(insetsPanel3, BorderLayout.CENTER);
insetsPanel1.add(button1, null);
panel1.add(insetsPanel1, BorderLayout.SOUTH);
panel1.add(panel2, BorderLayout.NORTH);
setResizable(false);
}
public void actionPerformed(ActionEvent
actionEvent)
{
if
(actionEvent.getSource() == button1)
{
dispose();
}
}
}
---------------------------------
//July/整理/05.23/。