Here's the code. It's a bit of a Java-y mess, but here it is:
Code:static Frame w;
Graphics grap;
void setup(){
size(320,240);
setupNew();
frameRate(5);
this.frame.setTitle("I'm the old window!");
}
void setupNew(){
w=new Frame("Hiya! I'm new!");
//see http://java.sun.com/docs/books/tutorial/post1.0/ui/mouselistener.html
//you could probably pass this all to the regular processing stuff with super.processMouseEvent( e );
MouseListener Win2MouseListner = new MouseListener() {
public void mouseEntered(MouseEvent e) {
}
public void mouseClicked(MouseEvent e){
println("Click! ");
}
public void mouseReleased(MouseEvent e){
}
public void mouseExited(MouseEvent e){
}
public void mousePressed(MouseEvent e){
}
};
//see http://java.sun.com/docs/books/tutorial/post1.0/ui/mousemotionlistener.html
MouseMotionListener Win2MouseMovementListner = new MouseMotionListener(){
public void mouseDragged(MouseEvent e) {
}
public void mouseMoved(MouseEvent e) {
println(e.getX()+","+e.getY());
}
};
w.addMouseListener(Win2MouseListner);
w.addMouseMotionListener(Win2MouseMovementListner);
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
w.setBounds(dim.width/2-160,dim.height/2-120,320,240);
w.show();
grap= w.getGraphics();
}
void draw()
{
background(0,random(255),0);
try {
PGraphics stuff;
stuff = createGraphics(320, 240, JAVA2D);
//draw your stuff here
stuff.beginDraw();
stuff.background(random(255),0,0);
stuff.stroke(255);
stuff.line(40, 40, 50,50);
stuff.endDraw();
BufferedImage img = PG2BI(stuff);
grap.drawImage(img, 0, 0, this);
}
catch(Exception e) {
e.printStackTrace();
}
}
BufferedImage PG2BI(PGraphics i) {
BufferedImage img=new BufferedImage(i.width, i.height, BufferedImage.TYPE_INT_RGB);
i.loadPixels();
img.setRGB(0, 0, i.width, i.height, i.pixels, 0, i.width);
return img;
}