Results 1 to 3 of 3

Thread: รบกวนหน่อยนะค่ะ

  1. #1
    Anonymous
    Guest


    รบกวนหน่อยนะค่ะ

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

    public class ImageMap extends Applet {

    Image background;
    boolean overlay;

    Vector areas = new Vector();
    Vector images = new Vector();
    Vector urls = new Vector();

    int current = -1;

    public void init() {
    System.out.println ("ImageMap applet copyright Prominence Dot Com 1996");
    // get the parameters
    background = getImage(getDocumentBase(), getParameter("main"));
    prepareImage(background, this);
    overlay = Boolean.valueOf(getParameter("overlay")).booleanValue();
    String bgcolor = getParameter("bgcolor");
    if (bgcolor != null)
    setBackground (new Color (Integer.parseInt (bgcolor.substring (1), 16)));
    boolean ok = true;
    for (int i = 1; ok; ++i) {
    String areaStr = getParameter("area"+i);
    String imageStr = getParameter("image"+i);
    String urlStr = getParameter("url"+i);
    if ((areaStr != null) && (imageStr != null) && (urlStr != null)) {
    try {
    StringTokenizer str = new StringTokenizer(areaStr);
    Rectangle area = new Rectangle(Integer.parseInt(str.nextToken()),
    Integer.parseInt(str.nextToken()),
    Integer.parseInt(str.nextToken()),
    Integer.parseInt(str.nextToken()));
    Image image = getImage(getDocumentBase(), imageStr);
    URL url = new URL(getDocumentBase(), urlStr);
    areas.addElement(area);
    images.addElement(image);
    urls.addElement(url);
    prepareImage (image, this);
    } catch (MalformedURLException ex) {
    System.out.println ("Invalid format for URL " + i + " : " + urlStr);
    } catch (NoSuchElementException ex) {
    System.out.println ("Invalid format for area " + i + " : " + areaStr);
    } // end try
    } else {
    ok = false;
    } // end if
    } // end for
    } // end init

    public boolean handleEvent(Event e) {
    switch(e.id) {
    case Event.MOUSE_ENTER:
    case Event.MOUSE_MOVE:
    case Event.MOUSE_EXIT:
    case Event.MOUSE_DOWN:
    case Event.MOUSE_DRAG:
    case Event.MOUSE_UP:
    int next = -1;
    if (e.id != Event.MOUSE_EXIT) {
    for (int i = 0; i < areas.size (); ++i) {
    Rectangle rect = (Rectangle) areas.elementAt (i);
    if (rect.inside (e.x, e.y)) {
    next = i;
    } // end if
    } // end for
    } // end if
    if (next != current) {
    int temp = current;
    current = next;
    repaintImages (temp, current);
    } // end if
    if ((e.id == Event.MOUSE_DOWN) && (current != -1)) {
    URL url = (URL) urls.elementAt (current);
    getAppletContext().showDocument(url);
    }
    break;
    } // end switch
    return(super.handleEvent(e));
    } // end handleEvent

    protected void repaintImages(int last, int current) {
    if (overlay) {
    if (last != -1) {
    Rectangle oldRect = (Rectangle) areas.elementAt (last);
    Image oldImage = (Image) images.elementAt (last);
    repaint (oldRect.x, oldRect.y, oldImage.getWidth (this), oldImage.getHeight (this));
    }
    if (current != -1) {
    Rectangle newRect = (Rectangle) areas.elementAt (current);
    Image newImage = (Image) images.elementAt (current);
    repaint (newRect.x, newRect.y, newImage.getWidth (this), newImage.getHeight (this));
    }
    } else {
    repaint (0, background.getHeight (this), size ().width, size ().height -
    background.getHeight (this));
    } // end if
    } // end repaintImages

    public void update (Graphics g) {
    int x = background.getWidth (this), y = background.getHeight (this);
    if ((x > 0) && (y > 0)) {
    g.setColor (getBackground ());
    g.fillRect (x, 0, size ().width - x, y);
    g.fillRect (0, y, size ().width, size ().height - y);
    paint (g);
    } else {
    super.update (g);
    }
    }

    public void paint(Graphics g) {
    g.drawImage (background, 0, 0, this);
    if (current != -1) {
    Image image = (Image) images.elementAt (current);
    if (overlay) {
    Rectangle rect = (Rectangle) areas.elementAt (current);
    g.drawImage (image, rect.x, rect.y, this);
    } else {
    int w = image.getWidth (this), h = image.getHeight (this);
    g.drawImage (image, (size ().width - w) / 2, (size ().height +
    background.getHeight (this) - h) / 2, this);
    } // end if
    } // end if
    } // end paint

    } // end ImageMap

  2. #2
    Anonymous
    Guest


    Re: รบกวนหน่อยนะค่ะ

    ลองโหลดดูแล้วแล้วสร้างไฟล์ html เรียก applet ขึ้นมา
    <applet code="ImageMap.class" width="336" height="280">
    <param name="main" value="main.gif">
    <param name="bgcolor" value="#000000">
    <param name="overlay" value="true">

    <param name="area1" value="1 3 186 81">
    <param name="image1" value="1.gif">
    <param name="url1" value="http://prominence.com/">


    </applet >
    มันโหลดแล้วบอกว่า applet fail น่ะคะ เลยไม่แน่ใว่มันทำงานยังไง ใช้ยังไงนะค่ะ ใครรู้ช่วยแนะนำหน่อยนะค่ะ พอดีเพิ่งหัดเขียนค่ะ
    ตัวอย่างของต้นฉบับ
    http://www.javaworld.com/javaworld/j.../dec/main.html

  3. #3
    Anonymous
    Guest


    Re: รบกวนหน่อยนะค่ะ

    มันไม่ขึ้นน่ะค่ะ มันขึ้นสีเทา แล้วบอกว่า applet imagemap nonitied น่ะค่ะ สักพักก็ขึ้นว่า loding java applet failค่ะ
    ปล ตอน compile มันขึ้นว่า
    Note: D:ImageMap.java uses or overrides a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    Note: D:ImageMap.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.

Members who have read this thread : 0

Actions : (View-Readers)

There are no names to display.

Members who have read this thread: 0

There are no members to list at the moment.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •