//EJEMPLO DE RECORTE import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import java.awt.image.*; public class Clipper extends Frame { static final int numShapes = 5; Shape shapes[] = new Shape[numShapes]; static final int width = 600; static final int height = 400; MyMenuBar menuBar; EventHandler eh = new EventHandler(); public static void main(String args[]){ Clipper app = new Clipper(); } public Clipper() { super("Clipper"); setupMenuBar(); add("Center",new MyCanvas()); createShapes(); setSize(width,height); addWindowListener(eh); show(); } void createShapes() { for(int i=0;i<shapes.length;++i) shapes[i] = null; shapes[0] = new Line2D.Double(0.0,0.0,100.0,100.0); shapes[1] = new Rectangle2D.Double(100.0,100.0,200.0,200.0); shapes[2] = new Ellipse2D.Double(200.0,200.0,100.0,100.0); GeneralPath path = new GeneralPath(new Line2D.Double(300.0,100.0,400.0,150.0)); path.append(new Line2D.Double(400.0,150.0,350.0,200.0),true); path.append(new Line2D.Double(350.0,200.0,325.0,175.0),true); path.append(new Line2D.Double(325.0,175.0,300.0,100.0),true); shapes[3] = path; shapes[4] = new RoundRectangle2D.Double(350.0,250,200.0,100.0,50.0,25.0); } void setupMenuBar(){ Object menuItems[][] = {{"File","Exit"}}; menuBar = new MyMenuBar(menuItems,eh,eh); setMenuBar(menuBar); } class MyCanvas extends Canvas { public void paint(Graphics graphics) { Graphics2D g = (Graphics2D) graphics; g.setClip(new Rectangle2D.Double(75.0,75.0,300.0,250.0)); float[] dashPattern = {10.0f,10.0f,5.0f,5.0f}; g.setStroke(new BasicStroke(5, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 10.0f, dashPattern, 0.0f)); g.draw(shapes[0]); g.setPaint(Color.blue); g.draw(shapes[1]); g.fill(shapes[1]); g.setPaint(new GradientPaint(350.0f,200.0f,Color.red, 325.0f,175.0f,Color.green)); g.draw(shapes[2]); g.fill(shapes[2]); g.setColor(Color.black); g.draw(shapes[3]); TexturePaint texture = new TexturePaint( createBufferedImage(), new Rectangle2D.Double(350.0,250,200.0,100.0)); g.setPaint(texture); g.draw(shapes[4]); g.fill(shapes[4]); } BufferedImage createBufferedImage() { BufferedImage image = new BufferedImage(20,20,BufferedImage.TYPE_INT_RGB); Graphics2D g = image.createGraphics(); g.draw(new Line2D.Double(0.0,0.0,10.0,10.0)); g.draw(new Line2D.Double(0.0,10.0,10.0,0.0)); return image; } } class EventHandler extends WindowAdapter implements ActionListener, ItemListener { public void actionPerformed(ActionEvent e){ String selection=e.getActionCommand(); if("Exit".equals(selection)){ System.exit(0); } } public void itemStateChanged(ItemEvent e){ } public void windowClosing(WindowEvent e){ System.exit(0); } } }