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.
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.
If a chicken that is half full crosses the road, will anyone hear it?