Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Netbeans and java

  • 24-09-2014 8: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