This is a sweet one. If you're doing any graphics at all in Java 2, you can make it look a lot nicer with a single line of code. Consider the following paint() method:
public void paint(Graphics g) {
g.setColor(Color.green);
g.drawLine(20, 20, 40, 140);
g.setColor(Color.blue);
g.fillOval(50, 110, 120, 60);
g.setColor(Color.red);
g.setFont(new Font("Serif", Font.ITALIC, 36));
g.drawString("Cellini", 40, 80);
}
I haven't even used any 2D API features here--it's just plain old AWT graphics stuff. Adding antialiasing is easy. Just add this line to the very top of the paint() method:
((Graphics2D)g).setRenderingHint
(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
No comments:
Post a Comment