Visualizzazione dei risultati da 1 a 4 su 4

Discussione: Errore Stranissimo

  1. #1

    Errore Stranissimo

    Ho l'applet qui sotto salvata in un file di nome menu.class
    //TESTO DELL'APPLET
    import java.applet.Applet;
    import java.applet.AppletContext;
    import java.awt.*;
    import java.net.MalformedURLException;
    import java.net.URL;
    public class menu extends Applet
    implements Runnable
    {
    public void init()
    {
    w = size().width;
    h = size().height;
    try
    {
    num_buttons = Integer.parseInt(getParameter("buttons"));
    }
    catch(Exception exception) { }
    try
    {
    direction = Integer.parseInt(getParameter("direction"));
    }
    catch(Exception exception1) { }
    try
    {
    with = Integer.parseInt(getParameter("border width"));
    }
    catch(Exception exception2) { }
    try
    {
    position = Integer.parseInt(getParameter("position"));
    }
    catch(Exception exception3) { }
    try
    {
    degree = Integer.parseInt(getParameter("degree"));
    }
    catch(Exception exception4) { }
    try
    {
    f_offset = Integer.parseInt(getParameter("f_offset"));
    }
    catch(Exception exception5) { }
    try
    {
    style = Integer.parseInt(getParameter("style"));
    }
    catch(Exception exception6) { }
    String s = getParameter("color");
    if(s == null)
    s = "000000";
    color = new Color(Integer.parseInt(s, 16));
    try
    {
    f_size = Integer.parseInt(getParameter("f_size"));
    }
    catch(Exception exception7) { }
    try
    {
    f_style = Integer.parseInt(getParameter("f_style"));
    }
    catch(Exception exception8) { }
    String s1 = getParameter("font");
    if(s1 == null)
    s1 = "Helvetica";
    String s2 = getParameter("f_color");
    if(s2 == null)
    s2 = "FFFFFF";
    f_color = new Color(Integer.parseInt(s2, 16));
    s2 = getParameter("f_color2");
    if(s2 == null)
    s2 = "FFFFFF";
    f_color2 = new Color(Integer.parseInt(s2, 16));
    image_w = new int[num_buttons];
    image_h = new int[num_buttons];
    image_x = new int[num_buttons];
    image_y = new int[num_buttons];
    position_is = new int[num_buttons];
    position_be = new int[num_buttons];
    sourceimage = new Image[num_buttons];
    link = new String[num_buttons];
    label = new String[num_buttons];
    frame = new String[num_buttons];
    for(int i = 0; i < num_buttons; i++)
    {
    position_be[i] = 1;
    position_is[i] = 0;
    image_w[i] = 0;
    image_h[i] = 0;
    image_x[i] = 0;
    image_y[i] = 0;
    label[i] = getParameter("label " + Integer.toString(i));
    if(label[i] == null)
    label[i] = "";
    link[i] = getParameter("link " + Integer.toString(i));
    if(link[i] == null)
    link[i] = "";
    String s3 = getParameter("image " + Integer.toString(i));
    if(s3 == null)
    s3 = "";
    frame[i] = getParameter("frame " + Integer.toString(i));
    if(frame[i] == null)
    frame[i] = "_self";
    if(frame[i].equalsIgnoreCase(""))
    frame[i] = "_self";
    sourceimage[i] = getImage(getCodeBase(), s3);
    loadimage(sourceimage[i], i);
    image_w[i] = sourceimage[i].getWidth(this);
    image_h[i] = sourceimage[i].getHeight(this);
    }
    button_x = new int[num_buttons];
    button_y = new int[num_buttons];
    if(direction == 0)
    {
    button_w = w - 1;
    button_h = h / num_buttons;
    for(int j = 0; j < num_buttons; j++)
    {
    button_x[j] = 0;
    button_y[j] = button_h * j;
    }
    } else
    {
    button_h = h - 1;
    button_w = w / num_buttons;
    for(int k = 0; k < num_buttons; k++)
    {
    button_y[k] = 0;
    button_x[k] = button_w * k;
    }
    }
    int l = color.getRed();
    int i1 = color.getGreen();
    int j1 = color.getBlue();
    b_clr_dark = new Color[with + 1];
    b_clr_dark[0] = color;
    b_clr_light = new Color[with + 1];
    b_clr_light[0] = color;
    for(int k1 = 1; k1 < with + 1; k1++)
    {
    b_clr_dark[k1] = new Color(Math.max(0, l - k1 * degree), Math.max(0, i1 - k1 * degree), Math.max(0, j1 - k1 * degree));
    b_clr_light[k1] = new Color(Math.min(255, l + k1 * degree), Math.min(255, i1 + k1 * degree), Math.min(255, j1 + k1 * degree));
    }

    byte byte0 = 0;
    if(f_style == 1)
    byte0 = 1;
    else
    if(f_style == 2)
    byte0 = 2;
    font_x = new int[num_buttons];
    font_y = new int[num_buttons];
    font1 = new Font(s1, byte0, f_size);
    setFont(font1);
    FontMetrics fontmetrics = getFontMetrics(font1);
    for(int l1 = 0; l1 < num_buttons; l1++)
    {
    switch(position)
    {
    case 0: // '\0'
    image_x[l1] = button_x[l1] + (button_w - image_w[l1]) / 2;
    image_y[l1] = button_y[l1] + (button_h - image_h[l1]) / 2;
    font_x[l1] = button_x[l1] + (button_w - fontmetrics.stringWidth(label[l1])) / 2;
    break;

    case 1: // '\001'
    image_x[l1] = button_x[l1] + with + f_offset;
    image_y[l1] = button_y[l1] + (button_h - image_h[l1]) / 2;
    font_x[l1] = image_h[l1] + button_x[l1] + with + f_offset * 2;
    break;

    case 2: // '\002'
    image_x[l1] = (button_x[l1] + button_w) - with - image_w[l1] - f_offset;
    image_y[l1] = button_y[l1] + (button_h - image_h[l1]) / 2;
    font_x[l1] = (((button_x[l1] + button_w) - with) + 1) - fontmetrics.stringWidth(label[l1]) - image_w[l1] - f_offset * 2;
    break;
    }
    font_y[l1] = button_y[l1] + (button_h / 2 + fontmetrics.getHeight() / 3);
    }

    }
    public void paintFrame(Graphics g)
    {
    g.setFont(font1);
    for(int i = 0; i < num_buttons; i++)
    if(position_be[i] != position_is[i])
    {
    boolean flag = false;
    position_is[i] = position_be[i];
    if(position_be[i] == 1)
    flag = true;
    g.setColor(color);
    g.fillRect(button_x[i], button_y[i], button_w, button_h);
    if(flag)
    {
    g.drawImage(sourceimage[i], image_x[i], image_y[i], color, this);
    g.setColor(f_color);
    g.drawString(label[i], font_x[i], font_y[i]);
    } else
    {
    g.drawImage(sourceimage[i], image_x[i] + 1, image_y[i] + 1, color, this);
    g.setColor(f_color2);
    g.drawString(label[i], font_x[i] + 1, font_y[i] + 1);
    }
    for(int j = 0; j < with; j++)
    {
    if(!flag)
    g.setColor(b_clr_dark[with - j]);
    else
    g.setColor(b_clr_light[with - j]);
    g.drawLine(button_x[i] + j, button_y[i] + j, (button_x[i] + button_w) - j, button_y[i] + j);
    g.drawLine(button_x[i] + j, button_y[i] + j, button_x[i] + j, (button_y[i] + button_h) - j);
    if(flag)
    g.setColor(b_clr_dark[with - j]);
    else
    g.setColor(b_clr_light[with - j]);
    g.drawLine(button_x[i] + j, (button_y[i] + button_h) - j, (button_x[i] + button_w) - j, (button_y[i] + button_h) - j);
    g.drawLine((button_x[i] + button_w) - j, (button_y[i] + button_h) - j, (button_x[i] + button_w) - j, button_y[i] + j);
    }
    } else
    if(style == 0)
    if(i + 1 == mouse_in)
    {
    g.setColor(color);
    g.setColor(f_color2);
    g.drawString(label[i], font_x[i], font_y[i]);
    } else
    {
    g.setColor(color);
    g.setColor(f_color);
    g.drawString(label[i], font_x[i], font_y[i]);
    }
    }
    void loadimage(Image image, int i)
    {
    MediaTracker mediatracker = new MediaTracker(this);
    mediatracker.addImage(image, 0);
    try
    {
    mediatracker.waitForAll();
    return;
    }
    catch(InterruptedException interruptedexception)
    {
    stop();
    }
    }
    public void update(Graphics g)
    {
    Dimension dimension = size();
    if(offGraphics == null || dimension.width != offDimension.width || dimension.height != offDimension.height)
    {
    offDimension = dimension;
    offImage = createImage(dimension.width, dimension.height);
    offGraphics = offImage.getGraphics();
    offGraphics.setColor(color);
    offGraphics.fillRect(0, 0, w, h);
    }
    paintFrame(offGraphics);
    g.drawImage(offImage, 0, 0, null);
    }
    public void start()
    {
    if(animationThread == null)
    {
    animationThread = new Thread(this);
    animationThread.start();
    Thread.currentThread().setPriority(10);
    }
    }
    public void run()
    {
    while(animationThread != null)
    {
    try
    {
    Thread.sleep(400L);
    }
    catch(InterruptedException interruptedexception) { }
    repaint();
    }
    }
    public void paint(Graphics g)
    {
    if(offImage != null)
    g.drawImage(offImage, 0, 0, null);
    }
    public menu()
    {
    color = new Color(0, 0, 0);
    num_buttons = 1;
    degree = 20;
    with = 1;
    f_size = 12;
    f_offset = 1;
    }
    int w;
    int h;
    int start;
    Image offImage;
    Graphics offGraphics;
    Dimension offDimension;
    Thread animationThread;
    Color color;
    int num_buttons;
    int direction;
    int button_x[];
    int button_y[];
    int button_w;
    int button_h;
    int degree;
    int with;
    String label[];
    String link[];
    String frame[];
    Color b_clr_light[];
    Color b_clr_dark[];
    int f_size;
    int f_style;
    int font_x[];
    int font_y[];
    int f_offset;
    Color f_color;
    Color f_color2;
    Font font1;
    int selected;
    int last;
    int mouse_in;
    int style;
    int position;
    int position_is[];
    int position_be[];
    int down;
    int image_w[];
    int image_h[];
    int image_x[];
    int image_y[];
    Image sourceimage[];
    }
    La pagina web che richiama la mia applet ha il seguente codice:
    <applet code="menu.class" width="100" height="340">
    <param name="border width" value="2">
    <param name="buttons" value="17">
    <param name="color" value="000000">
    <param name="degree" value="20">
    <param name="direction" value="0">
    <param name="f_color" value="C0C0C0">
    <param name="f_color2" value="FFFF00">
    <param name="f_offset" value="1">
    <param name="f_size" value="11">
    <param name="f_style" value="0">
    <param name="font" value="Helvetica">
    <param name="image 0">
    <param name="label 0" value="Home page">
    <param name="link 0" value="http://www.prova.it/">
    <param name="position" value="1">
    <param name="style" value="0">
    </applet>
    //FINE APPLET

    Sapete dirmi perchè quando carico la pagina mi dice che non trova la classe menu?

    AIUTATEMI SONO DISPERATO.

    GRAZIE MILLE.

    MATTEO

  2. #2
    Utente di HTML.it L'avatar di Zalex
    Registrato dal
    Aug 2001
    Messaggi
    357
    zio ma!la divina commedia e' piu corta........
    mi si incrociano gli occhi a leggere il codice che hai postato.....
    cmq non e' che lo devi salvare in un .class......devi compilare un .java per ottenere il .class


  3. #3
    lo so infatti ho creato un file .java e poi l'ho compilato e ottenuto un file.class ma quando compilo un file applet devo compilarlo con qualche parametro?

    Cioè quando scrivo javac prova.java devo aggiungere qualcosa?

  4. #4
    Utente di HTML.it L'avatar di Zalex
    Registrato dal
    Aug 2001
    Messaggi
    357
    io non ho mai usato nessun parametro...i due file(l'hatml e il class intendo) stanno nella stessa dir?

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.