// FlyingArrowApplet.java (c) 2005 Kari Laitinen // 2006-01-27 File created. // 2006-01-27 Latest modification. // This is a Java Swing applet that demonstrates Java 2D features. import java.awt.* ; import java.awt.geom.* ; // Classes GeneralPath etc. import javax.swing.* ; class FlyingArrowPanel extends JPanel { public void paintComponent( Graphics graphics ) { super.paintComponent( graphics ) ; Graphics2D graphics2D = (Graphics2D) graphics ; // The arrow coordinates are selected so that Point (0, 0) // is at the tip of the arrow, and the arrow points upwards. int[] arrow_shape_coordinates_x = { 0, 15, 5, 5, 15, 0, -15, -5, -5, -15 } ; int[] arrow_shape_coordinates_y = { 0, 40, 30, 120, 160, 130, 160, 120, 30, 40 } ; GeneralPath flying_arrow = new GeneralPath() ; flying_arrow.moveTo( arrow_shape_coordinates_x[ 0 ], arrow_shape_coordinates_y[ 0 ] ) ; for ( int point_index = 1 ; point_index < arrow_shape_coordinates_x.length ; point_index ++ ) { flying_arrow.lineTo( arrow_shape_coordinates_x[ point_index ], arrow_shape_coordinates_y[ point_index ] ) ; } flying_arrow.closePath() ; graphics2D.translate( 150, 250 ) ; // arrow tip to point (150, 250 ) graphics2D.fill( flying_arrow ) ; // draw solid arrow graphics2D.rotate( Math.PI / 4 ) ; // 45 degrees clockwise graphics2D.draw( flying_arrow ) ; // draw a hollow arrow graphics2D.translate( 0, -200 ) ; // flying "up" 200 points graphics2D.fill( flying_arrow ) ; graphics2D.rotate( Math.PI / 4 ) ; // 45 degrees clockwise graphics2D.translate( 0, -200 ) ; // flying "up" (i.e. to the right) graphics2D.fill( flying_arrow ) ; graphics2D.translate( 0, -100 ) ; // flying "up" 100 points graphics2D.rotate( Math.PI / 2 ) ; // 90 degrees clockwise graphics2D.scale( 1.5, 1.5 ) ; // magnify everything by 1.5 graphics2D.draw( flying_arrow ) ; // draw a hollow arrow graphics2D.translate( 0, -200 ) ; // flying "up" (i.e. down) 300 points graphics2D.fill( flying_arrow ) ; } } public class FlyingArrowApplet extends JApplet { public void init() { getContentPane().add( new FlyingArrowPanel() ) ; } } /* These are old (and bad) arrow coordinates: int[] arrow_shape_coordinates_x = { 15, 30, 20, 20, 30, 15, 0, 10, 10, 0 } ; int[] arrow_shape_coordinates_y = { 0, 50, 40, 140, 170, 150, 170, 140, 40, 50 } ; // The following coordinates are selected so that Point (0, 0) // is at the center point of the arrow. int[] arrow_shape_coordinates_x = { 0, 15, 5, 5, 15, 0, -15, -5, -5, -15 } ; int[] arrow_shape_coordinates_y = { -80, -40, -50, 40, 80, 50, 80, 40, -50, -40 } ; */