Search code examples
javaappletprocessingwindow-resize

Resizing multiple applets in Processing


I'm using the code from this answer and I have an issue with changing the size of the first applet. Changing values of size(100, 100) does nothing.How can I fix this problem?

public void setup() {
  size(100, 100);

  String[] args = {"TwoFrameTest"};
  SecondApplet sa = new SecondApplet();
  PApplet.runSketch(args, sa);
}

void draw() {
  background(0);
  ellipse(50, 50, 10, 10);
}     

public class SecondApplet extends PApplet {

  public void settings() {
    size(500, 500);
  }
  public void draw() {
    background(255);
    fill(0);
    ellipse(100, 50, 10, 10);
  }
}

Solution

  • An easy fix is to just move the first size() into the settings() function:

    void settings() {  
      size(500, 100);
    }
    
    void setup() {
      String[] args = {"TwoFrameTest"};
      SecondApplet sa = new SecondApplet();
      PApplet.runSketch(args, sa);
    }
    
    void draw() {
      background(0);
      ellipse(50, 50, 10, 10);
    }     
    
    class SecondApplet extends PApplet {
    
      public void settings() {
        size(500, 500);
      }
      public void draw() {
        background(255);
        fill(0);
        ellipse(100, 50, 10, 10);
      }
    }
    

    I'm not exactly sure why this is happening. I would guess that it has something to do with the fact that you have to call size() from settings() when using eclipse. More info here.