Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would recommend placing your options into some sort of file (whether it be xml or a .properties) especially if the values can change (such as a database username, etc). I would also say that you can break up these configuration files by component. Just like you break up your code, the components that need database information likely do not need image paths. So you can have a file for database info, image path info, etc. Then have your components load the file that they need. </p> <p>In the java-specific case, you can put these files on your classpath and have your components reference them. I like using .properties files because java has a nice class, <a href="http://docs.oracle.com/javase/6/docs/api/java/util/Properties.html" rel="nofollow">Properties</a>, for dealing with them.</p> <p>So here's a tiny example for an image provider that gives you a BufferedImage, given the filename.</p> <p>image.properties</p> <pre><code> icon.path=/path/to/my/icons background.path=/path/to/my/backgrounds </code></pre> <p>Make sure this file is on your classpath. Then here's my provider class</p> <pre><code> public class ImageProvider { private static final String PROP_FILE = "image.properties"; private static final String ICON_PATH = "icon.path"; private Properties properties; public ImageProvider() { properties = new Properties(); properties.load(getClass().getClassLoader().getResourceAsStream(PROP_FILE)); } public BufferedImage getIcon(String icon) { return ImageIO.read(properties.getProperty(ICON_PATH) + icon); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload