Avatar billede net-city Nybegynder
28. marts 2005 - 05:59 Der er 8 kommentarer og
1 løsning

Fejl ved compile til .class

Hejsa, en der vil compile denne kode, da mit compile program er blevet slettet?

---->

package tisdk;

import java.applet.Applet;
import java.awt.*;
import java.io.IOException;
import java.io.PrintStream;
import java.net.*;
import java.util.*;



public class test extends Applet
    implements Runnable
{

    public test()
    {
        guid = "";
        properties = new Properties();
        clothes = "0";
        face = "0";
        hair = "0";
        sex = 1;
        color = 0;
        hairIdx = 0;
        clothesIdx = 0;
        faceIdx = 0;
        availableClothes = "0";
        availableFace = "0";
        availableHair = "0";
        reverse = false;
        run = true;
        thisThread = new Thread(this);
    }

    public void init()
    {
        guid = getParameter("GUID");
        try
        {
            URLConnection urlCon = null;
            URL url = new URL(getCodeBase().toString() + "http://hhsrv.n.dk/ClothesSelector/clothesselector.ini");
            urlCon = url.openConnection();
            properties.load(urlCon.getInputStream());
        }
        catch(MalformedURLException mue)
        {
            mue.printStackTrace();
        }
        catch(IOException ioe)
        {
            ioe.printStackTrace();
        }
        sex = Integer.parseInt(getParameter("sex"));
        color = Integer.parseInt(getParameter("color"));
        container = new GraphicsContainer(this, sex, color);
        clothes = getParameter("clothes");
        face = getParameter("face");
        hair = getParameter("hair");
        availableClothes = getParameter("availableClothes");
        availableFace = getParameter("availableFace");
        availableHair = getParameter("availableHair");
        containerThread = new Thread(container);
        queueImages();
    }

    public void queueImages()
    {
        String job;
        for(StringTokenizer hairTokens = new StringTokenizer(availableHair, "|"); hairTokens.hasMoreTokens(); container.queueHair(job))
            job = hairTokens.nextToken();

        String job;
        for(StringTokenizer faceTokens = new StringTokenizer(availableFace, "|"); faceTokens.hasMoreTokens(); container.queueFace(job))
            job = faceTokens.nextToken();

        String job;
        for(StringTokenizer clothesTokens = new StringTokenizer(availableClothes, "|"); clothesTokens.hasMoreTokens(); container.queueClothes(job))
            job = clothesTokens.nextToken();

        container.getClass();
        container.queueCustom(container.imagePath + "root.gif");
        container.queueCustom("http://hhsrv.n.dk/ClothesSelector/background.gif");
        thisThread.start();
        containerThread.start();
    }

    public void run()
    {
        do
        {
            repaint();
            try
            {
                Thread.sleep(500L);
            }
            catch(InterruptedException e)
            {
                e.printStackTrace();
            }
        } while(true);
    }

    public Color getColor(String colorname)
    {
        StringTokenizer tokenizer = new StringTokenizer(properties.getProperty(colorname, "0 0 0"));
        int r = Integer.parseInt(tokenizer.nextToken());
        int g = Integer.parseInt(tokenizer.nextToken());
        int b = Integer.parseInt(tokenizer.nextToken());
        return new Color(r, g, b);
    }

    public void locateLayout()
    {
        for(int i = 0; i < container.hairJobs.size(); i++)
        {
            String img = (String)container.hairJobs.elementAt(i);
            if(!img.equals(hair))
                continue;
            hairIdx = i;
            break;
        }

        for(int i = 0; i < container.faceJobs.size(); i++)
        {
            String img = (String)container.faceJobs.elementAt(i);
            if(!img.equals(face))
                continue;
            faceIdx = i;
            break;
        }

        for(int i = 0; i < container.clothesJobs.size(); i++)
        {
            String img = (String)container.clothesJobs.elementAt(i);
            if(!img.equals(clothes))
                continue;
            clothesIdx = i;
            break;
        }

    }

    public void paintPreload(Graphics g)
    {
        g.setColor(getColor("backgroundColor"));
        g.fillRect(0, 0, getBounds().width, getBounds().height);
        g.setColor(getColor("textColor"));
        FontMetrics metrics = g.getFontMetrics();
        String text = "Indl\346ser lortet: ";
        int x = getBounds().width / 2 - metrics.stringWidth(text);
        int y = getBounds().height / 2;
        g.drawString(text + (container.preloadedPercentage() <= 100 ? container.preloadedPercentage() : 100) + "%", x, y);
        x = 3;
        int progressHeight = 15;
        y += progressHeight / 2;
        int progressBorder = 1;
        int progressWidth = getBounds().width - x * 2;
        g.setColor(getColor("progressBorderColor"));
        g.fillRect(x, y, progressWidth, progressHeight);
        g.setColor(getColor("progressBackgroundColor"));
        g.fillRect(x + progressBorder, y + progressBorder, progressWidth - progressBorder * 2, progressHeight - progressBorder * 2);
        double value = (double)container.preloadedPercentage() / 100D;
        double progressWidthPercentage = (int)((double)progressWidth * value);
        int pers = (int)progressWidthPercentage;
        g.setColor(getColor("progressBarColor"));
        g.fillRect(x + progressBorder, y + progressBorder, pers - progressBorder * 2, progressHeight - progressBorder * 2);
    }

    public void paintMain(Graphics g)
    {
        int width = getBounds().width;
        int height = getBounds().height;
        g.setColor(getColor("backgroundColor"));
        g.fillRect(0, 0, width, height);
        Image bg = getImage(getCodeBase(), "http://hhsrv.n.dk/ClothesSelector/background.gif");
        g.drawImage(bg, 0, 0, this);
        container.getClass();
        rootImg = getImage(getCodeBase(), container.imagePath + "root.gif");
        g.drawImage(rootImg, width / 2 - rootImg.getWidth(this) / 2, (height - rootImg.getHeight(this)) / 2, this);
        int imagesBaseline = (height - rootImg.getHeight(this)) / 2 + rootImg.getHeight(this);
        paintClothes(g);
        if(reverse)
        {
            paintFace(g);
            paintHair(g);
        } else
        {
            paintHair(g);
            paintFace(g);
        }
    }

    public void paintHair(Graphics buffer)
    {
        int width = getBounds().width;
        int height = getBounds().height;
        int imagesBaseline = (height - rootImg.getHeight(this)) / 2 + rootImg.getHeight(this);
        if(hairIdx > 0)
        {
            Image prevHairImg = container.hair[hairIdx - 1];
            buffer.drawImage(prevHairImg, 10, 10, this);
        }
        Image hairImg = container.hair[hairIdx];
        if(hairImg != null)
            buffer.drawImage(hairImg, width / 2 - hairImg.getWidth(this) / 2, imagesBaseline - hairImg.getHeight(this), this);
        if(hairIdx < container.hair.length - 1)
        {
            Image nextHairImg = container.hair[hairIdx + 1];
            buffer.drawImage(nextHairImg, width - 10 - nextHairImg.getWidth(this), 10, this);
        }
    }

    public void paintFace(Graphics buffer)
    {
        int width = getBounds().width;
        int height = getBounds().height;
        int imagesBaseline = (height - rootImg.getHeight(this)) / 2 + rootImg.getHeight(this);
        if(faceIdx > 0)
        {
            Image prevFaceImg = container.face[faceIdx - 1];
            buffer.drawImage(prevFaceImg, 10, (height - prevFaceImg.getHeight(this)) / 2, this);
        }
        Image faceImg = container.face[faceIdx];
        if(faceImg != null)
            buffer.drawImage(faceImg, width / 2 - faceImg.getWidth(this) / 2, imagesBaseline - faceImg.getHeight(this), this);
        if(faceIdx < container.face.length - 1)
        {
            Image nextFaceImg = container.face[faceIdx + 1];
            buffer.drawImage(nextFaceImg, width - 10 - nextFaceImg.getWidth(this), (height - nextFaceImg.getHeight(this)) / 2, this);
        }
    }

    public void paintClothes(Graphics buffer)
    {
        int width = getBounds().width;
        int height = getBounds().height;
        int imagesBaseline = (height - rootImg.getHeight(this)) / 2 + rootImg.getHeight(this);
        if(clothesIdx > 0)
        {
            Image prevClothesImg = container.clothes[clothesIdx - 1];
            buffer.drawImage(prevClothesImg, 10, height - 10 - prevClothesImg.getHeight(this), this);
        }
        Image clothesImg = container.clothes[clothesIdx];
        if(clothesImg != null)
            buffer.drawImage(clothesImg, width / 2 - clothesImg.getWidth(this) / 2, imagesBaseline - clothesImg.getHeight(this), this);
        if(clothesIdx < container.clothes.length - 1)
        {
            Image nextClothesImg = container.clothes[clothesIdx + 1];
            buffer.drawImage(nextClothesImg, width - 10 - nextClothesImg.getWidth(this), height - 10 - nextClothesImg.getHeight(this), this);
        }
    }

    public void prevHair()
    {
        if(hairIdx > 0)
            hairIdx--;
        repaint();
    }

    public void nextHair()
    {
        if(hairIdx < container.hair.length - 1)
            hairIdx++;
        repaint();
    }

    public void prevFace()
    {
        if(faceIdx > 0)
            faceIdx--;
        repaint();
    }

    public void nextFace()
    {
        if(faceIdx < container.face.length - 1)
            faceIdx++;
        repaint();
    }

    public void prevClothes()
    {
        if(clothesIdx > 0)
            clothesIdx--;
        repaint();
    }

    public void nextClothes()
    {
        if(clothesIdx < container.clothes.length - 1)
            clothesIdx++;
        repaint();
    }

    public void reverse()
    {
        reverse = !reverse;
        repaint();
    }

    public void submit()
    {
        try
        {
            String _hair = (String)container.hairJobs.elementAt(hairIdx);
            String _face = (String)container.faceJobs.elementAt(faceIdx);
            String _clothes = (String)container.clothesJobs.elementAt(clothesIdx);
            URL url = new URL(getCodeBase(), "http://hhsrv.n.dk/ClothesSelector/saveAvatar.asp?guid=" + guid + "&hair=" + _hair + "&face=" + _face + "&clothes=" + _clothes + "&reverse=" + reverse);
            url.openConnection();
            url.openStream();
        }
        catch(MalformedURLException ignore)
        {
            ignore.printStackTrace();
        }
        catch(IOException ioe)
        {
            ioe.printStackTrace();
        }
        System.out.println("Saved...");
    }

    public void update(Graphics g)
    {
        imageBuffer = createImage(getBounds().width, getBounds().height);
        Graphics buffer = imageBuffer.getGraphics();
        if(container.isPreloaded)
            paintMain(buffer);
        else
            paintPreload(buffer);
        paint(buffer);
        buffer.dispose();
        g.drawImage(imageBuffer, 0, 0, null);
    }

    public void paint(Graphics g1)
    {
    }

    private Image imageBuffer;
    private Image rootImg;
    private String guid;
    public Properties properties;
    public String clothes;
    public String face;
    public String hair;
    public int sex;
    public int color;
    public int hairIdx;
    public int clothesIdx;
    public int faceIdx;
    public GraphicsContainer container;
    public String availableClothes;
    public String availableFace;
    public String availableHair;
    public boolean reverse;
    public boolean run;
    public Thread containerThread;
    public Thread thisThread;
}
Avatar billede arne_v Ekspert
28. marts 2005 - 10:21 #1
Det compiler slet ikke så ....
Avatar billede jakand Nybegynder
28. marts 2005 - 11:25 #2
Klassen kan ikke compile da:

- Klassen GraphicsContainer mangler
- Variablen 'job' bliver erklæret 3 gange i funktionen queueImages()
Avatar billede kalp Novice
28. marts 2005 - 12:11 #3
hvis det er fordi du gerne vil bruge job variablen igen, men slette alt der var i den skal du gøre sådan her.. og ellers skal du slette 2 af disse i metoden

String job ;

  public void queueImages()
    {
        String job = "";
        for(StringTokenizer hairTokens = new StringTokenizer(availableHair, "|"); hairTokens.hasMoreTokens(); container.queueHair(job))
            job = hairTokens.nextToken();

        String job = "";
        for(StringTokenizer faceTokens = new StringTokenizer(availableFace, "|"); faceTokens.hasMoreTokens(); container.queueFace(job))
            job = faceTokens.nextToken();

        String job = "";
        for(StringTokenizer clothesTokens = new StringTokenizer(availableClothes, "|"); clothesTokens.hasMoreTokens(); container.queueClothes(job))
            job = clothesTokens.nextToken();

        container.getClass();
        container.queueCustom(container.imagePath + "root.gif");
        container.queueCustom("http://hhsrv.n.dk/ClothesSelector/background.gif");
        thisThread.start();
        containerThread.start();
    }
Avatar billede arne_v Ekspert
28. marts 2005 - 12:15 #4
Den compiler da lige så lidt som originlen ....
Avatar billede net-city Nybegynder
28. marts 2005 - 16:16 #5
Vil bare gerne have den til og du igen.
Avatar billede jakand Nybegynder
28. marts 2005 - 17:08 #6
Hvis du vil have en til at compile den for dig, så må jo vedlægge GraphicsContainer klassen.
Avatar billede net-city Nybegynder
28. marts 2005 - 17:42 #7
Hmm, prøv lav class filen uden grapichs
Avatar billede alister_crowley Nybegynder
29. marts 2005 - 12:39 #8
net-city

Hvad med at spørge forfatteren af den applet ?-) Han ved sikkert hvad du mangler, og hvordan du skal compile den, der skal jo nogle gange nogle packages med i classpath.
Avatar billede net-city Nybegynder
21. juni 2005 - 20:30 #9
g
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester