2013-11-21 27 views
0

我的主類(擴展小程序)顯示一個絕對路徑的圖像,但我不知道如何讓它從我的html所在的文件夾中獲取路徑。小應用程序與圖像

try { 
     tutorial2 = TextureLoader.getTexture("PNG", new FileInputStream(
       new File("D:/eclipse/workspace/Final/res/tutorial2.png"))); 

    } catch (IOException e) { 
     e.printStackTrace(); 
     System.err.println("Nu s-a gasit imaginea"); 
    } 

但我的html applet是在另一個目錄中,我希望當你移動html仍然查看圖像。

+1

您可能會發現[如何使小程序(HTTP:/ /docs.oracle.com/javase/tutorial/uiswing/components/applet.html)教程有幫助 – MadProgrammer

回答

0

複製圖像(tutorial2.png)和圖像粘貼到文件夾中保存了上面的類,然後做這個

tutorial2 = TextureLoader.getTexture("PNG", new FileInputStream(
       new File("tutorial2.png"))); 
+0

java.io.FileNotFoundException:tutorial2.png(系統找不到指定的文件) \t at java.io.FileInputStream.open (Native Method) \t at java.io.FileInputStream。 (來源不明) \t在Tanc.Game.setUpEntity(Game.java:1128) \t在Tanc.Game.gameLoop(Game.java:230) \t在Tanc.Game $ 1.run(Game.java:143 ) 女SA gasit imaginea 異常在線程 「螺紋-144」 顯示java.lang.NullPointerException \t在Tanc.Game.INTRO(Game.java:858) \t在Tanc.Game.gameLoop(Game.java:266) \t at Tanc.Game $ 1.run(Game.java:143) – user2979622

+0

URL url = this.getCodeBase(); \t \t String url = url.getPath(); \t \t System.out.println(urls); /D:/ work/t/bin/ 這是圖像,它是正確的,但我的小程序dosent看到它。 – user2979622

+0

你正在使用哪個工具來創建你的項目(netbeans或eclipse)? – Ashish

相關問題