import java.awt.Event;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.text.DefaultEditorKit;
public class MainClass extends JFrame {
MainClass(String title) {
super(title);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel jp = new JPanel();
JLabel jl = new JLabel("Name:");
jp.add(jl);
JTextField jt = new JTextField(20);
jp.add(jt);
KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_B, Event.CTRL_MASK);
jt.getInputMap().put(ks, DefaultEditorKit.beepAction);
getContentPane().add(jp);
pack();
setVisible(true);
}
public static void main(String[] args) {
new MainClass("Binding Demo2");
}
}
|