Processing Forum
void setup() { noLoop(); final Outer a = new Outer(); final Outer.Inner aa = a.new Inner(); println(aa); //aa.start(); // can't invoke Thread's start() from Outer.Inner println(aa); exit(); } class Outer extends Thread { class Inner extends PVector { { x = getId(); // Thread's method y = getPriority(); // Thread's method z = 4*atan(1); // PApplet's method } void run() { sub(20, 10, -5); // PVector's method } } }
import acm.program.*; import java.awt.event.*; import javax.swing.*; public class ACMButton extends ConsoleProgram { public void init() { setFont("Courier-24"); add(new JButton("Hi"), SOUTH); addActionListeners(); } public void actionPerformed(ActionEvent e) { final String cmd = e.getActionCommand(); if (cmd.equals("Hi")) println("Hello there!"); } }
/** * Traffic Light (v3.0) * by Stephen o'Connor (2013/Jan) * * http://forum.processing.org/topic/traffic-light-functions-help */ PImage bg; void setup() { size(700, 550); smooth(); frameRate(50); rectMode(CORNER); imageMode(CORNER); background(0); bg = loadImage("background.png"); // Street background image image(bg, 0, 0, width, height); fill(50); // Colour of traffic light pole/hanger rect(200, 125, width-50, 40); // Position of traffic light pole/hanger rectMode(CENTER); ellipseMode(CENTER); fill(242, 201, 0); // Traffic light box colour rect(350, 225, 125, 275); // Position of traffic light box drawTrafficLight( 350, 140, 75, color(90, 25, 15) ); // Unlit red stop light drawTrafficLight( 350, 225, 75, color(40, 30, 10) ); // Unlit yellow stop light drawTrafficLight( 350, 310, 75, color(0, 0100, 0) ); // Unlit green stop light bg = get(); // Store reference to current canvas buffer } void draw() { background(bg); turnLightOn(); } void turnLightOn() { if (mouseX > 312 && mouseX < 388 && mouseY > 102 && mouseY < 178) drawTrafficLight( 350, 140, 75, color(240, 20, 10) ); // Lit red stop light else if (mouseX > 312 && mouseX < 388 && mouseY > 187 && mouseY < 263) drawTrafficLight( 350, 225, 75, color(225, 250, 5) ); // Lit green stop light else if (mouseX > 312 && mouseX < 388 && mouseY > 272 && mouseY < 348) drawTrafficLight( 350, 310, 75, color(55, 255, 20) ); // Lit blue stop light } void drawTrafficLight(int x, int y, int sz, color colour) { fill(colour); // Unlit stop light ellipse(x, y, sz, sz); // Position of stop light }