Real'sHowTo AddThis Feed Button
Custom Search

Draw a line or set a pixel in my own imageTag(s): AWT

import java.awt.image.*;
import java.awt.*;
import java.applet.*;

public class CreateAnImage extends Applet {
  Image myImage;

  public void init() {
    int x = 100;
    int y = 100;
    myImage = createImage(x,y);
    Graphics g = myImage.getGraphics();
    for(int i=0; i < x; i+=2){
       setPixel(myImage, 50, i, new Color(0).blue);
       setPixel(myImage, i, 50, new Color(0).green);

  public void paint(Graphics g) {

  public void setPixel
      (Image image, int x, int y, Color color ) {
    Graphics g = image.getGraphics( );
    g.setColor( color );
    g.fillRect( x, y, 1, 1 );
    g.dispose( );

blog comments powered by Disqus

If you find this article useful, consider making a small donation
to show your support for this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2015
[ home ]