package net.javaswing.startingSwing;

import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


import javax.swing.*;
public class AcceleratorExample  {
	public void createAndShowFrame(){
		
		//Create a JFrame Object
		//Pass the title as an argument to the constructor
		//We make it final, so that we cann access it in the
		//ActionListener inner class below
		final JFrame frame = new JFrame(" A Simple Swing Example");
		
		//Set the Size of the frame
		frame.setSize(300, 300);
		
		//Specify that, when the user closes this frame,
		//the program should exit
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JLabel label = new JLabel();
		label.setText("Accelerator Key: f");
		JTextField field = new JTextField("Press alt+'f' to focus on this Field ");
		
		label.setLabelFor(field);
		label.setDisplayedMnemonic('f');
		
				
		frame.getContentPane().setLayout(new GridLayout(2,2));
		frame.getContentPane().add(label);
		frame.getContentPane().add(field);
		
		
		JLabel label2 = new JLabel();
		label2.setText("Accelerator Key: g");
		JTextField field2 = new JTextField("Press alt+'g' to focus on this Field ");
		
		label2.setLabelFor(field2);
		label2.setDisplayedMnemonic('g');
		
		frame.getContentPane().add(label2);
		frame.getContentPane().add(field2);
		//Make the frame visible
		frame.setSize(400, 100);
		frame.setVisible(true);
	}
	
	public static void main(String[] args){
		//Create an instance of our class
		final AcceleratorExample example = new AcceleratorExample();
		
		//Call the createAndShowFrame method in the 
		//EventDispatch thread
		SwingUtilities.invokeLater(new Runnable(){
			public void run(){
				example.createAndShowFrame();
			}
		});
	}
}
