popupURL
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); }
}
Back to the popupURL applet page
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.