import javax.swing.*; import java.awt.event.*; /** * Minibrowse application that adds a home button and a text field * for typing in web pages. */ public class Minibrowse implements ActionListener { private MinibrowseCore mc; private JTextField url; // Constructor. public Minibrowse() { mc = new MinibrowseCore(); // Create a home button JButton homeButton = new JButton("Home"); homeButton.addActionListener(this); mc.add(homeButton); // Create a text field for typing in the web page URL url = new JTextField(30); url.setActionCommand("url"); url.addActionListener(this); mc.add(url); } // Fires whenever an event happens. public void actionPerformed(ActionEvent event) { String actionCommand = event.getActionCommand(); if (actionCommand.equals("Home")) { mc.setPage("http://www.carleton.edu"); } else if (actionCommand.equals("url")) { mc.setPage(url.getText()); } else { throw new UnsupportedOperationException(actionCommand); } } public static void main(String[] args) { Minibrowse minibrowse = new Minibrowse(); } }