/******************
名前解決プログラムGUI
******************/
//パッケージのインポート
import java.awt.*;
import java.awt.event.*;
import java.net.*;

class MyFrame extends Frame implements ActionListener{
	
	//結果のIPアドレスを出力するTextArea
	TextArea IP = new TextArea();
	//結果のホストnameを出力するTextField
	TextField HOST = new TextField();
	//問い合わせすすURLまたはAddressを入力するTexiField
	TextField query = new TextField();
	//問い合わせ開始のボタン
	Button btn = new Button("問い合わせ");
	//クリアボタン
	Button clear = new Button("クリア");
	
	//Label類
	Label lb1 = new Label("Host Name/IP Address");
	Label lb2 = new Label("ANS(HostName)");
	Label lb3 = new Label("ANS(IPaddress)");
	//下半分のPanel
	Panel under = new Panel(new GridLayout(1,2));
	//上半分のPanel
	Panel up    = new Panel(new GridLayout(6,1));
	
	//コンストラクタ
	MyFrame(String name){
		//スーパークラスのコンストラクタ呼び出し
		super(name);
		
		//Frame諸設定
		setLayout(new BorderLayout());
		setSize(300,300);
		setLocation(200,200);
		
		//Frameへpanelの配置
		add("Center",up);
		add("South",under);
		
		//upパネルへ部品の配置
		up.add(lb1);
		up.add(query);
		up.add(lb2);
		up.add(HOST);
		up.add(lb3);
		up.add(IP);
		//underパネルへボタンの配置
		//under.add(IP);
		under.add(btn);
		under.add(clear);
		
		//ActionListenerへ登録
		btn.addActionListener(this);
		clear.addActionListener(this);
		//Frame表示
		setVisible(true);
	}
	
	public void actionPerformed(ActionEvent e){
		if(e.getSource()==clear){
			HOST.setText("");
			IP.setText("");
			query.setText("");
		}else{
			try{
				InetAddress ans = InetAddress.getByName(query.getText());
				HOST.setText(ans.getHostName());
				IP.setText(ans.getHostAddress());
			}catch(UnknownHostException ue){
				HOST.setText(query.getText());
				IP.setText("Could not find URL :"+query.getText());
			}
		}
	}
}

class Name_Resolution_GUI{
	public static void main(String[] args){
		MyFrame mf = new MyFrame("名前解決アプリ");
	}
}
