Source of LinesRectsOvalsJPanel.java


  1: // Fig. 12.18: LinesRectsOvalsJPanel.java
  2: // Drawing lines, rectangles and ovals.
  3: import java.awt.Color;
  4: import java.awt.Graphics;
  5: import javax.swing.JPanel;
  6: 
  7: public class LinesRectsOvalsJPanel extends JPanel 
  8: {
  9:    // display various lines, rectangles and ovals
 10:    public void paintComponent( Graphics g )
 11:    {
 12:       super.paintComponent( g ); // call superclass's paint method
 13: 
 14:       this.setBackground( Color.WHITE );
 15: 
 16:       g.setColor( Color.RED );
 17:       g.drawLine( 5, 30, 380, 30 );
 18: 
 19:       g.setColor( Color.BLUE );
 20:       g.drawRect( 5, 40, 90, 55 );
 21:       g.fillRect( 100, 40, 90, 55 );
 22: 
 23:       g.setColor( Color.BLACK );
 24:       g.fillRoundRect( 195, 40, 90, 55, 50, 50 );
 25:       g.drawRoundRect( 290, 40, 90, 55, 20, 20 );
 26: 
 27:       g.setColor( Color.YELLOW );   
 28:       g.draw3DRect( 5, 100, 90, 55, true );
 29:       g.fill3DRect( 100, 100, 90, 55, false );
 30: 
 31:       g.setColor( Color.MAGENTA );
 32:       g.drawOval( 195, 100, 90, 55 );
 33:       g.fillOval( 290, 100, 90, 55 );
 34:    } // end method paintComponent
 35: } // end class LinesRectsOvalsJPanel
 36: 
 37: /**************************************************************************
 38:  * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and               *
 39:  * Pearson Education, Inc. All Rights Reserved.                           *
 40:  *                                                                        *
 41:  * DISCLAIMER: The authors and publisher of this book have used their     *
 42:  * best efforts in preparing the book. These efforts include the          *
 43:  * development, research, and testing of the theories and programs        *
 44:  * to determine their effectiveness. The authors and publisher make       *
 45:  * no warranty of any kind, expressed or implied, with regard to these    *
 46:  * programs or to the documentation contained in these books. The authors *
 47:  * and publisher shall not be liable in any event for incidental or       *
 48:  * consequential damages in connection with, or arising out of, the       *
 49:  * furnishing, performance, or use of these programs.                     *
 50:  *************************************************************************/