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

import java.awt.event.*;

// Anzeige eines Bildes
// Stonehenge.jpg

import java.awt.geom.*;

import java.io.*;
import java.awt.image.*;

import com.sun.image.codec.jpeg.*;


public class Dialog_Picture1_2D extends JFrame {



  CCanvas1 _canvas = new CCanvas1(this, "Stonehenge.jpg");


  public Dialog_Picture1_2D(String caption) {
    setTitle(caption);
    setGUI();
  }


  private void setGUI() {
    this.getContentPane().setLayout( new BorderLayout() );
    this.getContentPane().add(_canvas, BorderLayout.CENTER);
  }


    // dient zum Beenden
  protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if(e.getID() == WindowEvent.WINDOW_CLOSING) {
      System.exit(0);
    }
  }



    public static void main(String args[]) {
      Dialog_Picture1_2D f = new Dialog_Picture1_2D("Dialog_Picture1_2D");
     	f.setSize(900,800);
    	f.setVisible(true);
    }


}


class CCanvas1 extends JPanel {

  Component cmp;
  BufferedImage image;


  public CCanvas1(Component cmp, String sFilename) {
    this.cmp = cmp;
    image = loadPicture(sFilename);
  }


  private BufferedImage loadPicture(String filename)  {
    BufferedImage image=null;
    try {
     	FileInputStream in = new FileInputStream(filename);
      JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(in);
      image = decoder.decodeAsBufferedImage();
      in.close();
    }
    catch (IOException e) {
    }
    return image;
  }

  public void paint (Graphics g) {
    // holt die Abmessungen des Canvas
    Rectangle r = new Rectangle();  // double wert
    g.getClipBounds(r);
        // Löschen des Bildschirms
    g.setColor(Color.white);
    g.fillRect(0,0, (int)r.getWidth(), (int)r.getHeight() );

    Graphics2D g2 = (Graphics2D) g;

    //g2.drawImage(image, 10,10, 200,100,cmp);
    g2.drawImage(image,10,10, Color.red, cmp);

//      g2.draw(rect);

  }

}





