/****************************************************************** * @(#) Triangle.java 1.0 * * Copyright (c) 2003 John Miller * All Right Reserved *----------------------------------------------------------------- * Permission to use, copy, modify and distribute this software and * its documentation without fee is hereby granted provided that * this copyright notice appears in all copies. * WE MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY * OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT * LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. WE SHALL NOT BE * LIABLE FOR ANY DAMAGES SUFFERED BY ANY USER AS A RESULT OF USING, * MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. *----------------------------------------------------------------- * * @version 1.0, 29 Mar 2003 * @author John Miller */ import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import javax.swing.*; /****************************************************************** * The Triangle class places a triangle at (100, 100). */ public class Triangle extends JFrame { /************************************************************** * The DisplayPanel inner class is used to place shapes in the * drawing region. */ public class DisplayPanel extends JPanel { /********************************************************** * Paint the display panel component. * @param gr Graphics context. */ public void paintComponent (Graphics gr) { super.paintComponent (gr); Graphics2D gr2 = (Graphics2D) gr; GeneralPath tri = new GeneralPath (); tri.moveTo (100, 100); tri.lineTo (100, 200); tri.lineTo (300, 200); tri.closePath (); gr2.setPaint (Color.red); gr2.fill (tri); }; // paintComponent }; // DisplayPanel inner class /************************************************************** * Construct a frame. * @param title Title of frame */ public Triangle (String title) { super (title); addWindowListener (new WindowAdapter () { public void windowClosing (WindowEvent e) { System.exit (0); } }); getContentPane ().add (new DisplayPanel ()); setLocation (100, 100); setSize (400, 400); setVisible (true); }; // Triangle /************************************************************** * Main method for invoking the application. * @param args Command-line arguments */ public static void main (String [] args) { Triangle frame = new Triangle ("Triangle"); }; // main }; // Triangle class