Adding image in JApplet

前端 未结 1 1142
温柔的废话
温柔的废话 2021-01-14 12:13
ImageIcon icon= new ImageIcon(\"a.gif\");
JLabel jLabel1=new JLabel(icon);
jLabel1.setVisible(true);
card1.add(jLabel1);

I am a newbie to Java and

1条回答
  •  广开言路
    2021-01-14 13:02

    public void init() 
        URL imageURL = new URL(getDocumentBase(), "a.gif");
        Image image = getImage(imageURL);
        ImageIcon icon = new ImageIcon(image);
        // ...
    

    The ImageIcon constructor that accepts a String presumes the string represents the path & file name of a File.

    Only trusted applets can access a File, and then only on the client file-system (not the server). If this is an application resource, it should be on the server, and can be accessed by URL.

    Note that the ImageIcon constructor will also accept an URL, rather than the Image used above. I just wanted to highlight that applets have an inbuilt method to obtain images.

    0 讨论(0)
提交回复
热议问题