日期:2014-05-20  浏览次数:20671 次

没找儿了,来帮帮我啊!
这是我的原代码,我在报错的地方做了标记,请大家帮帮我啊!!!!
import   java.awt.*;
import   java.awt.event.*;
import   java.applet.*;
import   java.net.*;
import   java.io.*;
public   class   ReadWebFileApplet   extends   Applet   {
TextField   textField1=new   TextField();
Button   button1=new   button();
TextArea   textArea1=new   TextArea();
public   ReadWebFileApplet(){
try{

jbInit();
}
catch(Exveption   e){
e.printStackTrace();
}
}
private   void   jbInit()   throws   Exception{
textField1.setText( "输入网络地址和文件名 ");
textField1.setBounds(new   Rectangle(0,1,179,30));
this.setLayout(null);
buttonl.setLabel( "获取网络文件 ");
button1.setBounds(new   Rectangle(186,4,108,28));
button1.addActionListener(new   java.awt.event.ActionListener(){
public   void   actionPerformed(ActionEvent   e){
这行总是报错,找不到错在那里了     button1.actionPerformed(e);
}

});
textAreal.setBounds(new   Rectangle(1,37,294,261));
this.add(textField1,null);
this.add(textArea1,null);
this.add(button1,null);
}
public   void   ReadURL(String   URLName)throws   Exception   {
int   HttpResult;
URL   url=new   URL(URLName);
URLConnection   urlconn=url.openConnection();
urlconn.connect();
HttpURLConnection   httpconn=(HttpURLConnection)urlconn;
HttpResult=httpconn.getResponseCode();
if(HttpResult   !=HttpURLConnection.HTTP_OK)
textArea1.setText( "无法连接到 "+textField1.getText());
else{
int   filesize=urlconn.getContentLength();
InputStreamReader   IsReader=new   InputStreamReader(urlconn.getInputStream());
char[]   buffer=new   char[2048];
int   num=0;
while(num> -1){
num=isReader.read(buffer);
if(num <0)   break;
textArea1.append(new   String(buffer,0,num));

}

IsReader.close();
}
}
void   button1_actionPeformed(ActonSvent   e){
String   str=e.getActionCommand();
try{
textArea1.setText( " ");
ReadURL(textField1.getText());
}
catch(Exception   ex){
textArea1.setText( "读取失败 ");
}
}
public   static   void   main(String[]   args){
Frame   f=new   Frame( "获取网路文件 ");
ReadWebFileApplet   readWebFile=new   ReadWebFileApplet();
readWebFile.init();
readWebFile.start();
f.add( "Center ",readWebFile);
f.setSize(350,350);
f.show();
}
}

------解决方案--------------------
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionEvent;
import java.applet.*;
import java.net.*;
import java.io.*;
public class ReadWebFileApplet extends Applet {
TextField textField1=new TextField();
Button button1=new Button(); ///b-> B
TextArea textArea1=new TextArea();
public ReadWebFileApplet(){
try{

jbInit();
}
catch(Exception e){ //Exception
e.printStackTrace();
}
}
private void jbInit() throws Exception{
textField1.setText( "输入网络地址和文件名 ");
textField1.setBounds(new Rectangle(0,1,179,30));
this.setLayout(null);
button1.setLabel( "获取网络文件 "); //l-> 1
button1.setBounds(new Rectangle(186,4,108,28)); //l-> 1