Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为图像使用不同文件夹中的链接(Java)_Java_Image_Swing_Hyperlink - Fatal编程技术网

为图像使用不同文件夹中的链接(Java)

为图像使用不同文件夹中的链接(Java),java,image,swing,hyperlink,Java,Image,Swing,Hyperlink,我正在设计一个带有定制按钮的计算器。当然,我希望将图像文件组织在不同于包接口的文件夹中。 文件夹的位置是interfaces/Seven/Seven-normal.png,但每当我没有包含完整链接时 "C:\Liloka\Source\interfaces\Seven\seven-normal.png" 它不起作用,一切都消失了。我发誓我已经看到这是在正常的代码。如果我在适当的程序中使用它,我不能期望人们改变链接到他们放置代码的地方!以下是我一直使用的代码: seven =

我正在设计一个带有定制按钮的计算器。当然,我希望将图像文件组织在不同于包接口的文件夹中。 文件夹的位置是interfaces/Seven/Seven-normal.png,但每当我没有包含完整链接时

    "C:\Liloka\Source\interfaces\Seven\seven-normal.png" 
它不起作用,一切都消失了。我发誓我已经看到这是在正常的代码。如果我在适当的程序中使用它,我不能期望人们改变链接到他们放置代码的地方!以下是我一直使用的代码:

    seven = new ButtonImage("/Seven/seven-normal.png"); - Doesn't work
    nine = new ButtonImage("C:/Users/Liloka/workspace/WebsiteContent/src/interfaces/Nine/nine-normal.png"); - Does work
谢谢

"/Seven/seven-normal.png"
…是指向
C:\Seven\Seven normal.png的路径
-因为路径的最开始是
/
,这基本上意味着,
从驱动器的根目录转到“Seven”文件夹,然后加载“Seven normal.png”

您必须使用相对路径,例如,
“../../interfaces/Seven/Seven normal.png”
,或者只使用
“interfaces/Seven/Seven normal.png”

第一条路径将带您“上”两个文件夹,然后下到
interfaces/Seven/Seven normal.png
。本质上,您必须弄清楚代码运行在哪个文件夹下,也称为“工作目录”,并从那里构建一个相对路径

…是指向
C:\Seven\Seven normal.png的路径
-因为路径的最开始是
/
,这基本上意味着,
从驱动器的根目录转到“Seven”文件夹,然后加载“Seven normal.png”

您必须使用相对路径,例如,
“../../interfaces/Seven/Seven normal.png”
,或者只使用
“interfaces/Seven/Seven normal.png”


第一条路径将带您“上”两个文件夹,然后下到
interfaces/Seven/Seven normal.png
。基本上,您必须找出代码运行在哪个文件夹下,也称为“工作目录”,并从那里构建一个相对路径。

只需删除第一个正斜杠即可

seven = new ButtonImage("interfaces/Seven/seven-normal.png");

interfaces
是应该与JAR位于同一文件夹中的文件夹。

只需删除第一个正斜杠即可

seven = new ButtonImage("interfaces/Seven/seven-normal.png");

interfaces
是应该与JAR位于同一文件夹中的文件夹。

Ah right。。我认为这将意味着转到接口\7,就好像文件查找任何东西,比如另一个类,只要它在接口中,对我来说,它将首先查找任何东西;但显然不是。非常感谢。啊对。。我认为这将意味着转到接口\7,就好像文件查找任何东西,比如另一个类,只要它在接口中,对我来说,它将首先查找任何东西;但显然不是。非常感谢。