import java.util.*; import java.io.*; import java.beans.*; import java.beans.Expression; import java.awt.*; import javax.swing.*; public class ResourcesExample { public static void main(String[] args) throws Exception { // Load resource bundle. ResourceBundle resources = ResourceBundle.getBundle("resources.Stylepad"); // Create the user interface. JFrame frame = new JFrame(); frame.setTitle(resources.getString("Title")); frame.setName("Stylepad"); Container c = frame.getContentPane(); c.add(new JLabel(resources.getString("colorLabel"))); frame.pack(); frame.show(); // Create the encoder. XMLEncoder e = new XMLEncoder( new BufferedOutputStream( new FileOutputStream("ResourcesExample.xml"))); // Tell the encoder how to locate the resource bundle. e.writeExpression(new Expression(ResourceBundle.class, "getBundle", new Object[]{"resources.Stylepad"})); // Tell the encoder how to locate the objects in the resource bundle. Enumeration keys = resources.getKeys(); while(keys.hasMoreElements()) { Object key = keys.nextElement(); e.writeExpression(new Expression(resources, "getObject", new Object[]{key})); } // Write the XML document. e.writeObject(frame); e.close(); System.exit(0); } }