我試圖做出一類這個網頁瀏覽器,但我無法得到它的工作:的Java Web瀏覽器程序的問題
import java.io.*;
import javax.swing.JLabel;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import javax.swing.JFrame;
import java.util.*;
public class WebViewer {
public static void main(String[] argv) throws Exception {
System.out.println("This program is made to view HTML code.");
Scanner input = new Scanner(System.in);
System.out.println("Enter webpage URL");
String url = ("");
String webpage = input.next();
webpage = new URL(url);
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String str;
while ((str = in.readLine()) != null) {
System.out.println(str);
JLabel textLabel = new JLabel(str);
}
}
}
// NEEDS FIXING
我最新的錯誤消息是:「不兼容的類型:java.net.URL中不能被轉換爲java.lang.String
任何人有任何建議,所有將不勝感激
因爲'input.nextLine()'應該存儲在'url'中,因爲如果不是這樣的話''''仍然是'''''。然後,「網頁」應該是在流中使用的Url實例(或相反;)) – AxelH