我试图用 Java Applet 来运行这个代码:
package test;
import java.applet.Applet;
import java.awt.Graphics;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
public class DrawExample extends Applet {
public void paint(Graphics g) {
try {
g.drawString("CODE:",50, 30);
URL yahoo = new URL("http://www.yahoo.com/");
URLConnection yc = yahoo.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
String inputLine;
int i=65;
while ((inputLine = in.readLine()) != null) {
g.drawString(inputLine,50, i);
i=i+15;
}
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
如果我把Eclipse的代码作为一个小程序运行,它就很好,但如果我试图在网页中运行,我只能得到“CODE:”的代码。
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
有人知道我做错了什么吗?