Hi, I am working on a calculator using Java Swing, and have it done, but I was wondering how you would make it so, say when a certain keyboard button is pressed, that number will appear in the text box. Currently, it works so when you press said JButton, that number will appear in the text box. I want the key bindings to be an alternative that one can use as well.

Didn't include all code, but:

JTextArea text = new JTextArea(1, 20);
	JButton but1 = new JButton("1");
	JButton but2 = new JButton("2");
	JButton but3 = new JButton("3");
	JButton but4 = new JButton("4");

Specify if you need more. Thanks!

yes, from your KeyStroke only to call


wrapped into javax.swing.Actions or ActionsLitener

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.