Code for an applet drawing example.
import java.awt.*;
import java.applet.*;
import java.util.*;
import java.awt.geom.*;
public class DrawText extends Applet {
public void paint(Graphics g) {
// using a more modern 2D graphics
Graphics2D g2 = (Graphics2D) g;
// get the size of the applet
// NOTE: NOT A GRAPHICS METHOD!
Dimension size = getSize();
// determine the size of the largest circle that fits into the
// the applet
int width = size.width;
int height = size.height;
int diameter;
if (width < height) diameter = width;
else diameter = height;
// set rendering hints to improve quality
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
// draw the background
g2.setColor(Color.black);
g2.fillRect(0,0,size.width,size.height);
// set color for writing:
g2.setColor(Color.orange);
// set the font
g2.setFont(new Font("SansSerif",Font.BOLD,100));
g2.drawString("Java",45,120);
g2.setColor(Color.green);
g2.setFont(new Font("SansSerif",Font.ITALIC,80));
g2.drawString("is",125,200);
g2.setColor(Color.cyan);
g2.setFont(new Font("SansSerif",Font.ITALIC,120));
// new Affine Transform
AffineTransform at = new AffineTransform();
at.shear(0., 0.2);
g2.setTransform(at);
g2.drawString("COOL",30,300);
}
}
This is an example from CSci 1211 course.