java - How to load and use images in applets? -
i've been going @ 2 days , can't find way how load images properly. applet going run locally on different computer, , it's not in jar file (for 1 previous applet, same project, i've used .class files , used them in directly in html source code). questions is: how load , use images have relative path (possibly next .class files) ? here's part of code
try { image = null; inputstream = new bufferedinputstream( new fileinputstream( system.getproperty("user.dir")+"\\toshiba.jpeg" )); image = imageio.read(is); image = image.getscaledinstance(400,200,image.scale_smooth); } catch (ioexception e) {} icon ic = new imageicon(image);
@roxasshadow try use
getdocumentbase().
@nick992 tried , returns null, think i've read somewhere can use applets accessed on remote websites , not locally.
there no accounting people think.

import java.awt.gridlayout; import javax.swing.*; // <applet code=whereamiapplet width=500 height=50></applet> public class whereamiapplet extends japplet { @override public void init() { setlayout(new gridlayout(0,1,5,5)); add(new jlabel("document base: " + getdocumentbase())); add(new jlabel("code base: " + getcodebase())); } }
Comments
Post a Comment