Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Netbeans and java

  • 24-09-2014 09:02PM
    #1
    Closed Accounts Posts: 431 ✭✭


    Can anyone help me out I'm looking to build a simple application that has a jtextfield so the user enters a number and the value is saved as a variable. How would I archive this?


Comments

  • Registered Users, Registered Users 2 Posts: 291 ✭✭Seridisand


    Can anyone help me out I'm looking to build a simple application that has a jtextfield so the user enters a number and the value is saved as a variable. How would I archive this?

    Can you clarify "archive"?

    Do you mean you want store the value so that it can be retrieved? You would need to either use a back end storage like a database or write the variable value to a file and then read the file from the application.


  • Closed Accounts Posts: 431 ✭✭whats newxt


    Seridisand wrote: »
    Can you clarify "archive"?

    Do you mean you want store the value so that it can be retrieved? You would need to either use a back end storage like a database or write the variable value to a file and then read the file from the application.

    Sorry I'm on the phone I mean achieve. Basically I want to take whatevers in the jtextfield and save it as a variable and then print it out on screen.


  • Registered Users, Registered Users 2 Posts: 291 ✭✭Seridisand


    If you want to accept it as a string you could do it like this
    String yourString = yourJTextField.getText();
    
    Or like this as an integer value
    int myInt = Integer.parseInt(yourJTextField.getText());
    

    You'll need to create some sort of Action Event - button event ideally to trigger the variable value being set to the value of the JTextField.

    http://docs.oracle.com/javase/tutorial/uiswing/events/intro.html


  • Closed Accounts Posts: 431 ✭✭whats newxt


    Seridisand wrote: »
    If you want to accept it as a string you could do it like this
    String yourString = yourJTextField.getText();
    
    Or like this as an integer value
    int myInt = Integer.parseInt(yourJTextField.getText());
    

    You'll need to create some sort of Action Event - button event ideally to trigger the variable value being set to the value of the JTextField.

    http://docs.oracle.com/javase/tutorial/uiswing/events/intro.html

    Thanks very much that works perfect i have another question whats the best event to use on the main window to trigger the event code? i want everything to update without pressing a button


  • Registered Users, Registered Users 2 Posts: 291 ✭✭Seridisand


    Have a look at the link in my last post, you could add a component/frame/focus event listener to update the main frame, but I'd recommend using a component like a button event to trigger the update


  • Advertisement
Advertisement