Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision |
| student:java:resources [2023/03/30 19:01] – bernstdh | student:java:resources [2025/10/27 16:36] (current) – bernstdh |
|---|
| ==== Icons ==== | ==== Icons ==== |
| |
| To easiest way to refer to icons in a portable fashion is to use a ''%%URL%%'' object (from the ''%%java.net%%'' package), and the easiest way to get the appropriate ''%%URL%%'' object is to use a ''%%Class%%'' object. For example, if you want to get the ''%%URL%%'' for a resource named ''%%logo.png%%'' that is in the ''%%icons%%'' directory **under the top-level directory containing the class of the object referred to by ''%%this%%''** then you would do the following: | To easiest way to refer to icons in a portable fashion is to use a ''%%URL%%'' object (from the ''%%java.net%%'' package), and the easiest way to get the appropriate ''%%URL%%'' object is to use a ''%%Class%%'' object. For example, if you want to get the ''%%URL%%'' for a resource named ''%%logo.png%%'' that is in the ''%%images%%'' directory **under the top-level directory containing the class of the object referred to by ''%%this%%''** then you would do the following: |
| |
| <code java> | <code java> |
| URL url = this.getClass().getResource("/images/logo.png"). | URL url = this.getClass().getResource("images/logo.png"). |
| </code> | </code> |
| |
| |
| <code java> | <code java> |
| InputStream is = this.getClass().getResource("/configurations/config.txt"). | InputStream is = this.getClass().getResourceAsStream("configurations/config.txt"). |
| </code> | </code> |
| |