use --display=n command

edited July 2015 in How To...

I found the following here: https://github.com/processing/processing/blob/master/core/src/processing/core/PApplet.java

/** * main() method for running this class from the command line. *

<

p> * The options shown here are not yet finalized and will be * changing over the next several releases. *

* The simplest way to turn and applet into an application is to * add the following code to your program: *

static public void main(String args[]) {
       *   PApplet.main("YourSketchName", args);
       * }
* This will properly launch your applet from a double-clickable * .jar or from the command line. *
       * Parameters useful for launching or also used by the PDE:
       *
       * --location=x,y        upper-lefthand corner of where the applet
       *                       should appear on screen. if not used,
       *                       the default is to center on the main screen.
       *
       * --full-screen         put the applet into full screen "present" mode.
       *
       * --hide-stop           use to hide the stop button in situations where
       *                       you don't want to allow users to exit. also
       *                       see the FAQ on information for capturing the ESC
       *                       key when running in presentation mode.
       *
       * --stop-color=#xxxxxx  color of the 'stop' text used to quit an
       *                       sketch when it's in present mode.
       *
       * --bgcolor=#xxxxxx     background color of the window.
       *
       * --sketch-path         location of where to save files from functions
       *                       like saveStrings() or saveFrame(). defaults to
       *                       the folder that the java application was
       *                       launched from, which means if this isn't set by
       *                       the pde, everything goes into the same folder
       *                       as processing.exe.
       *
       * --display=n           set what display should be used by this sketch.
       *                       displays are numbered starting from 0.
       *
       * Parameters used by Processing when running via the PDE
       *
       * --external            set when the applet is being used by the PDE
       *
       * --editor-location=x,y position of the upper-lefthand corner of the
       *                       editor window, for placement of applet window
       * 
*/

I want to use the --display=n command. I tried it with a 0 and a 1 but both give a result on the same window.

static final void main(String[] args) {
  final String sketch = Thread.currentThread()
    .getStackTrace()[1].getClassName();

  PApplet.main(sketch, append(args, "--display=0"));
}

Am i doing something wrong?

I know i can set the prefered window from preferences, but i have to get around that.

Tagged:

Answers

  • I did found this: http://wiki.processing.org/w/Command_Line

    However, i did 'install "processing-java"' and restarted processing but i can not type in the console. :S

  • The question is if those comments in the source code are still up to date.

    Maybe this works...

        public static void main(String args[]) {
            PApplet.main(new String[]{"--display=1", "SketchName"});
        }
    
  • edited April 2014

    @ammon -> I'm puzzled, why "SketchName" gotta be the last array entry?
    Why the format below w/ split "SketchName" & args doesn't work?

    final String[] deviceArg = {
      "--display=1", "1"
    };
    
    PApplet.main(sketch, concat(args, deviceArg));
    

    forum.processing.org/two/discussion/4121/make-2nd-papplet-window-fullscreen

  • Answer ✓

    No reason, I just copy-pasted the way I do it from my own application I am writing in the IntelliJ IDEA as another option that could be tried out...

  • edited April 2014

    PApplet.runSketch()'s parsing doesn't seem too smart iMO:
    1st time equals() fails w/ its parameter list while iterating over args[], it assumes that failed entry is the sketch's name!
    And break outta the while loop completely! Thus any further entries are ignored by the big if parser block @-)

    https://github.com/processing/processing/blob/master/core/src/processing/core/PApplet.java#L10581

    int argIndex = 0;
    
    while (argIndex < args.length) {
      int equals = args[argIndex].indexOf('=');
    
      if (equals != -1) {
        // ...
      }
    
      // ...
    
      else if (args[argIndex].equals(ARGS_EXTERNAL)) {
        external = true;
      }
    
      else {
        name = args[argIndex];
        break;
      }
    
      argIndex++;
    }
    

    Also, the "convenient" 2-parameter PApplet.main() version is highly deceptive!
    It concat() the sketch's name before passedArgs[], rendering the latter void for the parser ahead: :-w

    https://github.com/processing/processing/blob/master/core/src/processing/core/PApplet.java#L10455

    static public void
    main(final String mainClass, final String[] passedArgs) {
      String[] args = new String[] { 
        mainClass
      };
    
      if (passedArgs != null) {
        args = concat(args, passedArgs);
      }
    
      runSketch(args, null);
    }
    

    And that's the reason why I was tripping out! :-<

  • edited May 2014

    But in the end, thx for the provided extra info, I've redone "Cursor Keys" as the brand new "Parameterized PApplet Instances"!
    Now it dictates any desired parameters for each new PApplet instantiation! \m/

    /**
     * Parameterized PApplet Instances (v1.10)
     * by GoToLoop (2014/Feb)
     *
     * forum.processing.org/two/discussion/4121/
     * make-2nd-papplet-window-fullscreen
     *
     * forum.processing.org/two/discussion/4140/
     * use-displayn-command
     */
    
    static final int DIM = 56, CURVE = 8;
    static final color ON = #00FF00, OFF = 0;
    
    boolean north, south, east, west;
    int id;
    
    static final void main(String[] args) {
      final String sketch = Thread.currentThread()
        .getStackTrace()[1].getClassName();
    
      PApplet.main( concatArgs(sketch, "0", args, 
      "--location=200,400") );
    
      PApplet.main( concatArgs(sketch, "1", args, 
      "--full-screen", "--display=1") );
    
      PApplet.main( concatArgs(sketch, "2", args, 
      "--location=600,400") );
    }
    
    static final String[]
    concatArgs(String name, String idNum, 
    String[] oldArgs, String... newArgs)
    {
      return concat( concat(newArgs, oldArgs)
        , splitTokens(name + " " + idNum) );
    }
    
    void init() {
      id = int(args[args.length - 1]);
      super.init();
    }
    
    void setup() {
      size(
      id != 1? 400 : displayWidth, 
      id != 1? 400 : displayHeight, 
      JAVA2D);
    
      frameRate(30);
      noLoop();
      smooth(4);
    
      rectMode(CORNER);
      noStroke();
    
      background(id != 1? #0AF5E3 : #E3F50A);
      frame.setTitle(frame.getTitle() + " #" + id);
    
      println(args);
      println();
    }
    
    void draw() {
      fill(north? ON:OFF);
      rect(180, 120, DIM, DIM, CURVE);
    
      fill(south? ON:OFF);
      rect(180, 190, DIM, DIM, CURVE);
    
      fill(west? ON:OFF);
      rect(110, 190, DIM, DIM, CURVE);
    
      fill(east? ON:OFF);
      rect(250, 190, DIM, DIM, CURVE);
    }
    
    void keyPressed() {
      setDirection(keyCode, true);
      redraw();
    }
    
    void keyReleased() {
      setDirection(keyCode, false);
      redraw();
    }
    
    void setDirection(int k, boolean bool) {
      if      (k == UP    | k == 'W')   north = bool;
      else if (k == DOWN  | k == 'S')   south = bool;
      else if (k == LEFT  | k == 'A')   west  = bool;
      else if (k == RIGHT | k == 'D')   east  = bool;
    }
    
  • I moved to intelliJ, this works like a champ:

    import processing.core.*;
    
    
    public class MarkerMusic extends PApplet {
    
        int id;
    
        public static void main(String args[]) {
    
            final String sketch = Thread.currentThread()
                    .getStackTrace()[1].getClassName();
    
    
            PApplet.main(new String[]{"--display=1", "--present", "--hide-stop", "MarkerMusic", "0"});
            PApplet.main(new String[] { "--display=0", "MarkerMusic", "1" });
        }
    
        public void init() {
            id = parseInt(args[args.length - 1]);
            System.out.println(id);
            super.init();
        }
    
    
        public void setup() {
    
            System.out.println("setup for id:"+id);
    
            if (id == 0 ) size(displayWidth, displayHeight);
            if (id == 1) size(600, 400);
        }
    
        public void draw() {
            if (id == 0) {
                background(255, 0, 0);
            }
            if (id == 1) {
                background(0, 255, 0);
            }
        }
    }
    
  • edited April 2014

    Very nice indeed! :D Just a little redundancy note:

    Local variable sketch inside static main() was supposed to automatically get the class' name thx to that expression hack!
    If you're not using it, just remove that line or replace literal "MarkerMusic" by variable sketch! :(|)

    P.S.: I had no idea that conversion functions int() & float() had to be replaced as parseInt() & parseFloat() by the preprocessor!
    How dumb of me, since they're both keywords after all! b-(

    Processing's reference, of course, doesn't mention that at all.
    Neither that they can have 2 parameters by using their real method names! X(

    Ah! 1 more tip: We can still use the shorter println() even on other IDEs aFaIK! o->

  • I didn't notice i wasn't using sketch anymore. PApplet.println works.

  • hi there,

    i'm using

      public static void main(String args[]) {
          String sketch = Thread.currentThread()
          .getStackTrace()[1].getClassName();
          PApplet.main(new String[]{"--display=1", sketch});
       }
    

    in order to position applet window in the other display, but that somehow invalidates loading od images with loadImage(). it just doesn't find the image anymore.

    any ideas what am i doing wrong here?

  • What does this report?

    println(sketchPath());

Sign In or Register to comment.