/**
* @Author: Edmond Hoi
* @Description: IPM-ESAP-GERDC
* @Date: 2010.09.01
*/
package ipm.gerdc.baccarat;
import ipm.gerdc.baccarat.page.MainPage;
import ipm.gerdc.baccarat.util.TextFactory;
import ipm.gerdc.baccarat.util.UIFactory;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
public class MainFrame extends JFrame implements ActionListener {
private static final long serialVersionUID = 1L;
public static final String Page_001 = "ipm.gerdc.baccarat.page.MainPage";
public static final String Page_002 = "ipm.gerdc.baccarat.page.ConfigPage";
public static final String Page_003 = "ipm.gerdc.baccarat.page.ReportPage";
private static Main parent;
public MainFrame(Main frm) throws Exception {
parent = frm;
buildMenuBar();
parent.setPageName(Page_001);
MainPage mainPage = new MainPage();
mainPage.buildPage(parent);
getContentPane().add(mainPage, BorderLayout.CENTER);
}
public void buildMenuBar() {
parent.menus = new JMenu(TextFactory.textList.get("File"));
parent.menus.setFont(UIFactory.makeFonts(12));
parent.menus.setMnemonic('F');
parent.menuItems = new JMenuItem[5];
parent.menuItems[0] = createMenuItem(TextFactory.textList.get("PlayGame"), 'P');
parent.menuItems[1] = createMenuItem(TextFactory.textList.get("Config"), 'C');
parent.menuItems[2] = createMenuItem(TextFactory.textList.get("Report"), 'R');
parent.menuItems[3] = createMenuItem(TextFactory.textList.get("About"), 'A');
parent.menuItems[4] = createMenuItem(TextFactory.textList.get("Exit"), 'x');
parent.menus.add(parent.menuItems[0]);
parent.menus.add(parent.menuItems[1]);
parent.menus.add(parent.menuItems[2]);
parent.menus.add(parent.menuItems[3]);
parent.menus.addSeparator();
parent.menus.add(parent.menuItems[4]);
parent.mbar = new JMenuBar();
parent.mbar.add(parent.menus);
setJMenuBar(parent.mbar);
}
private JMenuItem createMenuItem(String name, char ch) {
JMenuItem jmi = new JMenuItem(name);
jmi.setFont(UIFactory.makeFonts(12));
jmi.addActionListener(this);
jmi.setEnabled(true);
jmi.setMnemonic(ch);
return jmi;
}
public void actionPerformed(ActionEvent evt) {
if (evt.getSource() instanceof JMenuItem) {
if (evt.getSource().equals(parent.menuItems[0])) {
parent.switchPage(Page_001);
} else if (evt.getSource().equals(parent.menuItems[1])) {
parent.switchPage(Page_002);
} else if (evt.getSource().equals(parent.menuItems[2])) {
parent.switchPage(Page_003);
} else if (evt.getSource().equals(parent.menuItems[3])) {
parent.about();
} else if (evt.getSource().equals(parent.menuItems[4])) {
setVisible(false);
System.exit(1);
}
}
}
}