mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
making processingapplet run smoothly, properly destroy old ones (though no gc), proper file cleanup
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user