import java.awt.BorderLayout;
import java.awt.event.*;
import javax.swing.*;

public class HWFrame extends JFrame implements ActionListener {

	static final long serialVersionUID = 43;
	
	HWDisplay appl;
	JMenuBar menuBar;
	JMenu menu;
	JMenuItem about, returnMain, exit;
	
	public HWFrame() {
		super("Hobo Wars");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setLayout(new BorderLayout());

		appl = new HWDisplay();
		appl.init();
		add(appl, BorderLayout.PAGE_END);
		
		menuBar = new JMenuBar();
		menu = new JMenu("Hobo Wars");
		menuBar.add(menu);
		
		about = new JMenuItem("About...");
		returnMain = new JMenuItem("Return to Main Menu");
		exit = new JMenuItem("Exit");
		
		about.addActionListener(this);
		returnMain.addActionListener(this);
		exit.addActionListener(this);
		
		menu.add(about);
		menu.add(returnMain);
		menu.add(exit);
		
		appl.setJMenuBar(menuBar);
		
		pack();
		setVisible(true);
	}
	
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == about) {
			Icon hanson = new ImageIcon(this.getClass().getClassLoader().getResource("img/about/hanson.jpg"));
			JOptionPane.showMessageDialog(this,
				    "Created by Daniel Naito and Joe Zorzi, 2008\nAmador Valley High School APCS\nMade in the service of Sir Hanson",
				    "About",
				    JOptionPane.INFORMATION_MESSAGE,
				    hanson);
		} else if (e.getSource() == returnMain) {
			appl.menu.setMenu(0);
			appl.menu.setSelection(0);
			appl.changeTo(appl.menu);
		} else if (e.getSource() == exit) {
			System.exit(0);
		}
	}
	
	public static void main(String[] args) {
		new HWFrame();
	}

}
