Page 2 of 2 FirstFirst 12
Results 21 to 30 of 30
  1. #21
    Join Date
    Apr 2010
    Posts
    59
    Rep Power
    0

    Default

    Hi Sno. Thank you for your post.

    I am not sure what your code would achieve?

    The problem I am having is in setting up a reset variable.

    When the private void jTextArea1FocusGained(java.awt.event.FocusEvent evt) { is activated it does not seem to know any variables that are imported into it (in this case reset).

    I have tried initialising a reset variable in various parts of the program.

    I need to somehow get the reset variable into the private void jTextArea1FocusGained.

  2. #22
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,233
    Rep Power
    7

    Default

    Now that you understand the basics of using a FocusListener you can check out Text Prompt for a more comprehensive solution to the requirement.

    this has always allowed me to compare, because it is now a string for use,
    There is no need to cast the value to a String since the getText() method already returns a String.

  3. #23
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,802
    Rep Power
    19

    Default

    Nice.
    :)
    ...blimmin character limit...

  4. #24
    Sno's Avatar
    Sno
    Sno is offline Senior Member
    Join Date
    Apr 2010
    Posts
    196
    Rep Power
    5

    Default

    camickr:
    hm, I attempted to do the same thing a few days ago and it wouldn't pass unless i casted the text from the box...

    AJArm:
    is reset public or private?

  5. #25
    Join Date
    Apr 2010
    Posts
    59
    Rep Power
    0

    Default

    Question - is reset public or private?

    Answer - I am not sure! I don't know how to make a variable so it can be accessed by all parts of the program.

  6. #26
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,802
    Rep Power
    19

    Default

    You're going to have to post some code if you want to get your thing working (rather than using camickr's stuff above). For example this should work:
    Java Code:
    public class SomeClass {
        private boolean reset;
    
        // Lots of your code in here//
        private void jTextArea1FocusGained(java.awt.event.FocusEvent evt) {
            // You can access reset in here.
        }
    }

  7. #27
    Sno's Avatar
    Sno
    Sno is offline Senior Member
    Join Date
    Apr 2010
    Posts
    196
    Rep Power
    5

    Default

    place this after your main class,

    Java Code:
    public static int result;
    Declaring Global Variables in Java

  8. #28
    Join Date
    Apr 2010
    Posts
    59
    Rep Power
    0

    Default

    Thank you for your messages.

    But how would I get the value of the variable reset? Get and set?

  9. #29
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,802
    Rep Power
    19

    Default

    It's an attribute of whatever class the focus gained method is in.
    I think you might want to start from some basic Java if you're having problems with that. Put Swing aside until you're confident about classes and objects and how they fit together.

    ETA: Oh, and global variables are a Bad Thing. Global constants, OK, but variables? Nope.

  10. #30
    Sno's Avatar
    Sno
    Sno is offline Senior Member
    Join Date
    Apr 2010
    Posts
    196
    Rep Power
    5

    Default

    You're absolutely right tolls, It's just a very bad habit of mine, coming out of college. making everything global was always easier at times...

Page 2 of 2 FirstFirst 12

Similar Threads

  1. How to Highlight a String in JTextArea
    By ramvaidhya in forum AWT / Swing
    Replies: 6
    Last Post: 12-31-2008, 07:23 AM
  2. How to select/highlight an entire row in JTextPane
    By Maladict in forum AWT / Swing
    Replies: 6
    Last Post: 08-15-2008, 09:21 AM
  3. How to highlight text by drag and selection
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-25-2008, 10:35 AM
  4. How to select/highlight an entire row in JTextArea
    By Valeriano in forum AWT / Swing
    Replies: 2
    Last Post: 05-28-2007, 11:20 AM

Posting Permissions

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