Yuet Sim Lee wrote:

> Hi,
>
> I knew that getImage() could
> load an image file from the
> network and paint() could
> display it.
>
> However, I don't know how can I
> get an image which is a local
> file. I tried
>
>  Image i = getImage( String filename )
>
> It can not be compiled and the
> compiler said:
>
> Incompatible type for method. Can't convert java.lang.String to java.net.URL.
>     i = getImage("houses.gif");
>

Check the Java tutorial java.sun.com go to documentation->tutorial

And check the section Using images essentially the things work like this

>From the Java tutorial:

Using the getImage Methods

    This section discusses first the Toolkit getImage methods and then the
Applet getImage methods.

    The Toolkit class declares two getImage methods:

        Image getImage(URL url)
        Image getImage(String filename)

    Here are examples of using the Toolkit getImage methods. Although every Java
application and applet can use these methods, applets are subject to the usual
security
    restrictions. In particular, untrusted applets can't successfully specify a
filename to getImage because untrusted applets can't load data from the local
file system. You can
    find information about restrictions on untrusted applets in Security
Restrictions.

        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Image image1 = toolkit.getImage("imageFile.gif");
        Image image2 = toolkit.getImage(
            new URL("http://java.sun.com/graphics/people.gif"));

Good Luck!



----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to