Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change IDEA's build folder from TEMP to something else?

Tags:

java

applet

Im trying to run:

import java.applet.Applet;
import java.awt.*;
import java.net.URL;

public class img extends Applet
{
    private Image img;
    public void init()
    {
        img = null;
    }
    public void loadImage()
    {
        try
        {
            img = getImage(getCodeBase(), "winter.jpg");
            System.out.println(img);
            System.out.println(prepareImage(img, 300, 400, this));
        }
        catch(Exception e){}

        System.out.println(getDocumentBase());
    }
    public void paint(Graphics g)
    {
        if (img == null)
            loadImage();
        g.drawImage(img, 0, 0, this);
    }
}

But it doesn't find winter.jpg unless its in: file:/C:/Users/Admin/AppData/Local/Temp/

System.out.println(getDocumentBase()); returns: file:/C:/Users/Admin/AppData/Local/Temp/AppletPage1228891259548967526.html Instead of: C:/Users/Admin/Dropbox/dev/idea/Exam3/out/production/Exam3/ (where the .class files are located)

I'm using IntelliJ IDEA 12.

I simply want to put my JPEGs in the Exam3 folder instead of the Temp folder. Any ideas?

like image 434
MK3GTX Avatar asked Nov 28 '25 02:11

MK3GTX


1 Answers

A workaround for loading the resource using getDocumentBase() you can get the URL by using the getResource of class which gets the resources relative to the class.

URL base = img.class.getResource("/data/winter.jpg");
Image img = ImageIO.read(base);

where data is a folder in the Exam3 folder in your case which contains this class file.

like image 162
flingo_1992 Avatar answered Nov 30 '25 17:11

flingo_1992



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!