Academic Java    Java Tutorial  >  Graphics  >  rendering

rendering Example

Java rendering EXAMPLE output This applet renders an image, a shape, and some text, all on the same graphics context.

Notice that the rendering begins on a plane furthest from the viewer.
// Rendering Example
import java.awt.*;
import javax.swing.*;
import java.io.*;

class Rendering extends JApplet {

   private Image im;

   @Override public void init() {
      im = getImage(getDocumentBase(),"images/world.gif");
   }

   @Override public void paint(Graphics g) {
      super.paint(g);

      g.drawImage(im, 150, 100, this);
      g.fillRect(30, 100, 100, 100);

      g.setColor(Color.red);
      g.drawString("HERE'S SOME TEXT", 70,150);

   }
}


* graphics context Examples