0
大きなプロジェクトに含まれるこれらの2つのクラスがありますが、何らかの奇妙な理由により、ブラウザではmain()
を実行するとHTMLファイルが表示されません。ここでブラウザにはHTMLファイルが表示されません
は、2つのクラスされています
メイン:
import java.awt.BorderLayout;
import java.awt.Component;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class main {
public static void main(String[] args) {
BrowserFrame browser = new BrowserFrame();
JFrame mainFrame = new JFrame();
Thread browserThread = new Thread();
mainFrame.getContentPane().add(browser);
mainFrame.setSize(550,550);
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
browserThread.start();
browser.setVisible(true);
mainFrame.setVisible(true);
}
}
BrowserFrame
import java.awt.BorderLayout;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.JEditorPane;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.StyleSheet;
public class BrowserFrame extends javax.swing.JPanel {
public void BrowserFrame() {
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
URL url = null;
try {
url = new URL("file:///C:/PersonalWorkSpace/PrivateEyes/html/test.html");
} catch (MalformedURLException e) {
e.printStackTrace();
}
JEditorPane jEditorPane = new JEditorPane();
jEditorPane.setEditable(false);
JScrollPane jScrollPane = new JScrollPane(jEditorPane);
HTMLEditorKit kit = new HTMLEditorKit();
jEditorPane.setEditorKit(kit);
StyleSheet styleSheet = kit.getStyleSheet();
styleSheet.addRule("body {color:#000; font-family:times; margin: 4px;}");
styleSheet.addRule("h1 {color: blue;}");
styleSheet.addRule("h2 {color: #ff0000;}");
setLayout(new BorderLayout());
add(jEditorPane);
try {
jEditorPane.setPage(url);
} catch (IOException e) {
e.printStackTrace();
}
jEditorPane.setVisible(true);
jScrollPane.setVisible(true);
System.out.println("Browser Window Run");
}
});
}
}
私のコードのいくつかは奇妙な/少し不安定なように出くわすかもしれないが、私がいたためですいくつかのことをしようとするといくつかの残党が残っている。
ありがとうございます。
ああ私の神!私はこの時間を少しずつ加えてビットを捨ててしまったと思っていました。それは私が習慣から追加した1つの単語でした。タイマーがダウンするとあなたの答えを受け入れます。 – RyanSoper
私はそれが起こるのは嫌いですが、私は通常、後で頭痛の原因となったいくつかのバグを発見しています) – aglassman