• Post Reply Bookmark Topic Watch Topic
  • New Topic

inner anonymous class in a actionlistener  RSS feed

 
Scott Stephens
Greenhorn
Posts: 23
Debian Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using the DJWebbrowser in a Java Swing Application that I am working on


and am sending data from a Google Map API , Distance Matrix Query with following code


The DJBrowser Class that invokes the browser



has a Browser Listener Implementation public commandReceived(

I haven't found a way to access a class property from the class that invoked the web browser, because the above WebBrowserAdapter is in an anonymous Inner Class.´I would like to have the distance that is sent from the Javascript to the application be passed on to the class member "distance" that in the invoking class. I Need some help.
 
Paul Clapham
Sheriff
Posts: 22823
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a bit confused, but I'll take a shot at answering.

It would be easiest if the data you wanted to get at in your createContent() method was actually a member of the same class that method is a member of. And if I understand your question right, that class is an anonymous inner class, right? But that shouldn't be a problem, an anonymous inner class can still have instance variables. Like so:



However the other part of the problem is that you want the variable to be assigned a value when the anonymous inner class instance is created. Normally you would do that in the constructor which builds the instance, but anonymous inner classes don't have constructors. There is a language feature which takes care of that problem, though, namely the instance initializer. You'd use it like so:



Another alternative is to use a named subclass of WebBrowserAdapter and to do the initialization in a suitable constructor.

Hope I got all the details right.

(By the way I have written working software which uses the DJ browser, it's a great tool.)

 
Mike. J. Thompson
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not totally clear where the 'distance' value from the Javascript is coming from, but the anonymous inner class can access all of the class members from the enclosing class, and any of the final local variables from the method it is called from. Can it get the 'distance' value from there?

For example:

 
Paul Clapham
Sheriff
Posts: 22823
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hopefully Mike's answer works for you, because it's a lot simpler than mine.
 
Scott Stephens
Greenhorn
Posts: 23
Debian Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My project is a taxi management module that manages planned trips that need the distance from a point A.
I guess I wasn't clear enough about the invoking class(class that implements an instance of the DJBrowser. I am trying to follow an MVC Approach and have a view class TripHandler that sets up the UI:

That means Class TripHandler implements the management view that invokes the BPanel Class that Returns the object browser. Because the Listener is in the static method util.BPanel.createContent(), with the inner class having access to the distance returned from the javascript, I don't know how to get the value of "distance" from the nested inner class from BPanel and assign it to member distance in the TripHandler class . It's probably really simple. Just don't know how to do it. I hope that makes it more understandable. Thanks for the replies.
 
Scott Stephens
Greenhorn
Posts: 23
Debian Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For those interested of Event handling in DJBrowser, I found the solution for my Problem.

1.) I needed to create a JWebBrowser object that I could use in the TripHandler class. In order to do this I needed to modify the BPanel like this:

I removed the WebBrowserlistener that was initially in the BPanel class stuck in a nested anonymous class that I couldn't access. Because I now have an object in my TripHandler class:


I could add the listener and get the "destination" that was sent from the browser via JavaScript:

the last step was to extend my TripHandler class with a WebBrowserListener provided from DJBrowser
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!