How to change the shape of your sketch's window?

I am working on creating my own themes for my projects but am unable to change the shape of the window. I would like to be able able to use the code from the you tube video in my project.

if it can not be done using the java.awt.geom.Ellipse2D library can someone point me to another to try.

this is what i have tried

import java.awt.MouseInfo;
import processing.opengl.*;
import java.awt.geom.Ellipse2D;

void setup() {
  size(400,400,OPENGL);
}

void draw() {
fill(80);
  strokeWeight(4);
  rect(0,0,width,height,12);
   smooth();
}


int mX;
int mY;

void mousePressed(){
  mX = mouseX;
  mY = mouseY;
}

void mouseDragged(){
 
  frame.setLocation(
  MouseInfo.getPointerInfo().getLocation().x-mX,
  MouseInfo.getPointerInfo().getLocation().y-mY);
}

public void init(){
  frame.removeNotify();
  frame.setUndecorated(true);
  frame.addNotify();
  super.init();


// this is the code that is supposed to change it shape 
setLayout(null);
  Shape= new Ellipse2D.Double(0,0,400,300);
  setShape(sp);
}

Answers

  • Look carefully at the code in the tutorial: the class he's using extends JFrame so it can make use of all methods available to JFrame. No such luxury inside a PApplet, we must call the JFrame methods of our frame field (which is a JFrame). Apart from that you were on the right track, except of course that to set the shape, addNotify() can't have been called yet.

    import java.awt.MouseInfo;
    import processing.opengl.*;
    import java.awt.Shape;
    import java.awt.geom.*;
    
    void setup() {
      size(400, 400, OPENGL);
      smooth();
      textAlign(CENTER);
    }
    
    void draw() {
      fill(80);
      strokeWeight(4);
      rect(0, 0, width, height, 12);
      fill(255);
      text("Hello I am an ellipse!", width*0.5, height*0.5);
    }
    
    
    int mX;
    int mY;
    
    void mousePressed() {
      mX = mouseX;
      mY = mouseY;
    }
    
    void mouseDragged() {
    
      frame.setLocation(
      MouseInfo.getPointerInfo().getLocation().x-mX, 
      MouseInfo.getPointerInfo().getLocation().y-mY);
    }
    
    public void init() {
      frame.removeNotify();
      frame.setUndecorated(true);
    
      frame.setLayout(null);
      Shape sp = new Ellipse2D.Double(0, 0, 400, 300);
      frame.setShape(sp);
      frame.addNotify();
      super.init();
    }
    
  • Thank you

Sign In or Register to comment.