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 › "Are you sure" check
Page Index Toggle Pages: 1
"Are you sure?" check (Read 402 times)
"Are you sure?" check
Jun 17th, 2009, 1:48pm
 
Hi there, i have got a question about a project i am working on. For school i am making a stop motion machine with 3 functions:

1 Take picture & display union skin
2 Play image sequence
3 Reset the project and start new movie file

Option 3 is what my question is about.
I need to make a "are you sure" chek. When the user presses the button to reset the project i want a image to pop up with some tekst on it and give the user 2 options:  Yes and No. Example: mousebutton left = Yes / Mousebutton right = no.

Here is my code:
Quote:
// TINY STOP-FRAME PROGRAM
// Saves an image from the camera when a key/mouse is pressed.
// For Processing Version 1.01.

//----------------------------------------------------------
// Parameters you can modify:
int videoWidth  = 800; // could be 160, 320, 640, etc.
int videoHeight = 600; // could be 120, 240, 480, etc.
int onionSkinTransparency = 0; // between 0 and 255
int playbackSpeed = 125; // speed van tussentijdse playback
int takePicDelay = 2; //delay tussen scherm zwart maken en foto maken.

//----------------------------------------------------------
import  processing.video.*;
PImage  previousImage;
PImage  _sequenceImage;
Capture myCapture;
int     saveCount = 0;
int     saveCountBackup = 0;
int     takePictureDelay = takePicDelay;
SerialListener serialListener;

boolean bDoSave = false;
boolean bReady = false;
boolean playSequence = false;
boolean startNew = true;

//SOUND CODE----------------------------------------------------------
import ddf.minim.*;
Minim minim;
AudioSample foto;
AudioSample play;
AudioSample upload;
//VIDEO CODE----------------------------------------------------------
import processing.video.*;
MovieMaker mm;




//----------------------------------------------------------
void setup(){
 myCapture = new Capture(this, videoWidth,videoHeight);
 size(myCapture.width,myCapture.height);

 
 serialListener = new SerialListener(this, "COM4");
//SOUND CODE----------------------------------------------------------  
 minim = new Minim(this);
 foto = minim.loadSample("camera.wav", 2048);
 play = minim.loadSample("bloop.wav", 2048);
 upload = minim.loadSample("boing.wav", 2048);


 
 
// video code -----------------------------------------  
 // Or, set specific compression and frame rate options
 createM();
}

void createM(){
 
 previousImage = new PImage(myCapture.width,myCapture.height);
 mm = new MovieMaker(this, width, height, "/data/movies/stop_motion"+ day()+ hour()+ minute()+ second()+".mov", 2,
                     MovieMaker.ANIMATION, MovieMaker.BEST);                
}

//----INPUT ----------------------------------------

void mousePressed(){
 if (mouseButton == LEFT) {
   makeFoto();
 }
 if (mouseButton == CENTER) {
   startNew();
 }  
if (mouseButton == RIGHT) {
   playMovie();
 }
}

void makeFoto() {
   bDoSave = true;
   bReady = true;
   foto.trigger();
}

void startNew() {
   upload.trigger();
   saveCount = 0;
   createM();
   startNew =  true;
}

void playMovie() {
   play.trigger();
   playSequence = true;
}
//----------------------------------------------------------
void draw()
{
//SAVEIN-------------------------------------------------------
 
 // Add window's pixels to movie
 
 serialListener.serialRead();

 if(myCapture.available()) {
   background(0);
   delay(200);
   //myCapture.read();
//BLACKFRAME-------------------------------------------------------    
   if (bReady) {
     //draw black frame
     startNew = false;
     bReady = false;
     bDoSave = true;

   } else if (bDoSave) {
     if(takePictureDelay > 0) {
       drawBlack();
       takePictureDelay--;
     } else {
       if(takePicture()){
         takePictureDelay = takePicDelay;
         bDoSave = false;
       }
     }
   } else {
     if(!playSequence) {
       //draw previous image
       if(startNew) {
         drawBlack();
       } else {
         image(previousImage, 0,0);
         image(myCapture, 0,0);
       }    
     }
   }
   // playsequence
   if(playSequence) {
     if(saveCountBackup < saveCount) {
       _sequenceImage = loadImage("/data/fotos/stopframe_"+ nf(saveCountBackup, 5)+ ".jpg");
       image(_sequenceImage,0,0);
       delay(playbackSpeed);
       saveCountBackup++;
     }else {
       saveCountBackup = 0;
       playSequence = false;
     }
   }
 }


}


void drawBlack() {
 
  fill(0);
  rect(0,0,this.width,this.height);
         
}

boolean takePicture() {
     //capture image
     noTint();
     myCapture.read();
     image(myCapture, 0,0);
     String filename = "/data/fotos/stopframe_" + nf(saveCount++, 5) + ".jpg";
     saveFrame(filename);
     previousImage.loadPixels();
     arrayCopy (myCapture.pixels, previousImage.pixels);
     previousImage.updatePixels();
     mm.addFrame();
     return true;
}

//SOUND CODE----------------------------------------------------------
void stop()
{
 // always close Minim audio classes when you are done with them
 foto.close();
 minim.stop();
 serialListener.destroy();
 super.stop();
}



Thanks in advance. Im kind of in a hurry  Cheesy so if someone can help me, please do!
Re: "Are you sure?" check
Reply #1 - Jun 17th, 2009, 3:11pm
 
When you get to the point of deciding, you could use a JOptionPane.
http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html

You may want to call noLoop() before and loop() after using the dialog (just my experience).
Page Index Toggle Pages: 1