📄 ch8_e8_28.java
字号:
import java.awt.*;
import java.awt.event.*;
import java.net.*;
public class ch8_e8_28
{
public static void main(String args[])
{
new MyFrame();
}
}
class MyFrame extends Frame implements ActionListener
{
TextField hostInputTfd = new TextField(50);
Label ipOutputLbl = new Label();
MyFrame()
{
super("主机与IP");
ipOutputLbl.setText(" ");
add(hostInputTfd,BorderLayout.NORTH);
add(ipOutputLbl,BorderLayout.CENTER);
pack();
show();
hostInputTfd.addActionListener(this);
addWindowListener(new winClose());
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource() == hostInputTfd)
{
try
{
InetAddress ip = InetAddress.getByName(
hostInputTfd.getText().trim());
ipOutputLbl.setText(ip.toString());
}
catch(UnknownHostException uhe)
{
ipOutputLbl.setText("未找到指定的主机。");
}
}
}
}
class winClose extends WindowAdapter
{
public void windowClosing(WindowEvent we)
{
we.getWindow().dispose();
System.exit(0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -