1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| /*
* AffProps.java
*
* Created on 18 février 2007, 16:18
*
*/
package praline;
import java.awt.Dimension;
import java.io.FileInputStream;
import java.util.Iterator;
import java.util.Locale;
import java.util.Properties;
import java.util.ResourceBundle;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.SwingUtilities;
public class AffProps
{
public static void main(String[] args) throws Exception
{
String nomprops;
final Properties props;
String nomrb;
final ResourceBundle rb;
nomrb = "props";
nomprops = nomrb+".properties";
if ((args != null) && (args.length > 0))
nomprops = args[0];
props = new Properties();
props.load(new FileInputStream(nomprops));
rb = ResourceBundle.getBundle(nomrb, Locale.getDefault());
// test en lisant le fichier directement
SwingUtilities.invokeLater(new java.lang.Runnable()
{
public void run()
{
JFrame frame;
JTextPane paneprops;
StringBuilder txtprops;
frame = new JFrame("Fichier properties!");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setPreferredSize(new Dimension(300, 400));
paneprops = new JTextPane();
txtprops = new StringBuilder();
Iterator it = props.keySet().iterator();
while(it.hasNext()) {
Object key = it.next();
txtprops.append(key.toString()+ " = "+props.get(key)+"\n");
}
paneprops.setText(txtprops.toString());
frame.getContentPane().add(new JScrollPane(paneprops));
frame.pack();
frame.setVisible(true);
}
});
// test en utilisant le ResourceBundle
SwingUtilities.invokeLater(new java.lang.Runnable()
{
public void run()
{
JFrame frame;
JTextPane paneprops;
StringBuilder txtprops;
frame = new JFrame("ResourceBundle!");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setPreferredSize(new Dimension(300, 400));
paneprops = new JTextPane();
txtprops = new StringBuilder();
Iterator it = props.keySet().iterator();
while(it.hasNext()) {
Object key = it.next();
txtprops.append(key.toString()+ " = "+rb.getString(key.toString())+"\n");
}
paneprops.setText(txtprops.toString());
frame.getContentPane().add(new JScrollPane(paneprops));
frame.pack();
frame.setVisible(true);
}
});
}
} |