I have a virtual keyboard class which implements a QWERTY alphanumeric only on-screen keyboard using JButtons in JAVA.
I have installed actionlisteners to each button so that whenever the button is clicked on the label of the button is logged.
What I want to do is that while keeping the class for keyboard separate, I want to create an instance of the keyboard class so that it receives an input and it passes it back to the main class and then that can happen in a loop. Just like how you can use has.nextLine() to keep on asking for input, I want to be able to do this by creating an instance of the on screen keyboard class.
I have already written the keyboard class and it works nicely and but the problem is that the integers are local to the keyboard class and I cant figure out a way to get it outside of the class.
You can use observer pattern . I am not using swing here but just to show to show it works.
Make Keyboard class Observable
Make your main class Observer