// -*- mode:java; encoding:utf-8 -*-
// vim:set fileencoding=utf-8:
// @homepage@

package example;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Optional;
import javax.imageio.ImageIO;
import javax.swing.*;

public final class MainPanel extends JPanel {
  private final transient TexturePaint texture;

  private MainPanel() {
    super(new BorderLayout());
    BufferedImage bi = Optional.ofNullable(getClass().getResource("16x16.png"))
        .map(url -> {
          try {
            return ImageIO.read(url);
          } catch (IOException ex) {
            return makeMissingImage();
          }
        }).orElseGet(MainPanel::makeMissingImage);
    texture = new TexturePaint(bi, new Rectangle(bi.getWidth(), bi.getHeight()));

    add(new JLabel("@title@"));
    setOpaque(false);
    setPreferredSize(new Dimension(320, 240));
  }

  @Override protected void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D) g.create();
    g2.setPaint(texture);
    g2.fillRect(0, 0, getWidth(), getHeight());
    g2.dispose();
    super.paintComponent(g);
  }

  private static BufferedImage makeMissingImage() {
    Icon missingIcon = UIManager.getIcon("OptionPane.errorIcon");
    int w = missingIcon.getIconWidth();
    int h = missingIcon.getIconHeight();
    BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = bi.createGraphics();
    missingIcon.paintIcon(null, g2, 0, 0);
    g2.dispose();
    return bi;
  }

  public static void main(String[] args) {
    EventQueue.invokeLater(MainPanel::createAndShowGui);
  }

  private static void createAndShowGui() {
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
      ex.printStackTrace();
      Toolkit.getDefaultToolkit().beep();
    }
    JFrame frame = new JFrame("@title@");
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.getContentPane().add(new MainPanel());
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }
}

@@ -178,16 +178,44 @@
 eption;%0A
+import java.io.InputStream;%0A
 import j
@@ -233,16 +233,16 @@
 tional;%0A
-
 import j
@@ -432,24 +432,132 @@
 rLayout());%0A
+    String path = %22example/16x16.png%22;%0A    ClassLoader cl = Thread.currentThread().getContextClassLoader();%0A
     Buffered
@@ -591,18 +591,10 @@
 ble(
-getClass()
+cl
 .get
@@ -606,64 +606,75 @@
 rce(
-%2216x16.png%22))%0A        .map(url -%3E %7B%0A          try %7B%0A    
+path)).map(url -%3E %7B%0A      try (InputStream s = url.openStream()) %7B%0A
     
@@ -701,18 +701,12 @@
 ead(
-url);%0A    
+s);%0A
     
@@ -734,24 +734,50 @@
 n ex) %7B%0A    
+    ex.printStackTrace();%0A
         retu
@@ -805,26 +805,18 @@
 ;%0A      
-    %7D%0A    
+%7D%0A
     %7D).o

use try-with-resources