import java.awt.*;

import javax.swing.*;


/**
 * @author Remi Forax
 *
 */
public class GraphicsExample extends JComponent {

  protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    
    g.drawImage(image, 120, 50, this);
    
    g.setColor(Color.RED);
    g.fillRect(12,12,150,150);
    
    g.setColor(Color.BLUE);
    g.fillOval(24, 24, 100, 100);
    
    g.setColor(Color.BLACK);
    g.drawLine(34,34,154,112);
    
    g.setFont(font);
    g.drawString("Example",12,32);
  }
  
  private final Font font=new Font("SansSerif",Font.BOLD,20);
  private final Image image=new ImageIcon("moon.jpg").getImage();

  public static void main(String[] args) {
    
    JFrame frame=new JFrame("GraphicsExample");
    GraphicsExample component=new GraphicsExample();
    
    frame.getContentPane().add(component);
    frame.setSize(400,300);
    frame.show();
  }
}
