Manta.java



//EJEMPLO DE CANVAS DENTRO DE UNA VENTANA

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;


public class Manta extends JFrame
{
	Lienzo LIENZO;

	public Manta ()
	{
		this.getContentPane().setLayout(null);
		this.setTitle("LIENZO DENTRO DE UNA VENTANA (JFrame)");
		this.setResizable(false);
		this.setLocation(200, 100);
		this.setSize(new Dimension(700, 400));
		setBackground(Color.blue);
		setVisible(true);

		LIENZO=new Lienzo(); add(LIENZO); LIENZO.setBounds(100, 200, 400, 100);
		LIENZO.setBackground(Color.yellow);
		LIENZO.x=100; LIENZO.y=10; LIENZO.radio=90; LIENZO.repaint();
	}

	public static void main(String R[]) { new Manta(); }

	// 3.-	Captura del evento "cerrar ventana"
	protected void processWindowEvent(WindowEvent e)
	{
		super.processWindowEvent(e);
		if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); }
	}
}

class Lienzo extends Canvas
{
	int x=10, y=20, radio=10;

	public Lienzo()
	{
		setBackground(Color.yellow);
	}

	public void paint(Graphics G)
	{
		G.setColor(Color.blue);
		G.fillOval(x, y, radio, radio);
	}
}