Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servername

 
friso dejonge
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i am looking for a simple way to display the name of the server on my server gui. I know this is unnesseccary for the assignment, but it will help me.
Another question, are you allowed to use the System.getProperty methods to retrieve the user directory.
thanks,
friso
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi f,
i am looking for a simple way to display the name of the server on my server gui. I know this is unnesseccary for the assignment, but it will help me.

On the server GUI's JFrame just call super(title) (assuming you subclass JFrame) in the GUI constructor or call setTitle(title). Of course the title will have to be initialized to the server name. Or you could dedicate a JLabel somewhere on the GUI to display it.
Another question, are you allowed to use the System.getProperty methods to retrieve the user directory.

Of course. Feel free to use any tool available to you in the J2SE arsenal.
Hope this helps,
Michael Morris
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

On the server GUI's JFrame just call super(title) (assuming you subclass JFrame) in the GUI constructor or call setTitle(title). Of course the title will have to be initialized to the server name

I did the same, -- in networked mode, my client JFrame title bar showed "Fly High -- Connected to db.db on serverName:1099". In local mode, the title bar is "Fly High -- Connected to c:\userdir\db.db".
Eugene.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did the same, -- in networked mode, my client JFrame title bar showed "Fly High -- Connected to db.db on serverName:1099". In local mode, the title bar is "Fly High -- Connected to c:\userdir\db.db".

That's pretty cool.
Mark
 
friso jonge
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry guys,
you did indeed answer the question i asked. However i phrased it totally wrong. I know how to display something on a label or on a frame.
But.. my question was supposed to be
how can i extract the servername on the server ?
what java commands do i need to use ?
regards,friso
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friso,
Sorry for the confusion. What exactly do you mean by server name? Do you mean DNS or IP name? Do you mean host name? If you can clarify that, we'll see what we can come up with.
Michael Morris
 
Nate Johnson
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think he wants the name of the machine that the server is started on so that when you start the server at the command line, it will know what to call itself.
Ex: java -jar server.jar
When the GUI pops up for the server it says "I am remote.server.com" blah...
I dont know but I would guess if anything it would be in a System.getProperty()
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IMO, you're fine to just say "local connection" or "remote connection". My advice is to not waste your time on this: there are probably other parts of the test that would be a better time investment.
Best regards,
M, author
The Sun Certified Java Developer Exam with J2SE 1.4
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if he wants the local host name then he needs to get it thus:

On my workstation it returns MOMNT/192.168.0.101. I am behind a firewall with a lan IP as indicated and host name MOMNT.
Hope this helps,
Michael Morris
[ August 06, 2002: Message edited by: Michael Morris ]
 
friso dejonge
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Michael, this works fine
you code line would have to be extended with :
host = InetAddress.getLocalHost().getHostName();
but this is exactly what i wanted.
(nate, thanks as well for the further explanation)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic