/** * Minibrowse is a simple web browser that uses Java's rendering engine. * * @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.*; class Minibrowse implements ActionListener { private JFrame frame; private JEditorPane htmlPane; private JTextField url; public Minibrowse() { // 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 Home button. JButton homeButton = new JButton("Home"); homeButton.addActionListener(this); // Create a blank space where the user will type in the web // page to visit. url = new JTextField(30); url.setActionCommand("url"); url.addActionListener(this); // Create a JPanel to hold the "toolbar" that contains the // Home button and the URL field. JPanel panel = new JPanel(); panel.add(homeButton); panel.add(url); // 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); } public void actionPerformed(ActionEvent event) { String actionCommand = event.getActionCommand(); if (actionCommand.equals("Home")) url.setText("http://www.carleton.edu"); if (actionCommand.equals("Home") || actionCommand.equals("url")) { try { htmlPane.setPage(url.getText()); } catch (IOException exc) { JOptionPane.showMessageDialog(frame,"Bad page","Error.", JOptionPane.ERROR_MESSAGE); }; } else throw new UnsupportedOperationException(actionCommand); } public static void main(String[] args) { Minibrowse minibrowse = new Minibrowse(); } }