Page 2 of 2 FirstFirst 12
Results 21 to 24 of 24
  1. #21
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    OK, let's go over a few things, and you'll probably have to answer a few questions for me.

    1) Does the sunday class extend JFrame as well? Is the user interacting with this visual object and the results then are displayed in the results jframe? If so, do you have a sunday object displayed and finding that user interaction is not translating over to the results frame as expected? If so, you may have more than one sunday object, one visible, and one not visible, and unfortunately the invisible one is the one that results is interacting with.

    2) I'm not very familiar with NetBeans, but I would guess that that when you set a property of a component such as a JLabel, the property will be set at the JLabel's creation time. This means that if you set your JLabel's text to equal the rslt String, it is likely being set up when the program is being initialized and before any user has had a chance to interact with your program. I'm guessing that your JLabel's text needs to be set dynamically during the running of your program. For that to happen, you could do:

    a) create a public method in class results called something setLabel1Text(String text), i.e.:
    Java Code:
    public void setLabel1Text(String text)
    {
       jlabel1.setText(text);
    }
    b) pass a reference to your results class into your sunday class. This can be done either by a method or if results is the only location where sunday is created and displayed, then this could be done via the constructor, as I did in my example. Here is where you would pass a "this" object into sunday.
    c) have sunday call this method whenever an event occurs that makes it want to change what results should display. One place to call this would be inside of a button's actionPerformed method within its ActionListener.

    3) Make sure that there is only one sunday object and only one results object, and that the objects you expect to be dealing with each other are doing just that. You may want to sprinkle your code generously with some System.out.println("..."); where you print out your current location in the program and any key variable values, just to make sure that the code you think is being called is in fact being called. It's a primitive form of debugging.

    BTW, Java naming convention dictates that classes should have their first letters capitalized. One reason this is important is so that others reading your code will more easily understand it.
    Last edited by Fubarable; 06-10-2008 at 08:35 PM.

  2. #22
    kewlgeye is offline Member
    Join Date
    Apr 2008
    Posts
    34
    Rep Power
    0

    Default

    Yes the sunday class extends the JFrame

    when you ask do I have a sunday object, I don't understand.

    I used the system.out.println() to test
    my code. and within the sunday page, I received a null, and I don't know why, because it worked fine before.

    do you have a sunday object displayed? I don't know what that would look like, so I don't know what to say about that. I mean my sunday frame shows and I can interact with it.

    "Pass a reference to your results class into your sunday class. This can be done either by a method."

    I will use a method and place that method into the events section
    of the calculate button.


    The problem is, does the reference look something like this.
    if I used your example here (String aunder)

    //for the sunday class
    public void setLabel1Text(String aUnder)
    {
    jLabel1.setText(aUnder.results)
    }


    //for the results class
    public void setLabel1Text(String aUnder)
    {
    jLabel1.setText(aUnder)
    }

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

    Default

    * If aUnder is a String, then what is aUnder.results? That doesn't make much sense to me as the String class does not have a public results field.

    * Are you sure that you want to define setLabel1 within the sunday class? Are you trying to change one of sunday's labels too? From my understanding of your problem, you need to change a label that is within the results class, and if so this method needs to be defined within the results class and called from within the sunday class. It doesn't matter what the name of the parameter is, as you will stuff your string into the method when you call it.

    * By "displaying a sunday object" I meant displaying the JFrame that is a sunday object, simple as that.

    Sorry, but I'm still getting the sense that you need to review some basic Java before moving on with Swing. If you feel that you still desire to continue, you will probably need to post your code, but if you do, please use code tags, and try if possible to avoid posting NetBeans generated code. It was built to be read by a machine, not by humans.
    Last edited by Fubarable; 06-10-2008 at 11:52 PM.

  4. #24
    kewlgeye is offline Member
    Join Date
    Apr 2008
    Posts
    34
    Rep Power
    0

    Smile

    I figured it out. My original code before this whole post was ok. I figured that my referencing wasn't wrong, the whole time I was referencing a static to a non-static.

    I just needed to change the public ... to public static ... and on the sunday form

    just reference it that way like this

    result.jLabel1.setText("") with my variable inside that.

    I appreciate your help with this, and think that it is pretty safe to say that you are glad this was finally resolved :) I was getting tired with myself.

    Thank you for sticking through with this though.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. How can i copy a folder from one place to another..
    By rajeshgubba in forum New To Java
    Replies: 4
    Last Post: 06-14-2008, 02:21 AM
  2. How to place the GUI components in correct order
    By impact in forum New To Java
    Replies: 2
    Last Post: 05-04-2008, 06:41 AM
  3. How to place panel into frame
    By vivek_9912 in forum AWT / Swing
    Replies: 2
    Last Post: 11-19-2007, 11:21 PM
  4. how to place a divider of the splitpane?
    By christina in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 07:41 PM
  5. how to place an image in an applet
    By paty in forum Java Applets
    Replies: 2
    Last Post: 08-04-2007, 05:15 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
  •