I’m creating a keyboard using buttons with java, when a user clicks on a button labelled from A to Z it will set a JTextField text to A or whatever button they pressed.
I have a seperate class for each button so for A its public class listenser1 implements ActionListener, B its public class listenser2 implements ActionListener is this a good way of doing it?
Also I tried to do do it under one class and used if and if else statements buy using
if(a.getText().equals("A"))
{
input1.setText(input.getText() + "A");
}
.
.
.
And this doesn’t work, it prints out ABCDEFGHIJKLMNOPQRSTUVWXYZ instead of just the one letter.
No, that is not the most efficient way. That takes way too long to write. Instead, try this: