当前位置: 技术问答>java相关
方法调用的问题
来源: 互联网 发布时间:2015-04-05
本文导语: 下面的程序可以通过编译,但不能运行,请问方法如何调用? import java.awt.*; import java.awt.event.*; import java.io.*; import java.net.*; public class FileLister extends Frame { TextArea text; public FileLister(){ addWindow...
下面的程序可以通过编译,但不能运行,请问方法如何调用?
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
public class FileLister extends Frame {
TextArea text;
public FileLister(){
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){ dispose();}
});
text=new TextArea(" ",24,80);
text.setFont(new Font("MonoSpaced",Font.PLAIN,12));
text.setEditable(false);
this.add("Center",text);
Panel p=new Panel();
p.setLayout(new FlowLayout(FlowLayout.RIGHT,10,5));
this.add(p,"South");
this.pack();
}
public void getUrl(){
try{
URL url=new URL("http://www.sina.com.cn/");
String in;
DataInputStream stream=new DataInputStream(url.openStream());
while((in=stream.readLine())!=null){
text.append(in);
text.setCaretPosition(0);
}
}catch(MalformedURLException e){
System.out.println("MalformedURLException:"+e);
}catch(IOException e){
System.out.println("IOException:"+e);
}
}
public static void main(String [] args){
FileLister f=new FileLister();
f.addWindowListener(new WindowAdapter(){
public void windowClosed(WindowEvent e){ System.exit(0);}
});
f.show();
f.getUrl();
}
}
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
public class FileLister extends Frame {
TextArea text;
public FileLister(){
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){ dispose();}
});
text=new TextArea(" ",24,80);
text.setFont(new Font("MonoSpaced",Font.PLAIN,12));
text.setEditable(false);
this.add("Center",text);
Panel p=new Panel();
p.setLayout(new FlowLayout(FlowLayout.RIGHT,10,5));
this.add(p,"South");
this.pack();
}
public void getUrl(){
try{
URL url=new URL("http://www.sina.com.cn/");
String in;
DataInputStream stream=new DataInputStream(url.openStream());
while((in=stream.readLine())!=null){
text.append(in);
text.setCaretPosition(0);
}
}catch(MalformedURLException e){
System.out.println("MalformedURLException:"+e);
}catch(IOException e){
System.out.println("IOException:"+e);
}
}
public static void main(String [] args){
FileLister f=new FileLister();
f.addWindowListener(new WindowAdapter(){
public void windowClosed(WindowEvent e){ System.exit(0);}
});
f.show();
f.getUrl();
}
}
|
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
public class FileLister extends Frame {
TextArea text;
public FileLister(){
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){ dispose();}
});
text=new TextArea(" ",24,80);
text.setFont(new Font("MonoSpaced",Font.PLAIN,12));
text.setEditable(false);
this.add("Center",text);
Panel p=new Panel();
p.setLayout(new FlowLayout(FlowLayout.RIGHT,10,5));
this.add(p,"South");
this.pack();
}
public void getUrl(){
try{
URL url=new URL("http://www.sina.com.cn/");
String in;
DataInputStream stream=new DataInputStream(url.openStream());
while((in=stream.readLine())!=null){
text.append(in);
text.setCaretPosition(0);
}
}catch(MalformedURLException e){
System.out.println("MalformedURLException:"+e);
}catch(IOException e){
System.out.println("IOException:"+e);
}
}
public static void main(String [] args){
FileLister f=new FileLister();
f.addWindowListener(new WindowAdapter(){
public void windowClosed(WindowEvent e){ System.exit(0);}
});
f.show();
f.getUrl();
}
}
此程序没问题给分吧
import java.awt.event.*;
import java.io.*;
import java.net.*;
public class FileLister extends Frame {
TextArea text;
public FileLister(){
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){ dispose();}
});
text=new TextArea(" ",24,80);
text.setFont(new Font("MonoSpaced",Font.PLAIN,12));
text.setEditable(false);
this.add("Center",text);
Panel p=new Panel();
p.setLayout(new FlowLayout(FlowLayout.RIGHT,10,5));
this.add(p,"South");
this.pack();
}
public void getUrl(){
try{
URL url=new URL("http://www.sina.com.cn/");
String in;
DataInputStream stream=new DataInputStream(url.openStream());
while((in=stream.readLine())!=null){
text.append(in);
text.setCaretPosition(0);
}
}catch(MalformedURLException e){
System.out.println("MalformedURLException:"+e);
}catch(IOException e){
System.out.println("IOException:"+e);
}
}
public static void main(String [] args){
FileLister f=new FileLister();
f.addWindowListener(new WindowAdapter(){
public void windowClosed(WindowEvent e){ System.exit(0);}
});
f.show();
f.getUrl();
}
}
此程序没问题给分吧