📄 hostname.java
字号:
/* HostName.java * * Raven * raven@ravenmatrix.com * http://www.ravenmatrix.com * * * 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 at http://www.gnu.org */import java.applet.*;
import java.awt.*;
import java.net.*;
public class HostName extends Applet
{
String NameOfHost;
public void init()
{
try
{
InetAddress localAddress = InetAddress.getLocalHost();
NameOfHost = localAddress.getHostName();
}catch(UnknownHostException e)
{
NameOfHost = "Unknown";
}
}
public void paint(Graphics g)
{
String VisitorMessage = "Welcome to Code Collection visitor from: "+NameOfHost;
g.setFont(new Font("Courier", Font.PLAIN, 12));
FontMetrics fm = g.getFontMetrics ();
int vmWidth = fm.stringWidth(VisitorMessage);
Dimension aSize = size(); // call getSize() in Java 1.2
int x = aSize.width/2 - vmWidth/2;
int y = aSize.height/2;
g.drawString (VisitorMessage, x, y);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -