Programalama > JAVA - JSP

Etiketler: java, applet, seklinde, menu

Ort. 0
Puan ver:
/*<applet code="ImageMenu" width=150 height=180 hspace=0 vspace=0>
<param name="img" value="MENU.jpg">
<param name="urlPrefix"
           value="http://www.programlama.ustasi.com/">
<param name="urlList"
           value="MYSELF/index+HOME/index+LESSONS+EXAMPLES/index+SITE_MAP+LINKS">
<param name="targetList"
           value="_self+_self+_self+_self+_self+_self">
<param name="urlSuffix" value=".html">
</applet>
*/

import java.awt.* ;
import java.awt.event.*;
import java.applet.*;
import java.util.*;
import java.net.*;

public class ImageMenu extends Applet {
  Dimension d;

  Image img, off;
  Graphics offg;
  int MAXITEMS = 64;
  String url[] = new String[MAXITEMS];
  String target[] = new String[MAXITEMS];
  String urlPrefix, urlSuffix;
  int selectedCell = -1;
  int oldCell = -1;
  int cellH;
  int cells;

  public void init() {
    d = getSize();
    urlPrefix = getParameter("urlPrefix");
    urlSuffix = getParameter("urlSuffix");
    StringTokenizer st;
    st = new StringTokenizer(getParameter("urlList"), "+");
    int i=0;
    while(st.hasMoreTokens() && i < MAXITEMS)
        url[i++] = st.nextToken();
    cells = i;
    cellH = d.height/cells;
    st = new StringTokenizer(getParameter("targetList"), "+");
    i=0;
    while(st.hasMoreTokens() && i < MAXITEMS)
      target[i++] = st.nextToken();
    addMouseListener(new MyMouseAdapter());
    addMouseMotionListener(new MyMouseMotionAdapter());
  }

  private void lateInit() {
    off = createImage(d.width, d.height);
    try {
      img = getImage(getDocumentBase(), getParameter("img"));
      MediaTracker t = new MediaTracker(this);
      t.addImage(img, 0);
      t.waitForID(0);
    } catch(Exception e) {
      showStatus("error: " + e);
    }
  }

  public void update(Graphics g) {}
  public void paint(Graphics g) {
    if(off == null)
      lateInit();

    offg = off.getGraphics();
    offg.drawImage(img, 0, 0, this);
    if (selectedCell >= 0) {
      offg.clipRect(0, selectedCell * cellH, d.width, cellH);
      offg.drawImage(img, -d.width, 0, this);
    }
    g.drawImage(off, 0, 0, this);
  }

  class MyMouseMotionAdapter extends MouseMotionAdapter {
    public void mouseDragged(MouseEvent me) {
      mouseMoved(me);
    }
    public void mouseMoved(MouseEvent me) {
      int y = me.getY();
      selectedCell = (int)(y/(double)d.height*cells);
      if (selectedCell != oldCell) {
        paint(getGraphics());
        showStatus(urlPrefix + url[selectedCell] + urlSuffix);
        oldCell = selectedCell;
      }
    }
  }

  class MyMouseAdapter extends MouseAdapter {
    public void mouseExited(MouseEvent me) {
      selectedCell = oldCell = -1;
      paint(getGraphics());
      showStatus("");
    }

    public void mouseReleased(MouseEvent me) {
      URL u = null;
      try {
        u = new URL(urlPrefix + url[selectedCell] + urlSuffix);
      } catch(Exception e) {
        showStatus("error: " + e);
      }
      if (me.isShiftDown())
        getAppletContext().showDocument(u, "_blank");
      else
        getAppletContext().showDocument(u, target[selectedCell]);
    }
  }
}



Yorumlar                 Yorum Yaz
Bu hazır kod'a ilk yorumu siz yapın!
KATEGORİLER
ASP - 240
ASP.NET - 24
C# - 75
C++ - 174
CGI - 8
DELPHI - 247
FLASH - 49
HTML - 536
PASCAL - 246
PERL - 11
PHP - 160
WML - 9
XML - 2
Copyright © 2002 - 2024 Hazır Kod - Tüm Hakları Saklıdır.
Siteden yararlanırken gizlilik ilkelerini okumanızı tavsiye ederiz.
hazirkod.com bir İSOBİL projesidir.