//package <package_name>

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

public class SwingApplication extends JFrame {

	private JMenuBar mainMenuBar;
	private JMenu fileMenu;
	private Action exitAction;
	private int keyMask;
	
	public SwingApplication() {
		
		super("");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		keyMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
		exitAction = new ExitAction("Exit", KeyStroke.getKeyStroke(KeyEvent.VK_X, keyMask));
		mainMenuBar = new JMenuBar();
		addFileMenu();
		setJMenuBar(mainMenuBar);
		setSize(300, 200);
		setVisible(true);
	}

	private void exit() {	
		System.exit(0);
	}

	private void addFileMenu() {

		fileMenu = new JMenu("File");
		fileMenu.add(new JMenuItem(exitAction));
		mainMenuBar.add(fileMenu);
	}

	public void paint(Graphics g) {
		super.paint(g);
		g.setColor(Color.blue);
		g.drawString("Hello World", 40, 80);
	}
	
	private class ExitAction extends AbstractAction {
		
		public ExitAction(String text, KeyStroke shortcut) {
			super(text);
			putValue(ACCELERATOR_KEY, shortcut);
		}
	
		public void actionPerformed(ActionEvent e) {
			exit();
		}
	}
	
	public static void main(String args[]) {
		new SwingApplication();
	}

}