• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getImage() open image

 
Arun Maalik
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.net.URL;
import java.applet.*;
import java.awt.*;
public class first extends Applet{

Image abc;

public void init(){
try{
URL p=new URL("D:/MyPhoto");
abc=getImage(p,"ARUN1.JPEG");
}
catch(Exception e){}


}

public void paint(Graphics g){
g.drawImage(abc,30,30,this);
}
}

Helo sir in the above code I would like to draw a image through Applet. Image is stored on D:\MyPhoto\ARUN1.JPEG. But after runing this applet trough appletvier it is throughin a lot of Exception why?
I think U can n't open any object which has stored on local system on which U r runing the applet. M I RIGHT SIR?
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have two FAQ pages that are hightly relevant to your question:

UseRealWords, which explains that "U" and "R" and "M" are not real words, and should be avoided in these (and other) forums, and HowCanAnAppletReadFilesOnTheLocalFileSystem, which explains at least some of the exceptions you are seeing.
[ July 18, 2006: Message edited by: Ulf Dittmer ]
 
Arun Maalik
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sir i studied what U told and i found that from local system there is other way to access the image . But it is also not working.It is throwing some other types of Exception cod and exception are as follow.

import java.net.URL;
import java.applet.*;
import java.awt.*;
public class first extends Applet{
Image abc;
public void init(){
abc=Toolkit.getDefaultToolkit().getImage("D:/MyPhoto");
}
public void paint(Graphics g){
g.drawImage(abc,30,30,this);
}
}

java.security.AccessControlException:access denied (java.io.FilePermission D:/MyPhoto read)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:272)
at java.lang.SecurityManager.checkPermission(SecurityManager.java.545)
at java.lang.SecurityManager.checkPermission(SecurityManager.java.890)
at sun.awt.SunToolKit.getImageFromHash(SunToolKit.java:266)
at sun.awt.SunToolKit.getImage(SunToolKit.java:266)
at first.init(first.java:7)
at sun.applet.AppletPanel.run(AppletPanel.java:344)
at java.lang.Thread.run(Thread.java.484)

with regard
Arun kumar maalik
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It does not matter how you access the local file - you'll always get security exceptions. Have you read the article I linked to, which explains what you need to do to get around these exceptions?
 
Arun Maalik
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sir i m unable to understand by the link which U have provide me. I m not geting more there. I have done all thing but exception r contuneu. if possible give me the code of applet file which load a image from a local file System. Also one thing that i would like to know that , can i load a image in a frame also?


with regard

Arun kumar maalik
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arun, please read the article linked above titled "UseRealWords". We have many non-native English speakers on this site for whom abbreviations like "U", "M" and "R" mean nothing. Don't make it harder for them than necessary to follow the discussion, and restrict those abbreviations to text messaging.

As to the problem, you don't need any code to solve it. An applet is not allowed to access the local file system, unless it is digitally signed, or you have altered the local policy file. Both methods are described in the page linked above. Neither are trivial topics (security topics rarely are); if you have trouble understanding them, let us know specifically where you are stuck, and we'll try to get you going again.
[ July 18, 2006: Message edited by: Ulf Dittmer ]
 
Arun Maalik
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry sir further i will try my label best to use real word. sorry realy sorry. i m going to study that link now . and sir can i load a Image in a frame ?

with regard

Arun kumar maalik
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you can load an image in whatever class you want, and you can certainly display it in a in a Panel that's part of a Frame.
 
Arun Maalik
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks sir i loaded image in my applet from local file System by the policy tool given in java

with regard
Arun kumar maalik
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic