0

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!

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by JamesCherrill
1

yes, from your KeyStroke only to call

but1.doClick();

wrapped into javax.swing.Actions or ActionsLitener

Edited by mKorbel: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.