package org.json;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.*;
public class RealmName extends JPanel{
//标签
JLabel []label=new JLabel[]{
new JLabel("域名:"),new JLabel("IP:")
};
//文本框
JTextField []textField=new JTextField[]{
new JTextField(""),new JTextField("")
};
JButton button=new JButton("解析");
public RealmName(){
this.setLayout(null);
//
for(int i=0;i<label.length;i++){
label[i].setBounds(10,20+i*50,50,40);
label[i].setHorizontalAlignment(JLabel.CENTER);
this.add(label[i]);
textField[i].setBounds(50, 20+i*50, 200, 40);
this.add(textField[i]);
}
button.setBounds(100, 120, 60, 40);
button.addActionListener(new ButtonListener());
this.add(button);
}
private class ButtonListener implements ActionListener{
public void actionPerformed(ActionEvent e){
ButtonAction();
}
}
String realmName=null;
public void ButtonAction(){
realmName=textField[0].getText();
InetAddress ip=null;
try{
ip = InetAddress.getByName(realmName);
}catch(UnknownHostException e){
e.printStackTrace();
}
textField[1].setText(ip.getHostAddress());
}
public static void main(String[]args){
JFrame frame = new JFrame();
RealmName panel=new RealmName();
frame.add(panel);
frame.setTitle("域名/IP地址装换");
frame.setBounds(300, 200, 260, 200);
frame.setVisible(true);
frame.setResizable(false);
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.*;
public class RealmName extends JPanel{
//标签
JLabel []label=new JLabel[]{
new JLabel("域名:"),new JLabel("IP:")
};
//文本框
JTextField []textField=new JTextField[]{
new JTextField(""),new JTextField("")
};
JButton button=new JButton("解析");
public RealmName(){
this.setLayout(null);
//
for(int i=0;i<label.length;i++){
label[i].setBounds(10,20+i*50,50,40);
label[i].setHorizontalAlignment(JLabel.CENTER);
this.add(label[i]);
textField[i].setBounds(50, 20+i*50, 200, 40);
this.add(textField[i]);
}
button.setBounds(100, 120, 60, 40);
button.addActionListener(new ButtonListener());
this.add(button);
}
private class ButtonListener implements ActionListener{
public void actionPerformed(ActionEvent e){
ButtonAction();
}
}
String realmName=null;
public void ButtonAction(){
realmName=textField[0].getText();
InetAddress ip=null;
try{
ip = InetAddress.getByName(realmName);
}catch(UnknownHostException e){
e.printStackTrace();
}
textField[1].setText(ip.getHostAddress());
}
public static void main(String[]args){
JFrame frame = new JFrame();
RealmName panel=new RealmName();
frame.add(panel);
frame.setTitle("域名/IP地址装换");
frame.setBounds(300, 200, 260, 200);
frame.setVisible(true);
frame.setResizable(false);
}
}