getipaddr.java
来自「java课件 java课件 java课件 java课件」· Java 代码 · 共 47 行
JAVA
47 行
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class GetIPAddr extends JFrame{
private JTextField jtf =new JTextField(20);
private JButton jbtn = new JButton("OK");
private JLabel jlb= new JLabel(" ");
private Container cp =null;
public GetIPAddr(){
super("Get IP Address");
cp = getContentPane();
cp.setLayout(new FlowLayout());
cp.add(jtf);
cp.add(jbtn);
cp.add(jlb);
jbtn.addActionListener(new ActionL());
setSize(300,200);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public class ActionL implements ActionListener{
public void actionPerformed(ActionEvent ae){
String addr = jtf.getText();
InetAddress address=null;
try{
address=InetAddress.getByName(addr);
jlb.setText("Name:"+address.getHostName()+
" IP Address:"+address.getHostAddress());
} catch(UnknownHostException e){
JOptionPane.showMessageDialog(
GetIPAddr.this,"Ip address of "+addr+" does not exists.");
}
}
}
public static void main(String args[]) throws Exception{
new GetIPAddr();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?