Refferancing applets

If I wanted to write code in one applet's "draw" to display an image in the other, what would I do?

In the situation below, if I move "image(example.get(0),0,0);" to draw and put "sa." or "SecondApplet." in front of it. I get an error that the name isn't recognizable or that I'm mixing static with non-static. How would I refer to the second applet in this case?

ArrayList<PImage> example = new ArrayList<PImage>();

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

  text.add(loadImage("example.png"));

  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(200, 100);
  }
  public void draw() {
    background(255);
    fill(0);
    ellipse(100, 50, 10, 10);
    //////////
    image(example.get(0),0,0);
    /////////
  }
}

Answers

  • edited December 2017

    @LaxOfBayDay===

    line 29 change it for: image(text.get(0),0,0):

  • Sorry that was a mistake. In my program the image is called "text" but in this small example replicating the problem I was trying to change the name to "example".

    Edited.

    The name's not the issue. I'm wondeing how I could move line 29 to line 16, and still have the image appear in SecondApplet.

  • You are there... Check this.

    Kf

    PImage example;
    
    void setup() {
      size(100, 100);
    
      example=createImage(width,height,RGB);
      example.loadPixels();
      for(int i=0;i<width*height;i++)
      example.pixels[i]=color(map(i%width,0,width,0,255));
      example.updatePixels();
    
      String[] args = {"TwoFrameTest"};
      SecondApplet sa = new SecondApplet();
      PApplet.runSketch(args, sa);
    }
    
    void draw() {
      background(0);
      ellipse(50, 50, 10, 10);
      image(example, 0, 0,25,25);
    }    
    
    public class SecondApplet extends PApplet {
    
      public void settings() {
        size(200, 100);
      }
      public void draw() {
        background(255);
        fill(0);
        ellipse(100, 50, 10, 10);
        //////////
        image(example, 0, 0,50,50);
        /////////
      }
    }
    
Sign In or Register to comment.