[Java]
Import java. awt. event. ActionEvent;
Import java. awt. event. ActionListener;
Import java. io. DataInputStream;
Import java. io. IOException;
Import java.net. MalformedURLException;
Import java.net. URL;
Import java.net. URLConnection;
Import javax. swing. JButton;
Import javax. swing. JFrame;
Import javax. swing. JPanel;
Import javax. swing. JScrollPane;
Import javax. swing. JTextArea;
Import javax. swing. JTextField;
Import org. omg. CORBA. TCKind;
Public class web extends JFrame implements ActionListener {
/**
* @ Param args
*/
JTextField t1 = new JTextField (30 );
JTextArea t2 = new JTextArea ();
JButton b1 = new JButton ("open ");
JPanel p = new JPanel ();
Public web (){
P. add (t1 );
P. add (b1 );
JScrollPane jp = new JScrollPane (t2 );
B1.addActionListener (this );
GetContentPane (). add (p, "North ");
GetContentPane (). add (jp, "Center ");
Setdefaclocloseoperation (JFrame. EXIT_ON_CLOSE );
SetSize (500,400 );
SetVisible (true );
SetTitle ("read url ");
}
Public static void main (String [] args ){
// TODO Auto-generated method stub
Web webH = new web ();
}
@ Override
Public void actionreceivmed (ActionEvent e ){
// TODO Auto-generated method stub
ReadURL (t1.getText ());
}
Private void readURL (String URLName ){
// TODO Auto-generated method stub
Try {
URL url = new URL (URLName );
URLConnection tc = url. openConnection ();
Tc. connect ();
DataInputStream dis = new DataInputStream (tc. getInputStream ());
String inputLineString;
While (inputLineString = dis. readLine ())! = Null ){
T2.append (inputLineString + "\ n ");
}
} Catch (MalformedURLException e ){
// TODO: handle exception
E. printStackTrace ();
} Catch (IOException e1 ){
E1.printStackTrace ();
// TODO: handle exception
}
}
}
Import java. awt. event. ActionEvent;
Import java. awt. event. ActionListener;
Import java. io. DataInputStream;
Import java. io. IOException;
Import java.net. MalformedURLException;
Import java.net. URL;
Import java.net. URLConnection;
Import javax. swing. JButton;
Import javax. swing. JFrame;
Import javax. swing. JPanel;
Import javax. swing. JScrollPane;
Import javax. swing. JTextArea;
Import javax. swing. JTextField;
Import org. omg. CORBA. TCKind;
Public class web extends JFrame implements ActionListener {
/**
* @ Param args
*/
JTextField t1 = new JTextField (30 );
JTextArea t2 = new JTextArea ();
JButton b1 = new JButton ("open ");
JPanel p = new JPanel ();
Public web (){
P. add (t1 );
P. add (b1 );
JScrollPane jp = new JScrollPane (t2 );
B1.addActionListener (this );
GetContentPane (). add (p, "North ");
GetContentPane (). add (jp, "Center ");
Setdefaclocloseoperation (JFrame. EXIT_ON_CLOSE );
SetSize (500,400 );
SetVisible (true );
SetTitle ("read url ");
}
Public static void main (String [] args ){
// TODO Auto-generated method stub
Web webH = new web ();
}
@ Override
Public void actionreceivmed (ActionEvent e ){
// TODO Auto-generated method stub
ReadURL (t1.getText ());
}
Private void readURL (String URLName ){
// TODO Auto-generated method stub
Try {
URL url = new URL (URLName );
URLConnection tc = url. openConnection ();
Tc. connect ();
DataInputStream dis = new DataInputStream (tc. getInputStream ());
String inputLineString;
While (inputLineString = dis. readLine ())! = Null ){
T2.append (inputLineString + "\ n ");
}
} Catch (MalformedURLException e ){
// TODO: handle exception
E. printStackTrace ();
} Catch (IOException e1 ){
E1.printStackTrace ();
// TODO: handle exception
}
}
}