line break here
script>
2nd line break
3rd line break
4th line break
5th break line
6th break line
7th break line
import java.applet.*;
import java.awt.*;
import java.net.*;
// v1.0 Gethost applet 25th January 1997
// Purpose - this applet displays the hostname of the machine it is running
// on. If this is not available "unknown host" is displayed.
/*
* Copyright (c) 1997 Richard Everitt G4ZFE
* richard@babbage.demon.co.uk
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 675 Mass Ave, Cambridge, MA 02139, USA.
*
*
*/
// Font metrics stuff from "Exploring Java", O'Reilly p.338-339
public class gethost extends Applet
{
String hostname;
public void init()
{
try
{
InetAddress localAddress = InetAddress.getLocalHost();
hostname = localAddress.getHostName();
} catch(Exception e)
{
hostname = "Unknown";
}
}
public void paint(Graphics g)
{
FontMetrics fm;
// Draw the rectangle the text will appear in
g.drawRect(0,0,size().width-1,size().height-1);
// Choose a font
// Dialog, Helvetica, TimesRoman, Courier, Symbol
// should be available on all JAVA platforms
g.setFont (new Font ("Dialog",Font.BOLD,12) );
// Determine spacing info about the font
FontMetrics metrics = g.getFontMetrics ();
int fontAscent = metrics.getAscent();
int fontDescent = metrics.getDescent ();
int messageWidth = metrics.stringWidth (hostname);
// Centre the text in the middle of the rectangle
int startX = size().width/2 - messageWidth/2;
int startY = size().height/2 - fontDescent/2 + fontAscent/2;
// Display the hostname
g.drawString (hostname,startX, startY);
}
}