Tuesday, March 16, 2010

Java's Graphics

Java is capable of employing graphics operations including creating of geometric shapes and making graphic designs.

This is supported by AWT package and since it is an abstract class, it can be instantiated directly. Typical graphics' methods include drawString() which places some text on x,y coordinates, setColor() for text colors and setFont() for changing font types, styles and sizes.  These methods can be done inside paint() method as one of Applet's inherent methods.

See the program below for sample illustration. 

[+/-] show/hide

/* sample program on graphics */

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class GraphicsDemo2 extends Applet {
String companyName = new String("STI");
Color newColor = new Color(100,20,255);//creating your own color
Font bigFont = new Font("Helvetica",Font.ITALIC,24);

public void paint(Graphics gr){
gr.drawString(companyName, 10, 100);
gr.drawString(companyName, 40, 140);