I am trying to make a program that outputs some data when I press a physical key on my keyboard. Is there anyway to do this without having either the cmd selected or a gui?
Thanks, Not sure how clear this sounds, but if you need clarification ask and I'll try again
Related
How would I be able to clear the console in Java without it clearing any text that has been inputed by the user?
I have an application that clears the screens and re writes it every second. But it doesn't keep what I type in. I need to be able to preserve the user input until enter is pressed. Is there a way to do this?
Thanks :)
I've scoured for the answer for this. I have a simple text based game. I make a choice with a radio button, and confirm it with a button click. I've set the game to save for when I change to landscape from portrait view.
But I cannot for the life of me find how to save the game when the back button is pressed.
I'd like to have a simple menu on the title screen with three buttons, one of them being "Continue" which would restore the game's saved settings. And obviously, one in the action menu I already have set up which would reset all the game data.
I've tried sharedPreferences etc. if someone can tell me the way to save the game data by using SQL so no user can mess with the data, that'd be better.
Thank you in advance for you help.
on edit I realized my question is not specific enough. I am trying to retain the state of a TextView which I am modifying with user choices, thus changing the text. Every time the app is restarted, the first text loads.
It kind of depends on how much information you want to save, but if it's very little I'd look in to shared preferences which saves key value pares. If it contains a bit more, you should look in to SQLLite which is just a database for your app on the device.
Further reading:
SharedPreferences:
https://developer.android.com/training/basics/data-storage/shared-preferences.html
SQLLite:
https://developer.android.com/training/basics/data-storage/databases.html
Have you tried serialization? Put the informations in a file, like a text file, then simply un-serialize it and take back the informations. You can always encrypt it if you don't want anyone to change the datas, like a real game save file.
I have a barcode that reads :
"SerialNumberALT09ProductNumber"
where ALT09 = Tab.
I read the number in to a JTextArea, if i write the number manually with the tab key on my keyboard i get a valid input i can then text.trim().split("\t");
to get a valid input to get respective serial number and product number. But when reading the barcode who sends ALT09 it does not read anything.
How do i get the JTextArea to accept ALT09 as Tab (or as alternative split on the location).
JTextArea is not getting Tab at all. Tab is interrupted by whole GUI interface to switch to next editable field. Of course you can bend this rule, intercept Tab on parent container and force it to send it to the child JTextArea and then you can even write your won method for KeyPressed event and insert Tab character into the text but it's good approach because it changes user experience. User expects Tab to go to next field but for this particular text area you say that it should be delimiter for your text? Another reason - Tab is similar for Space - so in user experience it's not clear was input right or not.
To avoid all these troubles why not take simple approach:
SerialNumber=ProductNumber
It is clear, visible, predictable, understandable and most off all - doesn't required your question ;)
JNI C code sends a java method the key pressed and the name/title of the window where the key was pressed/typed.
I have to store both the name of window and the key typed for later purposes when I want to know which key was pressed at what time (I also store the time) and in which window. For example let the title of the window be User grassPro - Stack Overflow and I had typed something like difference hashtable hashmap in the search bar.
Later I want to retrieve these i.e the keys typed with the window title. I am able to get both these details,but I do not understand how do I store them . Should I store them in separate lists,use a tree or what ?
I think of storing each key typed with the name of the window. I do not like this approach but is there a better one ? If there is a thought the please share it.
Note : Finally I have to write the data to a log file
I'm not familiar with JNI C, but it sounds like you should make a class with the 3 variables you want to save, and then make a list of this class.
I am a huge newbie and I have a program that normally prints items to the Java console window. I would like this program to become a window in which the user can interact with. The reason why I have not resorted to dialog boxes and panels is because this program require multiple prints to the console window. A traditional dialog box does not continuously update or compound on data that has already been printed on the box. I realize that there is another way of doing this by creating a program that mimics the Java console window. Because I am a noob, all of the java console redirecting questions and answers on this site have blown over my head. Can anyone please help me?
See maybe How to Use Editor Panes and Text Panes will be helpful and give you some ideas.
The short answer is, every time you want to update the contents of a text box, call the setText function again. There's no "append" function on the contents: you have to give the entire contents each time. If you want something that mimics a console window, where messages continue to scroll, the simplest thing to do is to keep the entire contents in a StringBuilder. Each time you get new text append to the StringBuilder, then setText(myStringBuilder.toString).
You could, I supppose, write mybox.setText(mybox.getText()+"new contents"). That would be a little inefficient but probably not a big deal.
I don't know exactly what you're up to, but trying to redirect console output to a text box sounds like more nuisance that it's worth. Just put your data in the text box: don't write it somewhere else, then try to get it back and put it where you want it. I suppose if you have thousands of lines of code writing to the console and now you want it to go a text box, there might be value in not having to change all that code. But the structure of a console app is so different from the structure of a GUI app that changing the output statements would probably be the least of the things you'd have to rework.