Government Security
Network Security Resources

Jump to content

Photo

IP Lookup


  • Please log in to reply
No replies to this topic

#1 GT3X

GT3X

    Private

  • Members
  • 1 posts

Posted 04 May 2009 - 11:28 AM

Hi guys,
well this was one of my first java apps with an gui. I thougt it could be useful for some ppls whicht are starting java programming.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.net.*;


public class ip extends JFrame {
  // Anfang Attribute
  private JTextField jTextField1 = new JTextField();
  private JLabel jLabel1 = new JLabel();
  private JButton jButton1 = new JButton();
  // Ende Attribute

  public ip (String title) {
	// Frame-Initialisierung
	super (title);
	setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
	int frameWidth = 263;
	int frameHeight = 199;
	setSize(frameWidth, frameHeight);
	Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
	int x = (d.width - getSize().width) / 2;
	int y = (d.height - getSize().height) / 2;
	setLocation(x, y);
	Container cp = getContentPane();
	cp.setLayout(null);
	// Anfang Komponenten

	jTextField1.setBounds(24, 0, 201, 24);
	jTextField1.setText("bifrostworld.org");
	cp.add(jTextField1);
	jLabel1.setBounds(16, 112, 212, 48);
	jLabel1.setText("IP....");
	jLabel1.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
	cp.add(jLabel1);
	jButton1.setBounds(80, 48, 81, 41);
	jButton1.setText("getIP");
	jButton1.addActionListener(new ActionListener() {
	  public void actionPerformed(ActionEvent evt) {
		jButton1_ActionPerformed(evt);
	  }
	});
	cp.add(jButton1);
	// Ende Komponenten

	setResizable(false);
	setVisible(true);
  }

  // Anfang Methoden
  public void jButton1_ActionPerformed(ActionEvent evt) {
	String host = jTextField1.getText();
	try{
	  jLabel1.setText(InetAddress.getByName(host).getHostAddress());
	}
	catch(Exception e){
	System.out.println(e);
	}

	
  }

  // Ende Methoden

  public static void main(String[] args) {
	new ip("ip");
  }
}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users