• Post Reply Bookmark Topic Watch Topic
  • New Topic

Main Class JFrame, Second Class - Business Logic. Business Class assign values to JFrame fields

 
Peter Brown
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I believe I need to instantiate a reference to the JFrame class in the UrlConnect Class - I do not how to do this. My current code gives me an NPE. I have tried to place the reference in the default constructor - no change. Creating a new instance - does not assign the values to the existing JFrame Gui. They are both in the same package. I really need a working example based on the code below. I have read posts and articles and am no clearer in what I need to do. I am using Eclipse VEP. Thank you. [The xml etc works without issue]



Business Class
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A couple of this.

1. Why does your UrlConnect class need a reference to your Gui?

2. Question 1 aside, if you need it, just pass it in...

 
Peter Brown
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the very quick reply.

I (understood) needed it as the xml returned in the second class has values that I want to populate certain textfield's text with. Is my thinking convoluted - is there a better way?

Also in the jFrame getJButtonVerify() where it says



what do I put between the ( and )? I have tried Gui thisClass, this without success.

Thank you
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, what I would do is have your UrlConnection class pass back the information you need for your text field(s). So you're code might end up looking something like...



Then modify your UrlConnection class to return SomeObjectThatHoldsTheDataYourNeed. The you don't need to pass your Gui around at all. That's the trick. Pass data around, not Gui's. ;)
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know that this doesn't directly involve your question, but you may want to consider looking into and using a SwingWorker object here so that you can do your URL connecting and such in background thread. That way it won't freeze your GUI while it's trying to do its task.
 
Peter Brown
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gregg - you are right of course.

For closure I would appreciate how to pass the gui reference in UrlConnect urlconn = new UrlConnect(); to the second class as I still draw a blank on how to to do this.

Thank you.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter Brown wrote:Gregg - you are right of course.

For closure I would appreciate how to pass the gui reference in UrlConnect urlconn = new UrlConnect(); to the second class as I still draw a blank on how to to do this.

Thank you.





So you can't make a reference to 'this' from an anonymous inner class, which is what your actionPerformed method is residing in. From your actionPerformed() method, you need to simply call another method, and then you can pass 'this' into your UrlConnect constructor. Code shown above as an example.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!