/** Affichage d'images : Exercise 2
 *
 *	@version 0.9  12/07/2001
 *	@author Pascal Vuylsteker
 */
 
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*;
import java.awt.geom.*;


public class Test extends JFrame	{	

	public Test()	{
		setTitle("Here is a pretty picture");

		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		ShowPanel panel = new ShowPanel();
		Container contentPane = getContentPane();
		contentPane.add(panel);
		setBounds(0,0,600,600);		
	}
	
	public static void main(String[] args)	{		
		Test frame = new Test();
		frame.show();
	}
	
}


class ShowPanel extends JPanel 	{	
	ShowPanel()	{	
	
		setBackground(Color.white);

		
		img = tk.getImage("/Volumes/Users/pvk/nexen.gif");
		
		try	{
        	MediaTracker tracker = new MediaTracker(this);
        	tracker.addImage(img, 0);
        	tracker.waitForID(0);
        }
        catch ( Exception e ) {}
        
        x = img.getWidth(this);
		y = img.getHeight(this);
		
		img = img.getScaledInstance(200, 200, Image.SCALE_SMOOTH);
		try	{
        	MediaTracker tracker = new MediaTracker(this);
        	tracker.addImage(img, 0);
        	tracker.waitForID(0);
        }
        catch ( Exception e )	{}

 		bi = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
		Graphics2D biContext = bi.createGraphics();
		biContext.drawImage(img, 0, 0, null);
		
		biContext.setPaint(Color.red);
		biContext.draw(new Line2D.Double(0,0,199,199));


		lbi = bi.getSubimage(0,0,199,199);
		try	{
        	MediaTracker tracker = new MediaTracker(this);
        	tracker.addImage(lbi, 0);
        	tracker.waitForID(0);
        }
        catch ( Exception e )	{}
    }


	public void paintComponent(Graphics g)	{
		super.paintComponent(g);
		Graphics2D g2 = (Graphics2D) g;
		
		
        // Draws and fills the newly positioned rectangle.
		g2.setPaint(Color.red);

		g2.drawImage(lbi,rect.x,rect.y,null);

		g2.drawImage(bi,0,0,null);		

		g.drawString("Bonjour...  "+name, 20, 20);
	}

private	Image img;
private	BufferedImage bi,lbi;
private Graphics2D big;
}
