iamhavingahardtimefiguringouthowtoshowanimage (orimageicon ) ina Java applet.thefollowingismycode.the picture (test.BMP ) ) doesexistandisontheddrivebutwhenirunthisigettheappletwindowwithnothinginit.cansomebodytellmewhatiammmissingtomaketheimageicon
公共类表单1扩展SJ小程序{
公共语音init (
I=新图像Icon (d : (test.BMP );
}
公共语音绘制(图形) {
I.painticon(this,g,0,0 );
}
}
Thanks、lkdys/p解决方案
参考yourimagethroughanabsolutelocalfilepathmightnotworkwhenyourunyourappletfromaserver.usetheimageicon (结构控制器esourceontheserver.usethejapplet.getcode base (todeterminewhereyourappletoriginant
公共类表单1扩展SJ小程序{
Image i;
公共语音init (
try {
I=imageio.read (newurl (getcode base )、' test.bmp ' );
}catch(malformedurlexceptionex ) )
ex.printStackTrace (;
}catch(ioexceptionex ) {
ex.printStackTrace (;
}
}
公共语音绘制(图形) {
g.drawimage(I,0,0,null );
}
}
edit : imageiosupportsbmpandthechangedsampleworksforme。
edit 23360 ifitstilldoesn ' tdisplaytheimage,try ' ./test.BMP ' becausewhenyourunanappletfromletssayeclipseithasthebindirirage
edit : ifyouputyourtest.bmpintothejarorontheclasspath,youcanloaditusingthesamewaybutreplacing
newURL(getcodebase )、' test.bmp ' ) ) )。
微信
form1. class.get resource (' test.BMP ' ) )。