/* * @file HellowWorld.java * @author Chee Yap (yap@cs.nyu.edu) * @date Jan 24, 2003 * * @purpose * A first example of Java2D Graphics. * Uses ApplicationFrame class to draw a yellow rectangle * with a blue "Hello World!" message. * * @notes Used for Webbased Visualization Class, Spring'03 * * $Id: HelloWorld.java,v 1.1 2003/01/26 05:19:42 Administrator Exp $ ************************************************************/ import java.awt.*; import java.awt.event.*; import java.awt.geom.*; public class HelloWorld { //////////////////////////////////////////////////////////// // MAIN METHOD //////////////////////////////////////////////////////////// public static void main(String[] args) { ApplicationFrame f = new ApplicationFrame("Hello World Frame"){ public void paint(Graphics g){ // (1) Get Graphics2D object: Graphics2D g2 = (Graphics2D) g; // (2) Set Rendering Context g2.setPaint(Color.yellow); // paint attribute // (3) Render Geometry int x=50; int y=50; int w=100; int h=60; g2.fillRect(x, y, w, h); // draws solid yellow rect // (4) Render Text g2.setPaint(Color.blue); g2.drawString("Hello World!", 55, 80); }//paint };// new ApplicationFrame // Display the frame! int border = 100; f.setSize(500+border,300+border); f.center(); f.setVisible(true); }//main }//class HelloWorld