Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7501371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:30:23+00:00 2026-05-29T20:30:23+00:00

I have a virtual keyboard class which implements a QWERTY alphanumeric only on-screen keyboard

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T20:30:26+00:00Added an answer on May 29, 2026 at 8:30 pm

    You can use observer pattern . I am not using swing here but just to show to show it works.

    Make Keyboard class Observable

        import java.util.Observable;
    
        public class Keybaord extends Observable {
    
            private String keyThatIsPressed;
    
            public void setKeyThatIsPressed(String keyThatIsPressed) {
                this.keyThatIsPressed = keyThatIsPressed;
                setChanged();
                notifyObservers(keyThatIsPressed);
            }
    
            public String getKeyThatIsPressed(){
                return keyThatIsPressed;
            }
    
     }
    

    Make your main class Observer

    import java.util.Observable;
    import java.util.Observer;
    
    public class MainClass implements Observer {
        private String keyThatIsPressed;
    
        @Override
        public void update(Observable observable,
                Object object) {
            if (object instanceof String) {
                this.keyThatIsPressed = (String) object;
                System.out.println("Key that was unlucky enough to get pressed was: "
                        + keyThatIsPressed);
            } 
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to use a Virtual(on screen) keyboard on a asp:textbox which has a
I have an EditText which when some text entered the virtual keyboard appears and
I have a virtual on screen keyboard for a touch screen interface. I get
Suppose I have virtual function foo() in class B, and I need slightly different
I have a virtual machine (VMware) with Mercury Quick Test Professional 9.2 installed. I
For my WPF application I have developed a virtual keyboard. It runs fine on
Here's the problem: I have a user with disabilities and using a specialized virtual
I have an issue with a virtual keyboard. This Soft Keyboard Covers Data Fields
Does anyone have any ideas about how to make a Javascript virtual keyboard for
I'm creating virtual keyboard using C#, my friends designed it for me and sent

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.