# Resize window and object in class

**URL:** <https://discourse.processing.org/t/resize-window-and-object-in-class/22448>\
**Category:** Coding Questions\
**Created:** [July 7, 2020, 12:59pm UTC](https://discourse.processing.org/t/resize-window-and-object-in-class/22448 "2020-07-07T12:59:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![MiguelSanches](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/miguelsanches/32/11172_2.png) [@MiguelSanches](https://discourse.processing.org/u/MiguelSanches)\
**Post date:** [July 7, 2020, 12:59pm UTC](https://discourse.processing.org/t/resize-window-and-object-in-class/22448/1 "2020-07-07T12:59:41Z")

</div>

Hi all,

I am trying to do a small GUI and I was playing with resize.  
So, the following sketch display’s two circles as if they were two LEDs. I start the sketch with a small window, but if I change the window size to fullScreen the LED’s position are not resized.  
I understand that the constructor input’s the initial location for each LED but how can resize an object inside a class?  
Do I need to detect a change in the window size and set new positions? or is there an easier way to do this?

Thanks in advance

```auto

errorLED Temperature_LED;
errorLED EEPROM_LED;

PFont LED_font;

void setup() {
  size(600, 600);
  surface.setResizable(true);
  
  
  Temperature_LED = new errorLED("Temperature",width/8, height/6);
  EEPROM_LED = new errorLED("FFS",3*width/8,height/6);
  LED_font = createFont("Calibri",18);
}

void draw() {
  background(204);
  Temperature_LED.display();
 
  EEPROM_LED.display();
  stroke(0);
  line(0, 0, width, height);
  line(width, 0, 0, height); 
}

class errorLED {
  String name;
  color colorG, colorY, colorR, actualColor;
  float c_x, c_y, diameter;
  String errorMessage;

  errorLED(String _errorName, float xpos, float ypos) {
    this.name = _errorName;
    this.colorG = color(112, 173, 71);
    this.colorY = color(255, 192, 0);
    this.colorR = color(255, 0, 0);
    this.actualColor = color(100);
    this.c_x = xpos;
    this.c_y = ypos;
    this.diameter = 20;
    this.errorMessage = "";
  }

  void display() {
    noStroke();
    ellipseMode(CENTER);
    fill(actualColor);
    circle(c_x, c_y, diameter);
    fill(0);
    textFont(LED_font);
    textAlign(CENTER,CENTER);
    text(name,c_x,c_y - diameter - 10);
    textAlign(LEFT, CENTER);
    text(errorMessage,c_x + diameter + 15, c_y);
    noFill();
    
  }

  void setColor(String colorN) {
    switch (colorN) {
    case "R":
      this.actualColor = colorR;
      break;
    case "G":
      this.actualColor = colorG;
      break;
    case "Y":
      this.actualColor = colorY;
      break;
    }
  }
  
  void setError(String error){
   this.errorMessage = error; 
  }
}

```

---

<div class="post-metadata">

**Author:** ![SomeOne](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/someone/32/8639_2.png) [@SomeOne](https://discourse.processing.org/u/SomeOne)\
**Post date:** [July 7, 2020, 2:06pm UTC](https://discourse.processing.org/t/resize-window-and-object-in-class/22448/2 "2020-07-07T14:06:45Z")

</div>

> [@MiguelSanches](#):
>
> Do I need to detect a change in the window size and set new positions? or is there an easier way to do this?

You have to somehow take into account the change. It can be an if test or you use system variables width & height to always position element correctly

---

<div class="post-metadata">

**Author:** ![MiguelSanches](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/miguelsanches/32/11172_2.png) [@MiguelSanches](https://discourse.processing.org/u/MiguelSanches)\
**Post date:** [July 7, 2020, 2:19pm UTC](https://discourse.processing.org/t/resize-window-and-object-in-class/22448/3 "2020-07-07T14:19:35Z")

</div>

I was hoping that the fact the constructor uses width and height to initiate the object would account for those changes but I guess it passes the value not the “reference”.  
Thanks

---

<div class="post-metadata">

**Author:** ![SomeOne](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/someone/32/8639_2.png) [@SomeOne](https://discourse.processing.org/u/SomeOne)\
**Post date:** [July 7, 2020, 3:36pm UTC](https://discourse.processing.org/t/resize-window-and-object-in-class/22448/4 "2020-07-07T15:36:38Z")

</div>

Why would you want to use a local variable when you have access to a system variable? Well you could use the same class in another environment

---

<div class="post-metadata">

**Author:** ![MiguelSanches](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/miguelsanches/32/11172_2.png) [@MiguelSanches](https://discourse.processing.org/u/MiguelSanches)\
**Post date:** [July 8, 2020, 7:32am UTC](https://discourse.processing.org/t/resize-window-and-object-in-class/22448/5 "2020-07-08T07:32:38Z")

</div>

Because I don’t want to duplicate code. Creating the object class allows be to place multiple LED objects by passing its initial position in the constructor.  
But I will change things.  
Thanks
