Jump to content

Whois program

- - - - -

  • Please log in to reply
2 replies to this topic

#1
tanaysaksena

tanaysaksena

    Newbie

  • Members
  • Pip
  • 8 posts
hello
I have created this program for my school project try to make it and tell me how how it is
Program name is Whois
It tell details about domin names like google.com , yahoo.com etc:)
************************************************************************************************************
import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

import java.net.*;

import java.io.*;


public class Whois extends JFrame

{

    JTextField t1;

    TextArea t2;

    JButton b1;

    FlowLayout f;

    JProgressBar pb;

    Timer timer;

    final static int interval = 1000;

    int cc=0;

    Whois(String s)

    { super(s);

        t1= new JTextField(30);

        t2=new TextArea();

        

        

        b1=new JButton("Submit");

        t2.setEditable(false);

        f=new FlowLayout();

        pb = new JProgressBar(0,1);

        pb.setValue(0);

        pb.setStringPainted(true);

        pb.setPreferredSize(new Dimension(350,20));

        setLayout(f);

       

        add(t1);

        add(b1);

        add(pb);

        add(t2);

        

        b1.addActionListener(new ButtonListener());

        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

        setResizable(false);

        setLocation(250,250);

        resize(400,255);

        show();

    

    

    timer = new Timer(interval, new ActionListener() {

    public void actionPerformed(ActionEvent ae)

    {

        try{

            

    int c;

    Socket s=new Socket("whois.geektools.com",43);

    InputStream in=s.getInputStream();

    OutputStream out=s.getOutputStream();

    String args[]=new String[200];

    String st=t1.getText();

    args[0]=t1.getText();

    String str=(args.length==0?st:args[0])+"\n";

    byte buf[]=str.getBytes();

    out.write(buf);

    String st1="";

 while((c=in.read())!= -1)

{

	st1=st1+(char)c+""; 

	cc=cc+1;

	pb.setValue(cc);


}


   t2.setText(st1);

   timer.stop();

   b1.setEnabled(true);

    s.close();

    }

    catch(UnknownHostException e)

    { 

    }

    catch(IOException e)

    { 

    }

    

}});}


class ButtonListener implements ActionListener {

  public void actionPerformed(ActionEvent ae) {

  b1.setEnabled(false);

  pb.setValue(0);

  cc=0;

  timer.start();

  }

  }

      public static void main(String args[])

      {

      


		SwingUtilities.invokeLater(new Runnable() {


			@Override

			public void run() {

				

				try {

					UIManager.setLookAndFeel(UIManager.

							getSystemLookAndFeelClassName());

				} catch (ClassNotFoundException e) {

				} catch (InstantiationException e) {

				} catch (IllegalAccessException e) {

				} catch (UnsupportedLookAndFeelException e) {

				} 

				

				Whois ob = new Whois("Whois");

			}

		});


	}

      }

***********************************************************************************************************
Try it and reply me

Edited by Roger, 15 February 2012 - 10:47 AM.
added code tags


#2
Eieio

Eieio

    Learning Programmer

  • Members
  • PipPipPip
  • 47 posts
You should add code tags... then I might actually want to read it.

#3
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
It's easier to wrap the input- and outputstream in a BufferedReader and PrintWriter if you're just sending and receiving characters.
Then you don't have to deal with low-level bytes.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users