public void updateImage(URL url) throws IOException { image.setImage(ImageIO.read(url)); }
DragDropFrame(URL background, URL dragTarget) throws IOException { final PCanvas canvas = new PCanvas(); image = new PImage(); BufferedImage backgroundImage = ImageIO.read(background); PImage backgroundNode = new PImage(); backgroundNode.setImage(backgroundImage); // backgroundNode.setPickable(false); // canvas.get BufferedImage dragTargetImage = ImageIO.read(dragTarget); PImage dragTargetNode = new PImage(); dragTargetNode.setPickable(true); dragTargetNode.setOffset(10, 10); dragTargetNode.setImage(dragTargetImage); canvas.getLayer().addChild(backgroundNode); canvas.getLayer().addChild(dragTargetNode); add(canvas); dragTargetNode.addInputEventListener( new PDragEventHandler() { @Override protected void startDrag(PInputEvent event) { // System.out.println("Start dragging"); } }); dragTargetNode.addInputEventListener( new PBasicInputEventHandler() { @Override public void keyTyped(PInputEvent event) { super.keyTyped(event); System.out.println("Key typed: " + event.getKeyChar()); } @Override public void keyPressed(PInputEvent event) { super.keyPressed(event); System.out.println("Key pressed: " + event.getKeyChar()); } @Override public void mousePressed(PInputEvent event) { super.mousePressed(event); System.out.println("Mouse pressed: button " + event.getButton()); } @Override public void mouseReleased(PInputEvent event) { super.mouseReleased(event); System.out.println("Mouse released: button " + event.getButton()); } }); // setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(backgroundImage.getWidth(), backgroundImage.getHeight() + 25); setVisible(true); }