import java.applet.*;
import java.awt.*;
import java.net.*;
import java.awt.event.*;
public class popupURL extends Applet {
PopupMenu popup;
MenuItem menu;
Image image;
String webpage,
pageURL;
String[] holdPage;
String[] holdURL;
int pagenumber = 20,
count = 0,
index = 0;
int i,
in,
x;
public void init()
{
image = getImage(getDocumentBase(),"image.gif");
enableEvents(AWTEvent.MOUSE_EVENT_MASK|AWTEvent.MOUSE_MOTION_EVENT_MASK|
AWTEvent.ACTION_EVENT_MASK);
holdPage = new String[pagenumber];
holdURL = new String[pagenumber];
popup = new PopupMenu();
for(in = 0; in < pagenumber; in++)
{
webpage=getParameter("page" + in);
pageURL=getParameter("url" + in);
if((webpage == null) || (pageURL == null)) break;
count++;
index++;
holdPage[in] = webpage;
holdURL[in] = pageURL;
}
for(i = 0; i < count; i++)
{
menu = new MenuItem(holdPage[i]);
menu.setActionCommand(holdPage[i]);
popup.add(menu);
if(i != (count - 1)) popup.addSeparator();
else break;
} // End for-loop
add(popup);
popup.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
String command = e.getActionCommand();
System.out.println(command);
String address;
for(x = 0; x < index; x++) {
if (command.equals(holdPage[x]))
{
address = holdURL[x];
popupURL.this.newPage(address);
break;
}/* End if statement*/
}/* End for-loop */
}});
this.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
if (e.getID() == MouseEvent.MOUSE_CLICKED) {
popup.show(e.getComponent(),e.getX(),e.getY());
} }});
}
public void newPage(String s) {
try {
URL u = new URL(s); getAppletContext().showDocument(u);
}
catch(MalformedURLException ex)
{ System.err.println(ex);
}
}
public void paint(Graphics g)
{
g.drawImage(image,10,10,this); }
}