我正在尝试在我的 Java 程序中显示 Xbox Gamer Card:这是一张 GamerCard:http ://gamercard.xbox.com/de-DE/anybody.card
目前我有以下内容:
import java.awt.Dimension;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import javax.swing.JEditorPane;
import javax.swing.text.html.HTMLEditorKit;
public class CardLoader extends JEditorPane {
private static final long serialVersionUID = 1L;
private static final String[] card = { "http://gamercard.xbox.com/de-DE/", ".card" };
private static final String styleSheetLink = "http://gamercard.xbox.com/Content/Gamercard/default/gamercard.css";
public CardLoader(String username) {
HTMLEditorKit kit = new HTMLEditorKit();
this.setEditable(false);
this.setPreferredSize(new Dimension(200, 135));
kit.getStyleSheet().addRule(URLCaS(styleSheetLink));
this.setEditorKit(kit);
try {
this.setPage(card[0] +username +card[1]);
} catch (Exception e) {
e.printStackTrace();
}
}
String URLCaS(String url){
InputStream in = null;
String returner = new String();
try {
in = new URL(url).openStream();
InputStreamReader inR = new InputStreamReader( in );
BufferedReader buf = new BufferedReader( inR );
String line;
while ( ( line = buf.readLine() ) != null ) {
returner += line + "\n";
}
in.close();
} catch (Exception e){
e.printStackTrace();
}
return returner.substring(3);
}
}
看起来,它可以应用样式表,但不正确。
希望可以有人帮帮我。