Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Whois program

timer setpreferredsize

  • Please log in to reply
2 replies to this topic

#1 tanaysaksena

tanaysaksena

    CC Newcomer

  • Member
  • PipPip
  • 10 posts

Posted 13 November 2011 - 06:54 PM

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

  • 0

#2 Eieio

Eieio

    CC Regular

  • Just Joined
  • PipPipPip
  • 44 posts

Posted 13 November 2011 - 10:24 PM

You should add code tags... then I might actually want to read it.
  • 0

#3 wim DC

wim DC

    Roar

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2681 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Python

Posted 14 November 2011 - 12:15 AM

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.
  • 0





Also tagged with one or more of these keywords: timer, setpreferredsize

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download