Java Reference
In-Depth Information
L ISTING 8.5 Continued
loader = getClass().getClassLoader();
getContentPane().setLayout(new BorderLayout());
getContentPane().add(getToolBar(), BorderLayout.NORTH);
getContentPane().add(new TextArea(), BorderLayout.CENTER);
setTitle(“A Text Editor”);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(WindowEvent e) {
private JToolBar getToolBar() {
JToolBar jt = new JToolBar();
Icon saveIcon = new ImageIcon(loader.getResource(“images/Save16.gif”));
Icon findIcon = new ImageIcon(loader.getResource(“images/Find16.gif”));
jt.add(new JButton(saveIcon));
jt.add(new JButton(findIcon));
return jt;
private void exit() {
public static void main(String[] a) {
Editor1 ed1 = new Editor1();
The most important thing to note here is how items contained in the delivered resources are
accessed by the application. At line 22 in Listing 8.5, an icon is created that accesses a GIF file
in the editor1 JAR file. This is the simplest way to access items in application resources. Note
also that to access items, we need to use the JFrame 's classloader (see lines 15 and 17 in
Listing 8.5).
Search WWH ::

Custom Search