Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

  • Cannot find anything Named "surface"

    public void start_click(GButton source, GEvent event) { //CODE:start:285860: //println("start - GButton >> GEvent." + event + " @ " + millis()); start.setVisible(false); startPlot = true; start.setLocalColorScheme(GCScheme.CYAN_SCHEME); record.setEnabled(true); done.setEnabled(true); label1.setVisible(true); label2.setVisible(true); record.setLocalColorScheme(GCScheme.GREEN_SCHEME); } //CODE:start:285860:

    public void portList_click(GDropList source, GEvent event) { //CODE:portList:554725: //println("portList - GDropList >> GEvent." + event + " @ " + millis()); selectedPort = portList.getSelectedText(); portSelected = true; portList.setEnabled(false); portList.setLocalColorScheme(GCScheme.CYAN_SCHEME);

    } //CODE:portList:554725:

    public void record_click(GButton source, GEvent event) { //CODE:record:865284: //println("record - GButton >> GEvent." + event + " @ " + millis()); //////////////////////////////////////////////////////////////////////////////// // // Enable the buttons and calls the serial port function // Comselect is made true to call the serial function //
    /////////////////////////////////////////////////////////////////////////////// try { jFileChooser = new JFileChooser(); jFileChooser.setSelectedFile(new File("log.txt")); jFileChooser.showSaveDialog(null); String filePath = jFileChooser.getSelectedFile()+"";

    if ((filePath.equals("log.txt"))||(filePath.equals("null")))
    {
    } else
    {    
      done.setVisible(true);
      record.setVisible(false);
    
      start.setEnabled(false);
      close.setEnabled(false);
      start.setLocalColorScheme(GCScheme.CYAN_SCHEME);
      close.setLocalColorScheme(GCScheme.CYAN_SCHEME);
    
      logging = true;
      date = new Date();
      output = new FileWriter(jFileChooser.getSelectedFile(), true);
      bufferedWriter = new BufferedWriter(output);
      bufferedWriter.newLine();
      bufferedWriter.write(date+"");
      bufferedWriter.newLine();
      bufferedWriter.newLine();
      bufferedWriter.flush();
      bufferedWriter.close();
    }
    

    } catch(Exception e) { println("File Not Found"); } } //CODE:record:865284:

    public void done_click(GButton source, GEvent event) { //CODE:done:510429: //println("done - GButton >> GEvent." + event + " @ " + millis()); //////////////////////////////////////////////////////////////////////////////// // // Save the file and displays a success message //
    /////////////////////////////////////////////////////////////////////////////// if (logging == true) { showMessageDialog(null, "Log File Saved successfully");

    record.setVisible(true);
    done.setVisible(false);
    
    close.setEnabled(true);
    close.setLocalColorScheme(GCScheme.GREEN_SCHEME);
    record.setEnabled(true);
    record.setLocalColorScheme(GCScheme.GREEN_SCHEME);
    done.setEnabled(true);
    done.setLocalColorScheme(GCScheme.GREEN_SCHEME);
    logging = false;
    

    } } //CODE:done:510429:

    public void close_click(GButton source, GEvent event) { //CODE:close:309405: //println("close - GButton >> GEvent." + event + " @ " + millis()); exit(); } //CODE:close:309405:

    public void imgButton1_click1(GImageButton source, GEvent event) { //CODE:imgButton1:430047: println("imgButton1 - GImageButton >> GEvent." + event + " @ " + millis()); } //CODE:imgButton1:430047:

    // Create all the GUI controls. // autogenerated do not edit public void createGUI(){ G4P.messagesEnabled(false); G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME); G4P.setCursor(ARROW); surface.setTitle("Sketch Window"); /////////error here start = new GButton(this, 260, 7, 100, 35); start.setText("START"); start.setTextBold(); start.setLocalColorScheme(GCScheme.GREEN_SCHEME); start.addEventHandler(this, "start_click"); portList = new GDropList(this, 5, 7, 200, 396, 10); portList.setItems(loadStrings("list_554725"), 0); portList.setLocalColorScheme(GCScheme.GREEN_SCHEME); portList.addEventHandler(this, "portList_click"); record = new GButton(this, 395, 7, 100, 35); record.setText("RECORD"); record.setTextBold(); record.setLocalColorScheme(GCScheme.GREEN_SCHEME); record.addEventHandler(this, "record_click"); done = new GButton(this, 395, 7, 100, 35); done.setText("DONE"); done.setTextBold(); done.setLocalColorScheme(GCScheme.GREEN_SCHEME); done.addEventHandler(this, "done_click"); close = new GButton(this, 527, 7, 100, 35); close.setText("CLOSE"); close.setTextBold(); close.setLocalColorScheme(GCScheme.GREEN_SCHEME); close.addEventHandler(this, "close_click"); imgButton1 = new GImageButton(this, 897, 564, 100, 30, new String[] { "logo.png", "logo.png", "logo.png" } ); imgButton1.addEventHandler(this, "imgButton1_click1"); bpm1 = new GLabel(this, 558, 75, 240, 95); bpm1.setTextAlign(GAlign.CENTER, GAlign.MIDDLE); bpm1.setOpaque(false); label1 = new GLabel(this, 460, 290, 80, 20); label1.setTextAlign(GAlign.CENTER, GAlign.MIDDLE); label1.setText("My label"); label1.setOpaque(false); label2 = new GLabel(this, 460, 290, 80, 20); label2.setTextAlign(GAlign.CENTER, GAlign.MIDDLE); label2.setText("My label"); label2.setOpaque(false); }

    // Variable declarations // autogenerated do not edit GButton start; GDropList portList; GButton record; GButton done; GButton close; GImageButton imgButton1; GLabel bpm1; GLabel label1; GLabel label2;

  • "Could not run the sketch (Target VM failed to initialize)."

    Hi All, I've been writing a program for projection mapping. I'm using PApplet.runSketch to run a program for each projector I have attached. Everything was working fantastically well for about a month, but just recently I started getting the error: "Could not run the sketch (Target VM failed to initialize)." Most of the changes I've made to the code recently are pretty simple little methods for scaling objects etc. I haven't fiddled much with how the Applets themselves are loaded etc.

    If it is relevant, the sketch uses the following libraries: import deadpixel.keystone.*; import java.util.*; import controlP5.*; import processing.video.*; import spout.*; import javax.swing.JFileChooser; import point2line.*;

    I would post the entire code, but it is really quite long.

    Interestingly, things work fine for a second; the error usually occurs around 45 seconds to 2 minutes into running the sketch, at which point it crashes and dumps the following information:

    _#

    A fatal error has been detected by the Java Runtime Environment:

    #

    EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007fff26083def, pid=12912, tid=0x000000000000341c

    #

    JRE version: Java(TM) SE Runtime Environment (8.0_102-b14) (build 1.8.0_102-b14)

    Java VM: Java HotSpot(TM) 64-Bit Server VM (25.102-b14 mixed mode windows-amd64 compressed oops)

    Problematic frame:

    C [msvcrt.dll+0x73def]

    #

    Failed to write core dump. Minidumps are not enabled by default on client versions of Windows

    #

    An error report file with more information is saved as:

    C:\Users\DREWHA~1\AppData\Local\Temp\hs_err_pid12912.log

    #

    If you would like to submit a bug report, please visit:

    http://bugreport.java.com/bugreport/crash.jsp

    The crash happened outside the Java Virtual Machine in native code.

    See problematic frame for where to report the bug.

    # Could not run the sketch (Target VM failed to initialize). For more information, read revisions.txt and Help ? Troubleshooting._

  • How should I contribute my code for selecting multiple files at once with JFileChooser?

    Hey Guys! I had to create a custom JFileChooser for a project of mine, and since it seems to be something that is commonly needed, I thought about contributing my code to the processing github repo, but I wouldn't know where to start. Would someone want to take my code (after i give it some polishing) and contribute it?

    import java.io.File;
    import javax.swing.JFileChooser;
    import javax.swing.filechooser.FileNameExtensionFilter;
    import java.lang.management.ManagementFactory;
    
    
    public class Importtool {
          
      public void choose() {
          JFileChooser chooser = new JFileChooser();
          File f = null;
          if(System.getProperty("os.name").equals("Linux")) {
              f = new File("/home");
          } else if(System.getProperty("os.name").equals("Mac")) {
              f = new File("/home");
          } else if(System.getProperty("os.name").equals("Windows")) {
              f = new File("Desktop");
          }
          
          FileNameExtensionFilter filter = new FileNameExtensionFilter(
                    "Images", "jpg", "gif");
          FileNameExtensionFilter filter2 = new FileNameExtensionFilter(
                    "Documents", "txt","text");
          FileNameExtensionFilter filter3 = new FileNameExtensionFilter(
                    "Video", "mp4","avi");
          FileNameExtensionFilter filter4 = new FileNameExtensionFilter(
                    "All supported filetypes", "txt","text","jpg","jpeg","tga","mp4");
                chooser.setFileFilter(filter);
                chooser.setFileFilter(filter2);
                chooser.setFileFilter(filter3);
                chooser.setFileFilter(filter4);
          chooser.setDragEnabled(false);
          chooser.setDialogTitle("Import Manager");
         
          chooser.setFileSelectionMode(2);//Files and directories
          chooser.setMultiSelectionEnabled(true);
          chooser.setCurrentDirectory(f);
          chooser.showOpenDialog(null);
          File[] files = chooser.getSelectedFiles();
          
          if(files.length > 0) {
              for(int m = 0; m < files.length; m++) {
                  System.out.println(files[m].getAbsolutePath());
              }//or getName
          } else {
              System.out.println(files[0].getAbsolutePath());
          }
          
          //chooser.getIcon(file f);
          //choser.getFileDescription(file f);
          //chooser.getCurrentDirector(file f);
          
          
      }
    }
    

    You can email me at smeck1999@gmail.com. I know the code is rather simple, so if no one wants to add something similar to the processing library its fine. I am hoping that it will atleast be useful to some new programmer having trouble figuring this out.

    Thanks! -Seth

  • Arduino com port

    Sorry again...hopefully this time it is more clear

    import java.awt.*;

    import java.awt.event.ActionEvent;

    import java.awt.event.ActionListener;

    import java.io.ByteArrayInputStream;

    import java.io.IOException;

    //import javax.jnlp.*;

    import processing.serial.*;

    import javax.swing.*;

    Serial myPort; // Create object from Serial class

    int val;

    // Global variable declaration

    // Size of the image

    int imgH=650;

    int imgW=700;

    int marge=10;

    //int loc;

    boolean go=false;

    //boolean clr=false;

    boolean load = false;

    boolean pen = false;

    boolean rubber = false;

    boolean mode = false;

    boolean connected = false;

    boolean firstconnect = true;

    color c =#000000;

    color fond=#FFFFFF;

    color scan=#FF0000;

    color scannedColor;

    color clear=#00FF00;

    int scanX,scanY,drillX, drillY;

    boolean OnTrack= false;

    boolean calib = false;

    //JFileChooser fc;

    PImage imgToLoad;

    PImage img;

    // The setup methid is executed once at the begining

    void setup()

    {

    //Drawing the GUI

    size(imgW+220, imgH+20);

    background(#053A67);

    buttons(); //dessine les boutons

    console(); //dessine la console

    state(); // This is updating the console display

    //loadPixels();

    for (int x = marge; x < imgW+marge; x++) {

    for (int y = marge; y < imgH+marge; y++) {

    set(x,y,fond);

    }

    }

    //initializing variables

    scanX=marge+5;

    scanY=marge+5;

    drillX=marge+5;

    drillY=marge+5;

    //updatePixels(); // MAJ pixels

    // String portName = Serial.list()[0];

    // println("nom du port: " + portName + ".\n");

    // myPort = new Serial(this, portName, 9600);

    //fc = new JFileChooser();

    }

    void draw() // The draw function is a endless loop in which the program runs

    {

    textSize(14);

    console();

    /*********** Image drilling process *********/

    if(go==true)

    {

    if (calib== false)

    {

    if(mode==true){

    javax.swing.JOptionPane.showMessageDialog(null,"Please initialize the drill manually \n and set the mode on AUTO.\n\n\n Ok to continue. ");

    calib= true; myPort.write('p'); waitAck();

    println("\nInitial lifting drill");}

    }

    if(scanX>marge+imgW-5) // si on arrive à la fin de la ligne

    {scanX=marge+5; scanY+=16;println("\nreturn carrier"); }

    scannedColor=get(scanX,scanY);

    if (scannedColor==#000000) followLine();

    else

    {

    if( scannedColor!=#00FF00)set(scanX,scanY,#FF0000);

    scanX++;

    }

    // print ("\nx= "+scanX+" y= "+scanY);

    if(scanY>marge+imgH-5)//Si on arrive en fin de dessin

    {

    go=false;

    println("End of drilling!");

    scanX=marge+5;

    scanY=marge+5;

    }

    // delay (5); // 5 ms de dlay entre chaque instructions

    }

    /************** "Pen & rubber tools" *************************/

    if (mousePressed == true && pen==true || mousePressed == true && rubber==true)

    {

    if (mouseX>marge&&mouseX<(imgW+marge) && mouseY>marge &&mouseY<(imgH+marge))

    {

    set(mouseX-1,mouseY-1,c);

    set(mouseX,mouseY-1,c);

    set(mouseX+1,mouseY-1,c);

    set(mouseX-1,mouseY,c);

    set(mouseX,mouseY,c);

    set(mouseX+1,mouseY,c);

    set(mouseX-1,mouseY+1,c);

    set(mouseX,mouseY+1,c);

    set(mouseX+1,mouseY+1,c);

    }

    }

    }

  • Objects sharing the same value

    I did fixed it already, haha! I did some research and accidentally found a solution (or actually something that led to a solution). One guy mentioned that an array that is made has an fixed memory location(seems logical). So when the values inside the array are changed, all the values from the array list will change aswell.

    So what you mention by putting fresh objects was exactly my problem :)!

    Right now my code looks like this and this works like a charm:

    if (mouseX>=405&&mouseX<=505&&mouseY>=370&&mouseY<=420&&mouseClicked) { mouseClicked=false; boolean readText=false; String data; if (loadFileChooser.showOpenDialog(null)==JFileChooser.APPROVE_OPTION) { myFrames.clear(); frameNumber=0; frameNumberMax=0; File file=loadFileChooser.getSelectedFile(); if (file.getName().endsWith(".txt")) { reader=createReader(file.getAbsolutePath()); readText=true;
    while (readText) { String[] tempString=new String[65]; byte[] tempBytes=new byte[64]; try { data=reader.readLine(); } catch (IOException e) { e.printStackTrace(); data=null; } if (data==null) { readText=false; } else { tempString=split(data, ","); for (int i=0; i<64; i++) tempBytes[i]=Byte.valueOf(tempString[i]); myFrames.add(new Frame(tempBytes, Integer.valueOf(tempString[64]))); frameNumber++; frameNumberMax++; } tempBytes=null; tempString=null; } resetMyFrame(); infoState=FILE_LOADED; infoStateTime=millis(); } else { infoState=FILE_LOAD_ERROR; infoStateTime=millis(); } } else { infoState=FILE_LOAD_ERROR_2; infoStateTime=millis(); } } if (mouseX>=405&&mouseX<=505&&mouseY>=370&&mouseY<=420) { if (mousePressed) fill(buttonPressedColor); else fill(buttonActiveColor); } else fill(buttonColor); rect(405, 370, 100, 50, 10);

  • Slow write to array

    Yes maybe I am overcomplicating things, but hey I already knew the jfilechooser so I used that. Didnt even know the selectfolder/selectinput functions. Same goes for my buttons, I made them all myself, I could use the controlp5 library. However that still doesn't matter to my problem haha :p. It is loading fine, however it doesnt process it right.... :(

  • Slow write to array

    What's wrong w/ Processing's own selectFolder() & selectInput() after all? Why choose JFileChooser over them? :-/
    I see that you're picking various Java's API features while Processing got lazy easier solutions already available! O:-)
    Sorry still got lot to learn from Java's API yet. But I think you're over-complicating things! 8-X

  • Objects sharing the same value

    Well, I am having another problem. A couple days ago I made an save to file and load to file function. This was working fine, however yesterday just out of nowhere my loading from file system was not working properly. So I started debugging the function and found out that everytime I add an element to my arraylist all the other elements will get the same value of the added element. I stripped down the code to bare metal and it still does the same thing over and over again, am I missing something?

    My code (without printing):

    if (mouseX>=405&&mouseX<=505&&mouseY>=370&&mouseY<=420&&mouseClicked ) {
        mouseClicked=false;
        String[] tempString=new String[65];
        byte[] tempBytes=new byte[64];
        boolean readText=false;
        String data;
        if (loadFileChooser.showOpenDialog(null)==JFileChooser.APPROVE_OPTION) {
          myFrames.clear();
          frameNumber=0;
          frameNumberMax=0;
          File file=loadFileChooser.getSelectedFile(); 
          if (file.getName().endsWith(".txt")) {
            reader=createReader(file.getAbsolutePath());
            readText=true;  
            while (readText) {
              try {
                data=reader.readLine();
              } 
              catch (IOException e) {
                //e.printStackTrace();
                data=null;
              }
              if (data==null) {
                readText=false;
              } 
              else {
                tempString=split(data, ",");
                for (int i=0;i<64;i++) {
                  tempBytes[i]=Byte.valueOf(tempString[i]);
                }
                myFrames.add(new Frame(tempBytes, Integer.valueOf(tempString[64])));
                frameNumber++;
                frameNumberMax++;
              }
            }
          }
        }
      }
      if (mouseX>=405&&mouseX<=505&&mouseY>=370&&mouseY<=420) {
        if (mousePressed)
          fill(buttonPressedColor);
        else
          fill(buttonActiveColor);
      }
      else
        fill(buttonColor);
      rect(405, 370, 100, 50, 10);
    

    Here I added some printing to my code for debugging:

    if (mouseX>=405&&mouseX<=505&&mouseY>=370&&mouseY<=420&&mouseClicked ) {
        mouseClicked=false;
        String[] tempString=new String[65];
        byte[] tempBytes=new byte[64];
        byte[] test = new byte[64];
        boolean readText=false;
        String data;
        if (loadFileChooser.showOpenDialog(null)==JFileChooser.APPROVE_OPTION) {
          myFrames.clear();
          frameNumber=0;
          frameNumberMax=0;
          File file=loadFileChooser.getSelectedFile(); 
          if (file.getName().endsWith(".txt")) {
            reader=createReader(file.getAbsolutePath());
            readText=true;  
            while (readText) {
              try {
                data=reader.readLine();
                println("--------------------");
                print("R:");
                println(data);
              } 
              catch (IOException e) {
                //e.printStackTrace();
                data=null;
              }
              if (data==null) {
                readText=false;
              } 
              else {
                tempString=split(data, ",");
                print("S:");
                for (int i=0;i<64;i++) {
                  tempBytes[i]=Byte.valueOf(tempString[i]);
                  print(tempString[i]);
                  print(" ");
                }
                println("");
                print("B:");
                for (int i=0;i<64;i++) {
                  print(tempBytes[i]);
                  print(" ");
                }
                myFrames.add(new Frame(tempBytes, Integer.valueOf(tempString[64])));
                test=myFrames.get(frameNumber).getState();
                println("");
                print("A:");
                for (int i=0;i<64;i++) {
                  print(test[i]);
                  print(" ");
                }
                frameNumber++;
                frameNumberMax++;
                println("");
                println("--------------------");
              }
            }
            for (int j=0;j<frameNumberMax;j++) {
              test=myFrames.get(j).getState();
              println("");
              print("A"+j+":");
              for (int i=0;i<64;i++) {
                print(test[i]);
                print(" ");
              }
            }
          }
        }
      }
      if (mouseX>=405&&mouseX<=505&&mouseY>=370&&mouseY<=420) {
        if (mousePressed)
          fill(buttonPressedColor);
        else
          fill(buttonActiveColor);
      }
      else
        fill(buttonColor);
      rect(405, 370, 100, 50, 10);
    

    And here is the output file: https://www.dropbox.com/s/ma7pws2l6f1ouqk/println output.txt click on download --> direct download. Its cropped when viewing the file from the link itself.

    Meaning of the letters: R = Read data from readLine S = Read data from tempString (values of R are split and written to tempString) B = Read data from tempBytes (values of tempString are converted to bytes and written to tempByte) A = Read data from the last added element of the arraylist A0 to A26 = Read data from all the elements of the arraylist

    Note: Ignore the last number at R, this is the value of the delay time.

    Here is my frame class: class Frame { byte[] state = new byte[64]; int frameTime;

      Frame(byte[] inState, int inFrameTime) {
        state = inState;
        frameTime = inFrameTime;
      }
    
      byte[] getState() {
        return state;
      }
    
      int getFrameTime() {
        return frameTime;
      }
    }
    

    As I said this code did work before and I didn't change a thing to it. I commented out all the other code in my program but still this problem occurs. I really can't seem to figure it out why it isn't working. It probably is very easy to fix, but I cannot find it. Please help me :D hahaha

  • selectInput and using wildcards

    Yes, I more or less would like to show gifs only and hoped for a processing way, since I still know close to nothing about Java. The Arduino IDE uses Java as well, but you hardly need to know it to write a sketch for the microcontroller-board.

    When searching for animated gifs I probably will save them to my standard download folder, which often is filled with tons of different filetypes. Using a filefilter while selecting and sorting on date would give me easy access.

    I have been reading on this Forum for a few days though, notice... quite a lot is done with Java and I'll probably just need to step in.

    Thank you for the links, I'll check whether I can easily use JFileChooser and the File class or... have to start with an "Hello World" java-application first. If it's not to difficult for me to integrate I'll use it, otherwise I'll stick with selectinput() for now, work on a more easy user interface as changing variables in my sketch and look into Java after that.

  • selectInput and using wildcards

    Are you just asking how to restrict the types of file that can be selected from the selectInput() dialog?

    I don't know of a way to do that in pure Processing, but you can do it using Java's JFileChooser class. More info here: http://docs.oracle.com/javase/tutorial/uiswing/components/filechooser.html

    If you're asking how to automatically scan the file system or a particular directory for .gif files, the Java File class can help with that: http://docs.oracle.com/javase/7/docs/api/java/io/File.html

  • Image Selector

    you can also just do it like this

    import javax.swing.*; 
    PImage selected;
    
    void setup() {
      size(444, 333);
      if (selected==null)
        chooser() ;
    }
    
    void draw() {
      //
    }
    
    void chooser() {
      JFileChooser chooser = new JFileChooser();
    
      int returnVal = chooser.showOpenDialog(this); 
    
      if (returnVal == JFileChooser.APPROVE_OPTION) {
    
        File file = chooser.getSelectedFile();
        // println (file);
        String myInputFile = file.getAbsolutePath();
    
        if (fileIsOK(myInputFile))
          selected = loadImage(myInputFile);
        else 
          println ("not ok");
    
        if (selected!=null)
          image(selected, 2, 2);
      }
      else {
        println("Cancelled.");
      }
    }
    // 
    //
    boolean fileIsOK (String name) {
      // Image ? 
      //
      if (name==null) { 
        return false; // not ok
      }
      // name=trim(name);
      if (name.equals("")) return false;  
      if (name.substring (  name.length()-4 ).equals (".jpg")  ) return true; 
      if (name.substring (  name.length()-4 ).equals (".png")  ) return true; 
      if (name.substring (  name.length()-4 ).equals (".JPG")  ) return true;
      if (name.substring (  name.length()-4 ).equals (".PNG")  ) return true;
      if (name.substring (  name.length()-4 ).equals (".bmp")  ) return true;
      if (name.substring (  name.length()-4 ).equals (".BMP")  ) return true;
      if (name.substring (  name.length()-4 ).equals (".gif")  ) return true;
      if (name.substring (  name.length()-4 ).equals (".GIF")  ) return true;
      // 
      // when no extension matched:   
      return false; // not ok
    } // func 
    //
    
  • Image Selector

    you can use processing's own command

    http://www.processing.org/reference/selectInput_.html

    //void chooser() {
    // JFileChooser chooser = new JFileChooser();
    // selected = loadImage("chooser.showOpenDialog(aComponent)");
    // image(selected, width/2,height/2);
    //}
    //
    //
    
    PImage selected; 
    
    void setup() {
      size (600, 600);
      selectInput("Select an image to process:", "fileSelected");
    }
    
    void draw() {
      if (selected!=null)
        image(selected, 2, 2);
    }
    
    void fileSelected(File selection) {
      if (selection == null) {
        println("Window was closed or the user hit cancel.");
      } 
      else {
        println("User selected " + selection.getAbsolutePath());
        selected = loadImage(selection.getAbsolutePath());
      }
    }
    
  • Image Selector

    Hi Im trying to make an image selector, which can select images from any destination on the computer. Im trying to use the JFileCHooser.

    void chooser() {
     JFileChooser chooser = new JFileChooser();
     selected = loadImage("chooser.showOpenDialog(aComponent)");
     image(selected, width/2,height/2);
    }
    

    This is what I tried so far, but it won't work :/ any ideas?

  • How to make file choose dialog for different images before execute the code

    At line 24 the value of myInputFile is null because you do not select a file until line 31 so there is nothing to play - try changing setup to

    void setup()
    {
      size(400, 400);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        myInputFile = file.getAbsolutePath();
      }
      else {
        println("Cancelled.");
      }  
      myPort = new Serial(this, Serial.list()[5], 9600);
      myPort.bufferUntil('\n'); // Trigger a SerialEvent on new line
      distance = 0;
      minim = new Minim(this);
      distance = constrain(distance, 1 , 100);
      player = minim.loadFile(myInputFile, 2048);
      player.play();
      player.loop();
      player.unmute();
    }
    
  • How to make file choose dialog for different images before execute the code

    Hello. If I have few files different and I have the program that does something with them(like here playing the files), I want to let the user to change the file at the beginning from a dialog box. How can I do that? After the selection start the processing application. This is the example but it is not working changing the file.

    import processing.serial.*;
    import ddf.minim.*;
    import javax.swing.*; 
    
    String myInputFile ;
    Serial myPort;
    String comPortString;
    AudioPlayer player;
    Minim minim;
    int volume = 0;
    int distance;     
    
    final JFileChooser fc = new JFileChooser(); 
    int returnVal = fc.showOpenDialog(this); 
    
    void setup()
    {
      size(400, 400);
      myPort = new Serial(this, Serial.list()[5], 9600);
      myPort.bufferUntil('\n'); // Trigger a SerialEvent on new line
      distance = 0;
      minim = new Minim(this);
      distance = constrain(distance, 1 , 100);
      player = minim.loadFile(myInputFile, 2048);
      player.play();
      player.loop();
      player.unmute();
    
        if (returnVal == JFileChooser.APPROVE_OPTION) { 
     File file = fc.getSelectedFile(); 
        myInputFile = file.getAbsolutePath();
      } 
      else { 
        println("Cancelled.");
      }
    }
    
    void draw()
    {
      ellipse(mouseX, mouseY, 9, 9);
      println("Selected at this point " + myInputFile);
      background(distance);
      delay(200);
    
    }
    
    void stop()
    {
      player.close();
      minim.stop();
      super.stop();
    }
    
  • selectInput(); in a class in Eclipse, callback not found

    Thank you so much for the explanation! Clears things up a bit :) What I can conclude from it is that there are two options:

    1. What Phil.ho said (thanks!) - stating it should happen in this class.
    2. Calling the callback function like Mesh.fileSelected() (or mesh.fileSelected() - not sure), - which also states it should happen in this class.

    However, both still give 'fileSelected() could not be found'.

    I started looking for an alternative in java, to avoid all the complicated processing references, and solved it like this:

    public class Mesh {
          PApplet parent; 
    
          Mesh(PApplet p) {
                parent = p;
              }
    
          void open() {
             final JFileChooser fc = new JFileChooser();
             int returnVal = fc.showOpenDialog(parent);
    
             if (returnVal == JFileChooser.APPROVE_OPTION) {
                  File file = fc.getSelectedFile();
                  String path = file.getAbsolutePath();
                  IG.open(path);
              } else {
                  System.out.println("No file was selected; start again.");
              }
          }
    

    Which works, yay! Although.. almost. It gives one problem, which is that it opens the dialog twice, even if a file was selected the first time. If I press cancel the second time, it works alright though.

    Any thoughts?

  • selectInput(); in a class in Eclipse, callback not found

    Hi masterminds,

    I started using Processing in Eclipse, and I'm trying to load a file using the selectInput() function. This function should automatically bring the selected file to a callback function (named fileSelected() ), where it is processed further. See reference: http://www.processing.org/reference/selectInput_.html

    In my code however, it says fileSelected() cannot be found.

    I'm combining it with a function from a library called iGeo, but I tried it without that too, so that is not the problem.

    This is my code in the main class:

        public void setup() {
            size(displayWidth-50, displayHeight-150, IG.GL );
            IG.bg(0);
            IG.perspective();
            IG.focus();
    
            Mesh mesh = new Mesh(this);
            mesh.open();
              }
    

    And this is the mesh class:

    import java.io.File;
    import javax.swing.JFileChooser;
    import processing.core.PApplet;
    import igeo.*;
    
    public class Mesh {
    
      PApplet parent; 
    
      Mesh(PApplet p) {
            parent = p;
          }
    
      void open() {
          parent.selectInput("Select a mesh to process:", "fileSelected");
          }
    
    
      void fileSelected(File selection) {
          if (selection == null) {
            System.out.println("Window was closed or the user hit cancel.");
          } else {
              System.out.println("User selected " + selection.getAbsolutePath());
              String path = selection.getAbsolutePath();
              IG.open(path);
          }
              }
    }
    

    I hope someone can help out!

  • Multiselecting files to import?

    AFAIK, it is not possible with selectInput(), only with the native Java library (JFileChooser) that is used behind it...