I've been working on a small project recently, and I seem to of confused myself and hit a huge mental block. I know this should be simple which is why this is annoying me so much, but as the title suggests I have 3 classes:
main - This should instantiate the other classes, and only really contain constructors:
import java.awt.BorderLayout;
import java.awt.Component;
import javax.swing.JFrame;
public class main {
public static void main(String[] args) {
BrowserFrame browser = new BrowserFrame();
JFrame mainFrame = new JFrame();
mainFrame.setSize(550,550);
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Total Guesswork on the next line! Result of a mental block!
//mainFrame.add(browser);
}
}
BrowserFrame - This is where I have created the actual HTML viewer.
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 {
public 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;}");
try {
jEditorPane.setPage(url);
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
}
And finally Toolbar, which has nothing in thus far, but will eventually contain the Toolbar which i want to display at the top of the JFrame once it's coded.
I know I need to make the BrowserFrame a component, but I can't for the life of me work out How to do it, and resources it search for on the web are all applied to other example code so It ends up confusing me more!
What I want to achieve is that when you run the application opens, you get a window which displays my HTML document, and then at the top of the window there is a menu as well, but I can't even get the Browser to display at the moment ( :( ) Any help is greatly appreciated, as my mind is well and truly swimming in mud at the moment, time for a tea I think.