/** * MinibrowseCore provides the tools for a basic web browser. * * @author Dave Musicant * @author Jack Goldfeather * @author Amy Csizmar Dalal */ import javax.swing.*; import java.io.*; import java.awt.*; import java.util.*; import java.awt.event.*; public class MinibrowseCore { private JFrame frame; private JEditorPane htmlPane; private JPanel panel; /** * Constructor. */ public MinibrowseCore() { // Set up the main window. frame = new JFrame("Minibrowse"); frame.setLocation(50,50); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Create a component that can render HTML. Wrap a scollbar // component around it. htmlPane = new JEditorPane(); htmlPane.setContentType("text/html"); htmlPane.setEditable(false); JScrollPane scrollPane = new JScrollPane(htmlPane); scrollPane.setPreferredSize(new Dimension(500,500)); // Create a JPanel to hold the "toolbar" that contains the // Home button and the URL field. panel = new JPanel(); // Add the "toolbar" panel to the top of the window, and the // scrollable HTML window to the middle of the window. frame.add(panel,BorderLayout.NORTH); frame.add(scrollPane,BorderLayout.CENTER); frame.pack(); frame.setVisible(true); } /** * Render a specific web page. * * @param page the page to be rendered */ public void setPage(String page) { try { htmlPane.setPage(page); } catch (IOException exc) { JOptionPane.showMessageDialog(frame,"Bad page.","Error", JOptionPane.ERROR_MESSAGE); }; } /** * Add a GUI component to the window. Components are added from * left to right across the top. * @param component the JComponent to be added. Could be a * JButton, JTextField, or anything else that inherits from JComponent. */ public void add(JComponent component) { panel.add(component); frame.pack(); } }