Get input from a jtextfield [closed] - java

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
How would I get user input from a jtextfield in my GUI? Would I use java.util.Scanner or another class?
JTextField a = new JTextField("Input Here")
//Put calculation formula here

A GUI is an event driven environment. You will need to listen to the events that the component is producing.
For example, JTextField raises ActionEvents (amongst others) which tells you that the user has (on most systems) pressed the Enter key.
Start by taking a look at How to use Textfields
When your ready, you can use getText to get the String value that the user entered...

Related

Java: Set the default button [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
To set the default button to suppose jButton4 the following code has to be used: this.getRootPane().setDefaultButton(jButton4); But where to add this?
What all I tried:
I tried to add it in main function but it gave me an error, I tried to put it inside the button action performed block but it did not work, I tried to put it just before the main function it gave me an error.
Question: So where do I put this line of code so it works? I am using Netbeans GUI to make the program.
You could add this line everywhere you want to set the default button (a button click, where you create your UI etc.).
I think a nice place is where you create your UI elements.
In your case it would be, just after initComponents();

I need user input to puts a date where the tokens (/) are automatically put in [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Sorry in advance if this was already answered but what i need is for an user to input a date in this format AAAA/MM/DD. But when the user puts the year (4 numbers) the token(/) automatically appears not giving the user user the option to put it himself.
And the next question is how do i make the user only to input numbers without thinking in the before checks.
This in advance
Try MaskFormatter:
MaskFormatter formatter = new MaskFormatter("####/##/##");
JFormattedTextField textField = new JFormattedTextField(formatter);
'#' stands for only number input
I think you cannot do that at least in a multiplatform standard.
More info here but I don't think it will help. http://docs.oracle.com/javase/6/docs/api/java/io/Console.html
Maybe there are JNI multiplatform consoles somewhere that support it.

ON/OFF flip button in Swing [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I wish to create a button exactly same as this (from iOS5).
You will have two images, for ON and for OFF.
Whenever you click the button, you will switch images with button.setImage(..).
Swing constraints:
Button will still be rectangular, even though the image is oval
Animation possible, but quite hard AFAIK. From the way you asked your question, I think it will take you a while to study swing more
In swing, there is JToggleButton which can have two status. However, if you want the button of the same shape and the same visual effect, you should implement it.

Is it possible to increment a letter with a press of a button?/ [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to increment alphabets in a text field with the press of a button.
Like if the text field is 'A' then the next letter should be 'B' after I press the button.
Is it possible?
Without going into Java GUI with Swing etc, (RTM), here's a clue:
System.out.println((char) ('A'+1));
outputs B
yes, you would get the current character's keycode, delete the character, increment the keycode by one and create that character.

How to create a suggestion box [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I was developing an java swing application to add view and modify the list of medicines.While adding the medicines it should show the list from the database(like google search box).For example if we press "p" it should show 'paracetamol' from the database.
You should implement a change listener on the text input box, when the text is changed, run a query to the database with the contents of the input box.

Categories

Resources