URL along with the relative location of the image, which would That callĪgain, once you have the URL, you can load the file by using the Will get you the base URL you need to load the image. Suppose you have your CLASS files in a directory called CLASSESĪnd the image you want (still called IMAGE.gif) is stored in a Want to call getCodeBase() to obtain an URL for an image. (or a subdirectory of that directory) as your CLASS files, you'd If you're storing your images in the same directory The getCodeBase() method works similarly to getDocumentBase(),Įxcept that it returns the URL of the directory from which theĪpplet was loaded. Of the image file, would be FILE:/C:/MYHOMEPAGE/IMAGES/IMAGE.gif. This new URL, once you included the relative location ![]() That new directory, without your having to change the applet's The call to getDocumentBase() will give you the URL for If youĭecided to move your public files to a directory called MYHOMEPAGE, The file would then be FILE:/C:/PUBLIC/IMAGES/IMAGE.gif. Which in this case would be IMAGES/IMAGE.gif. ![]() That call looks like this:Īs you'll soon see, once you have the URL, you can load the fileīy using the URL along with the relative location of the image, Suppose you have your HTML documents in a directory called PUBLICĪnd the image you want, called IMAGE.gif, is stored in a subdirectory Of that directory) as your HTML files, you'd want to use this If you're storing your images in the same directory (or a subdirectory The URL of the directory from which the HTML document was loaded. URL of the directory from which the applet was run.Įxample: Using the getDocumentBase() MethodĪs I said previously, the getDocumentBase() method returns The current HTML file was loaded, whereas the latter returns the The former returns the URL of the directory from which You move the graphics file to a different directory on your disk.Ī better way to create the image's URL object is to callĮither the getDocumentBase() or getCodeBase() However, you have to change and recompile the applet whenever ![]() Image's URL directly into your Java source code. In order to do so, you need to create an URL object that The first step in displaying an image in your applet is to load In this book, you'll use GIF files, which are moreĬommon, although JPEG files are rapidly gaining a reputation,Įspecially for high-resolution, true-color images. Small price, however, since Java can load only GIF and JPEG imageįile formats. On the other hand, comes complete with classes that are capable To write all the file-loading code from scratch, anyway. Language like C++, you could choose to support whatever image If you were writing your Internet applications using a more conventional The PCX graphics file type, for example,īegan as the format for PC Paintbrush files, whereas BMP filesĪre usually associated with the Windows graphical interface. Of these file types was created by third-party software companiesįor use with their products, but many became popular enough to PCX, BMP, GIF, JPEG (or JPG), TIFF (or TIF), TGA, and more. Types are usually identified by their file extensions, which include Of which is associated with a specific file format. In the world of computers, there are many types of images, each In this chapter, you use Java's power to add images Hand, was designed to make creating applets as easy as possible.įor that reason, Java's classes handle almost all the difficultiesĪssociated with displaying images (commonly called bitmaps) and Handling these graphical and aural chores. Even the WindowsĪPI, as immense as it is, provides little help when it comes to When programming in a language such aĬ++, displaying graphics and playing sounds can be infamouslyĭifficult, thanks to the fact that these languages provide noĭirect support for handling these types of files. You've undoubtedly noticed that many of them feature vivid graphicsĪnd even sound effects. If you've seen a lot of the applets that are floating around, ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |