                              (windowIconified [this e])
                              (windowOpened [this e])
                              (windowClosed [this e])))
-      (.setUndecorated decor?)
-      (.setDefaultCloseOperation close-op)
-      (.add applet)
-      (.pack))
+      (.setDefaultCloseOperation close-op))
+
+    (javax.swing.SwingUtilities/invokeLater
+     (fn []
+       (.setResizable f true)
+       (.setAlwaysOnTop f keep-on-top?)))
+
     (when (= renderer :opengl)
       (.setResizable f false))
-    (.show f)
-    (.setAlwaysOnTop f keep-on-top?)
     (reset! (:target-obj (meta applet)) f)
     applet))
+
 
 (defn- applet-run
   "Launches the applet to the specified target."
   [applet title renderer target]
+  (PApplet/runSketch (into-array String ["--hide-stop" title]) applet)
   (case target
-    :frame (launch-applet-frame applet title renderer false)
-    :perm-frame (launch-applet-frame applet title renderer true)
-    :none applet)
-  (.init applet))
+    :frame (prepare-applet-frame applet title renderer false)
+    :perm-frame (prepare-applet-frame applet title renderer true)
+    :none (prepare-applet-frame applet title renderer false)))
+
 
 (def ^{:private true}
   renderer-modes {:p2d    PApplet/P2D


   :on-close       - Called once, when sketch is closed"
  [& opts]
  (when (= :fullscreen (:size opts))
    (hide-menu-bar-if-macos))
  (let [options           (merge {:size [500 300]
                                  :target :frame
                                  :safe-draw-fn true}
                                 (apply hash-map opts))
        decor             (:decor opts (not= :fullscreen (:size options)))
        size              (process-size (:size options))
        target            (validate-target! (:target options))
        title             (or (:title options) (str "Quil " (swap! untitled-applet-id* inc)))

  ; (don't know why, but let's trust Processing guys).
  ; Technically it's not first (there are 'when' and 'let' before 'size'),
  ; but hopefully it will work fine.
  (let [[width height] (:size (meta this))
          renderer (resolve-renderer (:renderer (meta this)))
          file (-> this meta :output-file absolute-path)]
    (when (= (:renderer (meta this)) :pdf)
      (.size this (int width) (int height) renderer file)))
  (with-applet this
    ((:setup-fn (meta this)))))
