📄 inetaddress.java
字号:
import java.net.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Inetaddress extends JFrame
{
private JButton ok,cancel,exit;
private JLabel InputLabel,OutputLabel,title;
private JTextField InputText,OutputText;
public Inetaddress()
{
setTitle("IP ADDRESS OF REMOTE HOST");
Container con=getContentPane();
con.setLayout(null);
setBounds(75,75,650,450);
con.setBackground(Color.DARK_GRAY);
title=new JLabel("IP ADDRESS OF REMOTE HOST");
title.setBounds(140,20,350,30);
title.setForeground(Color.ORANGE);
title.setFont(new Font("Times Roman",Font.BOLD,20));
con.add(title);
InputLabel=new JLabel("Enter the Name Of Computer or URL :");
InputLabel.setFont(new Font("Times Roman",Font.BOLD,14));
InputLabel.setBounds(50,90,290,30);
InputLabel.setForeground(Color.ORANGE);
con.add(InputLabel);
OutputLabel=new JLabel("IP ADDRESS :");
OutputLabel.setFont(new Font("Times Roman",Font.BOLD,14));
OutputLabel.setBounds(50,180,290,30);
OutputLabel.setForeground(Color.ORANGE);
con.add(OutputLabel);
InputText=new JTextField(15);
InputText.setFont(new Font("Times Roman",Font.BOLD,14));
InputText.setBounds(360,90,230,30);
con.add(InputText);
OutputText=new JTextField(15);
OutputText.setVisible(false);
OutputText.setFont(new Font("Times Roman",Font.BOLD,14));
OutputText.setBounds(360,180,230,30);
con.add(OutputText);
ok=new JButton("Find");
ok.setFont(new Font("Times Roman",Font.BOLD,14));
ok.setBounds(240,240,80,40);
con.add(ok);
cancel=new JButton("Cancel");
cancel.setFont(new Font("Times Roman",Font.BOLD,14));
cancel.setBounds(340,240,100,40);
con.add(cancel);
exit=new JButton("Exit");
exit.setFont(new Font("Times Roman",Font.BOLD,14));
exit.setBounds(460,240,80,40);
con.add(exit);
BHandler bh=new BHandler();
ok.addActionListener(bh);
cancel.addActionListener(bh);
exit.addActionListener(bh);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setResizable(false);
}
private class BHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String url;
if(e.getSource()==ok)
{
url=InputText.getText();
if(InputText.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"Enter The Host Name","Error",JOptionPane.ERROR_MESSAGE);
}
else
{
try
{
InetAddress address=InetAddress.getByName(url);
String IP=address.getHostAddress();
OutputText.setVisible(true);
OutputText.setText(IP);
}
catch(UnknownHostException u)
{
System.out.println("Unknown Host Name "+u);
}
}
}
if(e.getSource()==cancel)
{
InputText.setText("");
OutputText.setText("");
}
if(e.getSource()==exit)
{
System.exit(0);
}
}
}
public static void main(String[] args)
{
Inetaddress ip=new Inetaddress();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -