Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #21 (permalink)  
Old 06-10-2008, 09:31 PM
Senior Member
 
Join Date: Jun 2008
Posts: 220
Fubarable is on a distinguished road
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.:
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 09:35 PM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #22 (permalink)  
Old 06-10-2008, 10:14 PM
Member
 
Join Date: Apr 2008
Posts: 34
kewlgeye is on a distinguished road
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)
}
Bookmark Post in Technorati
Reply With Quote
  #23 (permalink)  
Old 06-10-2008, 10:38 PM
Senior Member
 
Join Date: Jun 2008
Posts: 220
Fubarable is on a distinguished road
* 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-11-2008 at 12:52 AM.
Bookmark Post in Technorati
Reply With Quote
  #24 (permalink)  
Old 06-11-2008, 09:15 AM
Member
 
Join Date: Apr 2008
Posts: 34
kewlgeye is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can i copy a folder from one place to another.. rajeshgubba New To Java 4 06-14-2008 03:21 AM
How to place the GUI components in correct order impact New To Java 2 05-04-2008 07:41 AM
How to place panel into frame vivek_9912 AWT / Swing 2 11-20-2007 12:21 AM
how to place a divider of the splitpane? christina New To Java 1 08-06-2007 08:41 PM
how to place an image in an applet paty Java Applets 2 08-04-2007 06:15 PM


All times are GMT +3. The time now is 12:38 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org