Results 1 to 14 of 14
  1. #1
    Ak-Emm is offline Member
    Join Date
    Aug 2008
    Posts
    17
    Rep Power
    0

    Question code for cleaning variables?

    Question to experts

    what i wanted to know if there is a code to erase variables
    like when you enter data or numbers in a text field

    and you want to clear that error by pressing either (A/C) or (erase) buttons

    your Help

    thanks

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Hm, I'm not sure I fully understand here. Do you mean to clear the contents of a JTextField? If so, there's the setText("") method that would work nicely. If not, then you'll have to clarify this a bit more. HTH.

  3. #3
    Ak-Emm is offline Member
    Join Date
    Aug 2008
    Posts
    17
    Rep Power
    0

    Default

    yes exactly
    that method is what i mean

    string s
    get.txtValueA
    Value A=Integer.parseInt sort of

    the code to clear the text fields

    thanks if you have the solution

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    um... that is the solution. You call setText("") on your JTextField when you want to clear it.

  5. #5
    Ak-Emm is offline Member
    Join Date
    Aug 2008
    Posts
    17
    Rep Power
    0

    Default

    Just relieved thanks

    ok so how would you assign this to a button function ? with the example above?

  6. #6
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    Quote Originally Posted by Ak-Emm View Post
    ok so how would you assign this to a button function ? with the example above?
    Most folks use an IDE, such as NetBeans to write the code. In NetBeans, you click on the button, and right click to generate a function. You put your calls to whatever you need inside the function that NetBeans writes

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Ak-Emm View Post
    Just relieved thanks

    ok so how would you assign this to a button function ? with the example above?
    Since you are just now learning Swing, I advise against using NetBeans or similar to generate Swing code. Better at this stage would be for you to create all your own Swing code, and later after you are more familiar with what Swing does, then fine go ahead and use NetBeans.

    But as to your question, you will need to add an ActionListener to the button that has the code that you want processed when the button is pressed. To learn how to do this (and to learn more about Swing in general) please check out the Sun Swing tutorials:

    The Sun Swing Tutorials
    The ActionListeners tutorial

  8. #8
    Ak-Emm is offline Member
    Join Date
    Aug 2008
    Posts
    17
    Rep Power
    0

    Default

    meaning i type the code after assigning the code generation of the text variables
    i.e txtNumber 1
    txtNumber2 when i right click the button (erase) for example

  9. #9
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    Quote Originally Posted by Fubarable View Post
    Since you are just now learning Swing, I advise against using NetBeans or similar to generate Swing code. Better at this stage would be for you to create all your own Swing code, and later after you are more familiar with what Swing does,
    Clearly my friend @Fubarable and I have a different viewpoint.
    Clearly you can do what he suggests. But I find a lot of Swing to be ugly and repetitive, so I much prefer to have the IDE solve the boring administrative tasks and focus on the domain stuff.

    YMMV, of course

  10. #10
    Ak-Emm is offline Member
    Join Date
    Aug 2008
    Posts
    17
    Rep Power
    0

    Default

    thanks ill check it out now

  11. #11
    Ak-Emm is offline Member
    Join Date
    Aug 2008
    Posts
    17
    Rep Power
    0

    Default

    oh That site ive tried to understand it through but still getting errors thats why im posting questions here through your expertise off course to understand better
    I use NetBeans 5.5 and Forte Java 4
    Last edited by Ak-Emm; 08-21-2008 at 10:11 PM.

  12. #12
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by fishtoprecords View Post
    But I find a lot of Swing to be ugly and repetitive, so I much prefer to have the IDE solve the boring administrative tasks and focus on the domain stuff. YMMV, of course
    I don't disagree here at all, and I think it is fine to use NetBeans to get away from some of the grunt work associated with Swing coding.

    But having said that, I know that I have seen (and I'm sure that you have too) many posts in this and other Swing fora filled with problems from folks who use NetBeans to generate their Swing code but who run into brick walls because they just don't understand what that Swing code is doing. All I'm saying is to learn Swing for say a month or four, and then, fine, let NetBeans do the dirty work.

  13. #13
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default

    I've found that knowing what goes on under the covers to be very useful. Keeps it from being FM.

  14. #14
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

Similar Threads

  1. Collecton of Variables
    By c26354 in forum New To Java
    Replies: 12
    Last Post: 06-30-2008, 03:09 PM
  2. Using Static Variables
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-16-2008, 11:08 PM
  3. Initialize variables before use
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-22-2007, 11:22 AM
  4. Variables
    By mew in forum New To Java
    Replies: 3
    Last Post: 12-11-2007, 12:44 PM
  5. Replies: 1
    Last Post: 04-26-2007, 03:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •