package example;
//-*- mode:java; encoding:utf-8 -*-
// vim:set fileencoding=utf-8:
//@homepage@
import java.awt.*;
import java.awt.datatransfer.*;
import java.awt.event.*;
import java.io.IOException;
import java.util.Objects;
import javax.jnlp.*;
import javax.swing.*;

public final class MainPanel extends JPanel {
    private final JLabel label = new JLabel();
    private final ClipboardService cs;
    public MainPanel() {
        super(new BorderLayout());

        ClipboardService tmp;
        try {
            tmp = (ClipboardService) ServiceManager.lookup("javax.jnlp.ClipboardService");
        } catch (UnavailableServiceException ex) {
            tmp = null;
        }
        cs = tmp;
        add(new JScrollPane(label));
        add(new JButton(new AbstractAction("get Clipboard DataFlavor") {
            @Override public void actionPerformed(ActionEvent e) {
                try {
                    Transferable t = Objects.nonNull(cs) ? cs.getContents() : Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
                    if (Objects.isNull(t)) {
                        Toolkit.getDefaultToolkit().beep();
                        return;
                    }
                    String str = "";
                    ImageIcon image = null;
                    if (t.isDataFlavorSupported(DataFlavor.imageFlavor)) {
                        image = new ImageIcon((Image) t.getTransferData(DataFlavor.imageFlavor));
                    } else if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                        str = (String) t.getTransferData(DataFlavor.stringFlavor);
                    }
                    label.setText(str);
                    label.setIcon(image);
                } catch (UnsupportedFlavorException | IOException ex) {
                    ex.printStackTrace();
                }
            }
        }), BorderLayout.SOUTH);
        setPreferredSize(new Dimension(320, 240));
    }
    public static void main(String... args) {
        EventQueue.invokeLater(new Runnable() {
            @Override public void run() {
                createAndShowGUI();
            }
        });
    }
    public static void createAndShowGUI() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException | InstantiationException
               | IllegalAccessException | UnsupportedLookAndFeelException ex) {
            ex.printStackTrace();
        }
        JFrame frame = new JFrame("@title@");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.getContentPane().add(new MainPanel());
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}

@@ -211,23 +211,17 @@
 va.util.
-Objects
+*
 ;%0Aimport
@@ -373,27 +373,64 @@
 nal 
-ClipboardService cs
+JButton button = new JButton(%22get Clipboard DataFlavor%22)
 ;%0A  
@@ -487,25 +487,24 @@
 out());%0A
-%0A
         
 Clipboar
@@ -499,28 +499,16 @@
     
-ClipboardService tmp
+Object o
 ;%0A  
@@ -535,32 +535,11 @@
     
-tmp = (ClipboardService)
+o =
  Ser
@@ -652,19 +652,17 @@
         
-tmp
+o
  = null;
@@ -684,198 +684,125 @@
     
-cs = tmp;%0A        add(new JScrollPane(label));%0A        add(new JButton(new AbstractAction(%22get Clipboard DataFlavor%22) %7B%0A            @Override public void actionPerformed(ActionEvent e) %7B%0A   
+Optional%3CClipboardService%3E csOp = Optional.ofNullable((ClipboardService) o);%0A        button.addActionListener(e -%3E %7B%0A
     
@@ -805,35 +805,30 @@
             
- 
 try %7B%0A
-    
             
@@ -852,49 +852,93 @@
 t = 
-Objects.nonNull(cs) ? cs.getContents() : 
+csOp.map(ClipboardService::getContents)%0A                                     .orElse(
 Tool
@@ -995,24 +995,25 @@
 ntents(null)
+)
 ;%0A          
@@ -1014,28 +1014,24 @@
             
-    
 if (Objects.
@@ -1039,28 +1039,24 @@
 sNull(t)) %7B%0A
-    
             
@@ -1123,20 +1123,16 @@
     
-    
 return;%0A
     
@@ -1127,20 +1127,16 @@
 return;%0A
-    
         
@@ -1161,20 +1161,16 @@
         
-    
 String s
@@ -1178,20 +1178,16 @@
 r = %22%22;%0A
-    
         
@@ -1230,28 +1230,24 @@
             
-    
 if (t.isData
@@ -1281,36 +1281,32 @@
 imageFlavor)) %7B%0A
-    
                 
@@ -1399,20 +1399,16 @@
         
-    
 %7D else i
@@ -1454,36 +1454,32 @@
 tringFlavor)) %7B%0A
-    
                 
@@ -1553,33 +1553,26 @@
             
-    %7D%0A   
+%7D%0A
             
@@ -1567,33 +1567,32 @@
                 
- 
 label.setText(st
@@ -1591,28 +1591,24 @@
 tText(str);%0A
-    
             
@@ -1641,28 +1641,24 @@
             
-   
- 
 %7D catch (Uns
@@ -1709,36 +1709,32 @@
                 
-    
 ex.printStackTra
@@ -1751,34 +1751,39 @@
         
+%7D%0A
     
-%7D%0A
     
+%7D);%0A%0A
         
 %7D%0A      
@@ -1774,28 +1774,63 @@
         
-%7D%0A        %7D)
+add(new JScrollPane(label));%0A        add(button
 , Border

use Optional.map().orElse() instead of if (Objects.nonNull(o)) {...}