Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Listener not listening to my event

Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to pass server name, user and password to connection string, I have preferences dialog with form and after clicking on the 'connect' button,ConnectionEvent(server,user,pass) is created connect() method is invoked and in my Database class, I am listening and getting input data that will be passed to my connection string.
Thus, prefsListener is not working at all, I need some help here.
I will try to put just the right amount of code for you to get the idea of this, and where the possible mistake lies.

Ranch Hand
Posts: 261
Android Angular Framework Spring AngularJS Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, Milan:

Based on just what I see there, the prefs listener is not going to be in synch with the "NULL, NULL, NULL" print out.  To me, it looks like your prefs listener gets established in the same thread as the "println", but it is not going to be called until you later carry out some user action.  This may be a kind of subtle point.  Hopefully, I am not overlooking anything in your code, and I will try and explain it differently.

When you call "connect", one thing that is done is to set a prefs listener (now I will plead some ignorance here, because I am not familiar with PrefsListener.  I will assume it works like other listeners in the Java Swing ecosystem).  After setting that listener (which is just like setting any field or indeed, just like setting the action listener above), the "connect" code proceeds to print the server, username and password immediately.  Then it tries to assemble a JDBC URL, etc.  But you must keep in mind that the "connectionEventOccurred()" method won't be invoked until this "prefs" event is posted.  Nothing has invoked that method (or is extremely unlikely to have--let's hedge bets ;-)  ) by the time you get to the println and the uses of those variables.

I would recommend that you instead move the code following the body of your anonymous inner class inside the PrefsListener inner class implementation.  I think leaving the "forName" outside is not too bad, because you won't need to do that for every connection.  But the rest is in the wrong place.

rubbery bacon. rubbery tiny ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic