Fnerd Java Menu Applet
December 5, 2007 | Barry Wise | Code Samples
Comment
This is some pretty old Java code – but it still works with the modern runtime
environment! It creates a mouseover fly-out menu of links. It was pretty cool back in the day …
/*
fnerd.java ver 3.1 (Fnerdstom's Theory - Final Release)
Barry Wise, 10/24/97
Param Updates 7/8/99
Final Release, added class align 2/1/2000
This applet is freeware. For minimal support and customizations, please contact
the author at bwise@cybernex.net.
Source supported at: http://www.barrywise.com/
The fnerd menu applet provides a list of links with mouse-over Windows 98-style
"tool tips." It has been designed to operate with Java 1.02, thereby supporting
older browsers such as MS IE 3+ and Netscape 3+, as well as all the latest releases.
Only the colors can be passed as parameters to the applet -- this applet has been
designed to work as a sort of Java Server-side includes. By compiling all the links
into this navbar applet and pointing every page on the site to this one applet, you
don't have to go in and change every HTML file every time you want to update
a menu item. This is particularly useful on larger sites with many menu items.
In order to change the values, just edit the text in this applet and re-compile the code.
NOTE: Newer Java compilers may give a "Deprecation" warning - this means that
this applet uses older Java 1.02 code, which is a good thing, so that older browsers
will see the applet.
*/
import java.applet.*;
import java.awt.*;
import java.net.*;
public class fnerd extends Applet {
align aligned_left = new align();
align aligned_right = new align();
int on = 0; // Initilialize Variables
int boxTop = 0;
int textTop;
URL pagelink = null;
Color backgroundColor, linkColor, tipBoxColor, tipTextColor;
String link[] = {"http://www.barrywise.com/",
"http://www.barrywise.com/",
"http://www.barrywise.com/",
"http://www.barrywise.com/",
"http://www.barrywise.com/",
"http://www.barrywise.com/",
"http://www.barrywise.com/",
"http://www.barrywise.com/",
"http://www.barrywise.com/",
"http://www.barrywise.com/" };
int bb;
String blurb[][] = { {"Line 1 for Link 1", "Line 2 for Link 1", "Line 3 for Link 1", "Line 4 for Link 1" },
{"Line 1 for Link 2", "Line 2 for Link 2", "Line 3 for Link 2", "Line 4 for Link 2" },
{"Line 1 for Link 3", "Line 2 for Link 3", "Line 3 for Link 3", "Line 4 for Link 3" },
{"Line 1 for Link 4", "Line 2 for Link 4", "Line 3 for Link 4", "Line 4 for Link 4" },
{"Line 1 for Link 5", "Line 2 for Link 5", "Line 3 for Link 5", "Line 4 for Link 5" },
{"Line 1 for Link 6", "Line 2 for Link 6", "Line 3 for Link 6", "Line 4 for Link 6" },
{"Line 1 for Link 7", "Line 2 for Link 7", "Line 3 for Link 7", "Line 4 for Link 7" },
{"Line 1 for Link 8", "Line 2 for Link 8", "Line 3 for Link 8", "Line 4 for Link 8" },
{"Line 1 for Link 9", "Line 2 for Link 9", "Line 3 for Link 9", "Line 4 for Link 9" },
{"Line 1 for Link 10", "Line 2 for Link 10", "Line 3 for Link 10", "Line 4 for Link 10" }
};
String sys = System.getProperty("os.name", "Not Determined");
String arc = System.getProperty("os.arch", "Not Determined");
String osv = System.getProperty("os.version", "Not Determined");
String ver = System.getProperty("java.version", "Not Determined");
private Image imageOffScreen;
private Graphics graphicsOffScreen;
public void init() {
imageOffScreen = createImage(size().width, size().height);
graphicsOffScreen = imageOffScreen.getGraphics();
String bgcolor = getParameter("backgroundColor");
backgroundColor = new Color(Integer.valueOf(bgcolor, 16).intValue());
String tbcolor = getParameter("tipBoxColor");
tipBoxColor = new Color(Integer.valueOf(tbcolor, 16).intValue());
String tcolor = getParameter("tipTextColor");
tipTextColor = new Color(Integer.valueOf(tcolor, 16).intValue());
String lcolor = getParameter("linkColor");
linkColor = new Color(Integer.valueOf(lcolor, 16).intValue());
setBackground(backgroundColor);
System.out.println("\n\nfnerd.java ver 3.0 (Fnerdstom's Theory Release) \n10/24/97, Barry Wise \nhttp://www2.cybernex.net/~bwise/");
System.out.println("\nYou are using " + sys + " " + osv);
System.out.println("On a " + arc + "-class computer");
System.out.println("\nYour browser supports Java " + ver);
}
public void update(Graphics g) {
graphicsOffScreen.setColor(backgroundColor); // Applet BG Color
graphicsOffScreen.fillRect(0, 0, 160, 400);
graphicsOffScreen.setColor(linkColor); // Link Font Color
graphicsOffScreen.setFont(new Font("Helvetica", Font.PLAIN, 12));
aligned_right = new align(); //Right align Links
aligned_right.set_alignment(aligned_right.RIGHT);
aligned_right.drawString(graphicsOffScreen, "Link 1", 150, 14); // Menu Items (Links)
aligned_right.drawString(graphicsOffScreen, "Link 2", 150, 32);
aligned_right.drawString(graphicsOffScreen, "Link 3", 150, 50);
aligned_right.drawString(graphicsOffScreen, "Link 4", 150, 68);
aligned_right.drawString(graphicsOffScreen, "Link 5", 150, 86);
aligned_right.drawString(graphicsOffScreen, "Link 6", 150, 104);
aligned_right.drawString(graphicsOffScreen, "Link 7", 150, 122);
aligned_right.drawString(graphicsOffScreen, "Link 8", 150, 140);
aligned_right.drawString(graphicsOffScreen, "Link 9", 150, 158);
aligned_right.drawString(graphicsOffScreen, "Link 10", 150, 176);
g.drawImage(imageOffScreen, 0, 0, this);
g.dispose();
}
public void paint(Graphics g) {
update(g);
}
public boolean mouseMove(Event e, int x, int y) {
on =0;
if ((y > 3 && y < boxtop =" 20;" bb="0;" texttop =" 34;"> 21 && y < boxtop =" 38;" bb="1;" texttop ="52;"> 39 && y < boxtop =" 56;" bb="2;" texttop ="70;"> 58 && y < boxtop =" 74;" bb="3;" texttop ="88;"> 76 && y < boxtop =" 92;" bb="4;" texttop ="106;"> 94 && y < boxtop =" 110;" bb="5;" texttop ="124;"> 111 && y < boxtop =" 128;" bb="6;" texttop ="142;"> 130 && y < boxtop =" 146;" bb="7;" texttop ="160;"> 148 && y < boxtop =" 164;" bb="8;" texttop ="178;"> 166 && y < boxtop =" 182;" bb="9;" texttop ="196;"> 183) {Graphics g = getGraphics(); update(g); on =0; boxTop = 0;}
if (on == 1) {Graphics g = getGraphics(); update(g); drawStuff(); }
return true;
}
public boolean mouseUp(Event e, int x, int y) {
try { pagelink = new URL (getDocumentBase(), link[bb]); }
catch (MalformedURLException err) {
System.out.println("Error: " +err.getMessage()); }
getAppletContext().showDocument(pagelink);
return true;
}
public boolean mouseExit(Event e, int x, int y) {
Graphics g = getGraphics();
update(g);
on = 0; boxTop = 0;
return true;
}
public void drawStuff() {
Graphics g = getGraphics();
graphicsOffScreen.setColor(tipBoxColor); // TipBox Fill
graphicsOffScreen.fillRect(3, boxTop, 150, 60);
graphicsOffScreen.setColor(Color.black); // TipBox Outline
graphicsOffScreen.drawRect(3, boxTop, 150, 60);
graphicsOffScreen.setColor(tipTextColor); // TipBox Font
graphicsOffScreen.setFont(new Font("Dialog", Font.PLAIN, 10));
aligned_left = new align(); // Left align TipBox Text
aligned_left.set_alignment(aligned_left.LEFT);
aligned_left.drawString(graphicsOffScreen, blurb[bb][0], 8, textTop); // Text Strings
aligned_left.drawString(graphicsOffScreen, blurb[bb][1], 8, textTop+12);
aligned_left.drawString(graphicsOffScreen, blurb[bb][2], 8, textTop+24);
aligned_left.drawString(graphicsOffScreen, blurb[bb][3], 8, textTop+36);
g.drawImage(imageOffScreen, 0, 0, this);
g.dispose();
}
} // End class fnerd
class align {
// Define constants for setting text alignment
public static final int LEFT = 0x00;
public static final int RIGHT = 0x01;
public static final int CENTER = 0x02;
public static final int BASELINE = 0x00;
public static final int TOP = 0x04;
public static final int BOTTOM = 0x08;
private int alignmentType;
public align()
{
alignmentType = LEFT BASELINE; // default alignment
}
public void set_alignment(int alignment_type)
{
alignmentType = alignment_type;
}
public void drawString(Graphics g, String aString, int x, int y)
{
FontMetrics fmetrics = g.getFontMetrics();
int len = fmetrics.stringWidth(aString);
if ((alignmentType & RIGHT) != 0)
x -= len; // offset x for right alignment
else if ((alignmentType & CENTER) != 0)
x -= len/2; // offset x for center alignment
if ((alignmentType & TOP) != 0)
y += fmetrics.getAscent(); // offset y for top alignment
else if ((alignmentType & BOTTOM) != 0)
y -= fmetrics.getDescent(); // offset y for bottom alignment
g.drawString(aString, x, y);
}
} // End class align
Tags: applet, fnerd, itcn, java, menu, mouseover, programming
Similar Posts:
- Java Operating System Identifier
- Java Image Rotator Banner
- SEO Search Engine Friendly URLs with ASP.NET and IIS
- SEO Canonical URLs And 301 Redirects In Windows IIS 6, IIS 7
- Global Find and Replace In WordPress using MySQL
Comments
Leave a Reply




















