We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › java 2 processing
Page Index Toggle Pages: 1
java 2 processing (Read 530 times)
java 2 processing
Sep 5th, 2008, 3:03pm
 
Hello,
I have got already a simulation written in java that use swing. If you click init button that appears a ball, then you can click the start button and the simulation will start. During the simulation you can click pause button and the simulation will make a pause. Additionally you can make a screenshot.

You can find the code here:
http://mitlox.republika.pl/pde/Moving.java
http://mitlox.republika.pl/pde/PaintSurface.java

I didn't see a run() methode in processing. What I need to rewrite this code to processing?

Best regards
Re: java 2 processing
Reply #1 - Sep 5th, 2008, 5:23pm
 
There is the mousePressed() event, which you can test against a region of the sketch area.
And you can use noLoop() to stop animation.
I added the following lines to the BouncyBubbles demo sketch:

boolean bMoving = true;

void mousePressed()
{
 if (bMoving) noLoop();
 else loop();
 bMoving = !bMoving;
}

and it did the trick (pause/start).
Re: java 2 processing
Reply #2 - Sep 6th, 2008, 3:16am
 
Thank you. Your solution looks simpler than in java.

How can I keep Swing buttons (with PhiLho solution) and exist something similar to BufferedImage so if I click on screenshot button I get a PNG picture of the simulation?

Re: java 2 processing
Reply #3 - Sep 6th, 2008, 9:42am
 
As I wrote, in Processing, the simplest method is to just draw a button and test the mousePressed() event against the region of the drawn button. I am not sure, but I think Swing and Processing doesn't mix well. That's probably why you have also a number of GUI libraries, which probably just draw controls and manage events on them. Although I think at least one of them use AWT or something like that (that Spring GUI, I checked some time ago because I want a text field accepting Windows paste operation, and I am not sure the other libraries accept it).

And to take a screenshot, it is very simple: you have the saveFrame() function!

BTW, that's the aim of Processing: being simpler than Java! While remaining powerful. And you can still tap on Java libraries whenever you need them.
Page Index Toggle Pages: 1