wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes A few questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "A few questions" Watch "A few questions" New topic
Author

A few questions

Pete Palmer
Ranch Hand

Joined: Oct 21, 2008
Posts: 74
Hi,

1) On the network client gui, the user can enter the port number and IP address. I just want to confirm that the IP address string could either be an actual IP address (xxx.xxx.xxx.xxx) or the string "localhost". Is this correct?

2)


The ConfigurationDialog provides a dialog window to the user to enter the ip address, port number and database location based on the applicationMode ( network, standalone or server )and also two buttons, Connect and Exit.
Connect will validate the user data and return back to the MainWindow. Exit will set local flag (userSelectToExit) and return back to the MainWindow.
The method userExited() effectively returns the value of userSelectToExit flag.

In the MainWindow(), the userExited() is invoked and if true, will perform "System.exit(0)" to exit the application.
However, most of the times, the returned value from userExited () is correct ie set to reflect whether user selected Connect or Exit, but on the odd occasion, it is incorrect. Any possible explanation for this behaviour ?

3) Finally, when I exit the application, I perform "System.exit(0)". The window closes, however, I have noticed under the Windows Task Manager, the "jawac.exe" process assoicated with the run does not terminate. I have had to manually end the process. Any possible explanation for this behaviour ?

As always any help would be appreciated.

Regards
Pete



K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2242
    
    7

Hello there again.

Ok Q1 - the answer really depends on how you "bind" the server. I recommend using IP address. One experiment you may want to do to verify this is to start your server saving "localhost" and try connecting client using IP address "127.0.0.1"... this would in fact NOT connect.

Q3 - did you set the EXIT_ON_CLOSE for the main window?

Q2 - one question. In your setup triggering "exit" will display the main window?
Connect will validate the user data and return back to the MainWindow. Exit will set local flag (userSelectToExit) and return back to the MainWindow.


In your main window - when are you executing userExited() method? What "return" value are you referring to?

K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5139
    
  12

Hi Pete,

Little remark: xxx.xx.x.x could also be a valid ip-address

Kind regards,
Roel


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Pete Palmer
Ranch Hand

Joined: Oct 21, 2008
Posts: 74

Appologises for asking three questions in one post. Will not happen again.

Hi K,

I did take up your advice of using a dialog and it is much simpler and works a treat...well almost except for Q2.

Q1) I actually support both localhost, hostname & IP address.
using 127.0.0.1 url is rmi://127.0.0.1:1099/RemoteBusinessServiceObject
using localhost url is rmi://localhost:1099/RemoteBusinessServiceObject

Q3 - did you set the EXIT_ON_CLOSE for the main window?

Yes I do as shown here :-


Q2 - one question. In your setup triggering "exit" will display the main window?


The MainWindow is only displayed if execution gets past line 21 in the code shown above. So if clientConfiguration.userExited() returns a "true", I perform System.exit(0) and exit the application before the MainWindow is displayed. Is this answering your question ?

In your main window - when are you executing userExited() method? What "return" value are you referring to?

The userSelectToExit flag is private to ConfigurationDialog class, which provides the user with the facility to enter ip address, db location, port number AND also two buttons - Connect & Exit. If the user selects Connect, the user data is validated ( & assuming thats ok), the userSelectToExit flag is set to TRUE, close the ConfigurationDialog window and return. If the user selects Exit, the userSelectToExit flag is set to FALSE, close the ConfigurationDialog window and return. The method userExited() will return the value of userSelectToExit. It is the value of userSelectToExit that I refer to as the return value.

Hi Roel,
Thank you for the valid comment.


Regards

Pete
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5139
    
  12

Hi Pete,

Seems you are following the example from Andrew's book.

Pete Palmer wrote:
If the user selects Connect, the user data is validated ( & assuming thats ok), the userSelectToExit flag is set to TRUE, close the ConfigurationDialog window and return. If the user selects Exit, the userSelectToExit flag is set to FALSE, close the ConfigurationDialog window and return.


I would expect it to be just the other way round: if user hits Exit, userSelectToExit is set to true instead of false. But i would guess that's just a flaw in your explanation The odd occasion the return value is incorrect, could it be the closing of the ConfigurationDialog by pressing the X in the upper right corner? The only explanation i can think of, because if you hit a button always the same code is executed, so if it's correct the first time, it should always be correct.
Pete Palmer
Ranch Hand

Joined: Oct 21, 2008
Posts: 74
Hi Roel,

My original approach was using as per the book but I had trouble with JOptionPane. So I changed the approach to use JDialog as suggested by K.
if it's correct the first time, it should always be correct.

Agree. Can you see anything wrong with the code below ? As mentioned, this problem is very occasional.

Regards

Pete

PS. As you can see you were correct w.r.t userExitSelected setting.

Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5139
    
  12

off-topic: why adding the networkClientConfigurationPanel twice?



what happens if you just close the dialog by the X in the upper right corner?

do you have any more info about when the odd thing happens? Maybe after first entering some invalid parameters? Because just based on your code i could not see anything wrong

i hope CONNECT and EXIT refer to 2 different strings

Now i'm gonna watch belgian football and record MotD
Pete Palmer
Ranch Hand

Joined: Oct 21, 2008
Posts: 74
Hi Roel,

off-topic: why adding the networkClientConfigurationPanel twice?

no reason, just guilty of poor coding

what happens if you just close the dialog by the X in the upper right corner?

dialog closes nicely.

i hope CONNECT and EXIT refer to 2 different strings

Indeed they are.
private static final String CONNECT = "Connect";
private static final String EXIT = "Exit";

I can't get it to fail now ... so I think I will put this issue on monitor.

Now i'm gonna watch belgian football and record MotD

What about the championship at crucible ? Enjoy

Pete

Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5139
    
  12

dialog closes nicely.


And is it handled as the user choose to exit?

What about the championship at crucible ?


I'll spend a lot of time coming 2 weeks in front of the tv, hope i don't have to press to often the red button to follow it on another bbc channel than bbc 1 or 2
Pete Palmer
Ranch Hand

Joined: Oct 21, 2008
Posts: 74
Good Day Roel,

And is it handled as the user choose to exit?

Yes but not nicely. The userExitSelected was initialised to true.
private boolean userExitSelected = true;
So when the user did close the window via "X", the userExitSelected value read back in the MainWindow was effectively correct. However, I have added to the following :-


Pete
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: A few questions
 
Similar Threads
User Input Parameters
Expected behaviour of server when no network connection?
Urlybird 1.2.1 - Clarifying network/standalone requirement
java.net Socket port number question
Questions on suncertify.properties