请看如下程序:.
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
public class E11
{
public static void main(String args[])
{
new NetWin();
}
}
class NetWin extends Frame implements ActionListener,Runnable
{
Button but;
URL http;
TextField text;
TextArea area;
byte b[]=new byte[118];
Thread thread1;
NetWin()
{
text=new TextField(20);
area=new TextArea(12,12);
but=new Button("sure");
but.addActionListener(this);
thread1=new Thread(this);
Panel p=new Panel();
p.add(new Label("input the websit"));
p.add(text);
p.add(but);
add(area,BorderLayout.CENTER);
add(p,BorderLayout.NORTH);
setBounds(60,60,360,300);
setVisible(true);
validate();
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e)
{
if(!(thread1.isAlive()))
{
thread1=new Thread(this);
}
try{
thread1.start();
}
catch(Exception ee)
{
text.setText("reading the http:"+http);
}
}
public void run()
{
try {
int n=-1;
area.setText(null);
http=new URL(text.getText().trim());
InputStream in=http.openStream();
while((n=in.read(b))!=-1)
{
String s=new String(b,0,n);
area.append(s);
}
}
catch(MalformedURLException e1)
{
text.setText(""+e1);
return;
}
catch(IOException e1)
{
text.setText(""+e1);
return ;
}
}
}
这里的run函数好像在NetWin()函数中没有调用,但是它怎么就运行了呢?
java程序的运行顺序和方式同c++有什么不同啊?哪位牛人能说明一下啊.啊啊啊啊:)......