import java.awt.*; import java.awt.event.*; import java.applet.*; import java.net.*; /** * Define our applet class. It extends the Applet object */ public class WebMenu extends Applet implements ActionListener{ // // define and create the objects that make up the interface // List main = new List(); String[] links = { "","http://www.cnn.com","http://www.abcnews.go.com", "http://www.msnbc.com", "","http://www.espn.com","http://sportsillustrated.cnn.com/", "http://www.foxsports.com", "", "http://www.weather.com"}; /** * Constructor the applet */ public WebMenu() { } /** * The following methods initialize the applet and are * invoked automatically. */ public void init(){ // // first set the applets layout manager // BorderLayout layout = new BorderLayout(); setLayout(layout); add("Center",main); main.addActionListener(this); main.setBackground(Color.yellow); main.setForeground(Color.blue); main.add("News"); main.add(" CNN"); main.add(" ABC"); main.add(" MSNBC"); main.add("Sports"); main.add(" ESPN"); main.add(" Sports Illustrated"); main.add(" FOX Sports"); main.add("Weather"); main.add(" The Weather Channel"); } /** * this method is called whenever a button is * pressed. Figure out what was pressed then do it */ public void actionPerformed(ActionEvent e){ // // first make sure that it was a button that sent this // event // if(e.getSource() instanceof List){ int index = main.getSelectedIndex(); if(index >= links.length || index < 0){ showStatus("Missing link"); return; } if(links[index].length() < 1) return; // just ignore heading list items try{ URL link = new URL(links[index]); getAppletContext().showDocument(link); } catch(MalformedURLException ex) { showStatus("Bad URL:"+links[index]); } } // end if } // end of actionPerformed } // end of class