From 12eb70645d7e06cd3b40e759c37b3da338d72929 Mon Sep 17 00:00:00 2001 From: benfry Date: Sun, 29 Jul 2001 18:30:08 +0000 Subject: [PATCH] making processingapplet run smoothly, properly destroy old ones (though no gc), proper file cleanup --- processing/app/PdeApplication.java | 17 ++++++++++---- processing/app/PdeRunner.java | 2 +- processing/app/ProcessingApplet.java | 34 ++++++++++++++++++++++++---- 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/processing/app/PdeApplication.java b/processing/app/PdeApplication.java index 89a703652..5baf4d574 100644 --- a/processing/app/PdeApplication.java +++ b/processing/app/PdeApplication.java @@ -52,15 +52,24 @@ implements ActionListener e.printStackTrace(); System.exit(1); } - int width = getInteger("width", 600); - int height = getInteger("height", 350); + int width = getInteger("window.width", 600); + int height = getInteger("window.height", 350); // ms jdk requires that BorderLayout is set explicitly frame.setLayout(new BorderLayout()); frame.add("Center", this); init(); Insets insets = frame.getInsets(); - frame.reshape(50, 50, width + insets.left + insets.right, - height + insets.top + insets.bottom); + + Toolkit tk = Toolkit.getDefaultToolkit(); + Dimension screen = tk.getScreenSize(); + int frameX = getInteger("window.x", (screen.width - width) / 2); + int frameY = getInteger("window.y", (screen.height - height) / 2); + + frame.setBounds(frameX, frameY, + width + insets.left + insets.right, + height + insets.top + insets.bottom); + //frame.reshape(50, 50, width + insets.left + insets.right, + // height + insets.top + insets.bottom); // i don't like this being here, but.. //((PdeEditor)environment).graphics.frame = frame; diff --git a/processing/app/PdeRunner.java b/processing/app/PdeRunner.java index 0196fc13e..8d658ba33 100644 --- a/processing/app/PdeRunner.java +++ b/processing/app/PdeRunner.java @@ -112,7 +112,7 @@ public class PdeRunner implements Runnable { forceStop = false; */ - engine = new KjcEngine(program); + engine = new KjcEngine(program, env); engine.start(); } //System.out.println("finished"); diff --git a/processing/app/ProcessingApplet.java b/processing/app/ProcessingApplet.java index fe216f5a2..a9da5a669 100644 --- a/processing/app/ProcessingApplet.java +++ b/processing/app/ProcessingApplet.java @@ -57,6 +57,22 @@ public class ProcessingApplet extends Applet } + public void start() { + thread = new Thread(this); + thread.start(); + } + + + // maybe start should also be used as the method for kicking + // the thread on, instead of doing it inside paint() + public void stop() { + if (thread != null) { + thread.stop(); + thread = null; + } + } + + // ------------------------------------------------------------ @@ -79,7 +95,8 @@ public class ProcessingApplet extends Applet // this is where screen grab could attach itself public void update() { - paint(this.getGraphics()); + Graphics g = this.getGraphics(); + if (g != null) paint(g); } public void update(Graphics screen) { @@ -87,14 +104,23 @@ public class ProcessingApplet extends Applet } public void paint(Graphics screen) { - if (thread == null) { + /* + if ((thread == null) && !finished) { // kickstart my heart thread = new Thread(this); thread.start(); } else { + if (screen == null) System.out.println("screen is null"); + if (g == null) System.out.println("g is null"); screen.drawImage(g.image, 0, 0, null); } + */ + if (screen == null) + System.out.println("ProcessinApplet.paint screen is null"); + if (g == null) + System.out.println("ProcessinApplet.paint g is null"); + screen.drawImage(g.image, 0, 0, null); } @@ -355,7 +381,7 @@ public class ProcessingApplet extends Applet g.rect(x1, y1, x2, y2); } - public void cube(float size) { // radius*2 + public void cube(float size) { g.cube(size); } @@ -368,7 +394,7 @@ public class ProcessingApplet extends Applet g.sphere(radius); } - public void potato() { // my teapot equivalent + public void potato() { g.potato(); }