1

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);
  }
}
Community
  • 1
  • 1
kukojus
  • 13
  • 2
  • An applet's size is set in the HTML. An applet should not try to 2nd guess what size the HTML has specified for it. Aslo: 1) Why code an applet? If it is due to the teacher specifying it, please refer them to [Why CS teachers should **stop** teaching Java applets](http://programmers.blogoverflow.com/2013/05/why-cs-teachers-should-stop-teaching-java-applets/). 2) See [Java Plugin support deprecated](http://www.gizmodo.com.au/2016/01/rest-in-hell-java-plug-in/) and [Moving to a Plugin-Free Web](https://blogs.oracle.com/java-platform-group/entry/moving_to_a_plugin_free). – Andrew Thompson Oct 14 '16 at 12:30

1 Answers1

0

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.

Kevin Workman
  • 41,537
  • 9
  • 68
  • 107