Fun with the frame object

From Processing

Jump to: navigation, search
Versions: 1.0+
Contributors: manic
Started: 2008-06-16


This is a really simple hack, you can use it to change your applets title, icon and make the frame resizable. It can be useful when making an openGL application or one with multiple tabs and you've found that your title has disappeared.

The PApplet object that everything is built on has an object within in called frame. This is a java.AWT.Frame object, and can used to customize your title bar, icon image and allow a resizeable frame.

Source Code

/**
fun-with-the-frame-object taken from http://wiki.processing.org/index.php/Fun_with_the_frame_object
@author Manic
*/
//the mouse X&Y controls the brightness and hue shift of the icon image
//you can resize the frame by dragging its corners
 
PGraphics icon;
 
void setup() {
  size(400,200);
  icon = createGraphics(16,16,JAVA2D);
 
  frame.setResizable(true);
}
 
void draw(){
  frame.setTitle("Frame Number "+str(frameCount));
  icon.beginDraw();
  //icon.background(102);
  icon.colorMode(HSB);
  for(int x=0;x<icon.width;x++){
    for(int y=0;y<icon.width;y++){
      icon.stroke((mouseX+(x*icon.width))%255,y*icon.height,constrain(mouseY,0,255));
      icon.point(x,y);
    }
  }
  icon.endDraw();
  frame.setIconImage(icon.image);
  ellipseMode(CORNERS);
  ellipse(0,0,width,height);
}

Downloads

Related Links

Personal tools