Draw 3D Rectangle & Square in Applet Window Example

  1. /*
  2. Draw 3D Rectangle & Square in Applet Window Example
  3. This java example shows how to draw 3-D rectangles and squares in an applet
  4. window using draw3DRect method of Graphics class. It also shows how to
  5. draw a filled 3-D rectangles and squares.
  6. */
  7.  
  8. /*
  9. <applet code="Draw3DRectanglesExample" width=200 height=200>
  10. </applet>
  11. */
  12.  
  13.  
  14. import java.applet.Applet;
  15. import java.awt.Color;
  16. import java.awt.Graphics;
  17.  
  18. public class Draw3DRectanglesExample extends Applet{
  19.  
  20. public void paint(Graphics g){
  21.  
  22. g.setColor(Color.green);
  23. /*
  24. * To draw a 3-D rectangle in an applet window use,
  25. * void draw3DRect(int x1,int y1, int width, int height, boolean raised)
  26. * method.
  27. *
  28. * This method draws a 3-D rectangle of specified width and
  29. * height at (x1,y1)
  30. */
  31.  
  32. //this will draw a 3-D rectangle of width 50 & height 100 at (10,10)
  33. g.draw3DRect(10,10,50,100,true);
  34.  
  35. /*
  36. * If you speficy same width and height, the draw3DRect method
  37. * will draw a 3-D square!
  38. */
  39.  
  40. //this will draw a 3-D square
  41. g.draw3DRect(100,100,50,50,true);
  42.  
  43. g.setColor(Color.orange);
  44.  
  45. /*
  46. * To draw a filled 3-D rectangle in an applet window use,
  47. * void fill3DRect(int x1,int y1, int width, int height, boolean raised)
  48. * method.
  49. *
  50. * This method draws a filled 3-D rectangle of specified width and
  51. * height at (x1,y1)
  52. */
  53.  
  54. //this will draw a filled 3-D rectangle of width 50 & height 100 at (10,10)
  55. g.fill3DRect(10,150,50,100,true);
  56.  
  57. /*
  58. * If you speficy same width and height, the fill3DRect method
  59. * will draw a filled 3-D square!
  60. */
  61.  
  62. //this will draw a filled 3-D square
  63. g.fill3DRect(100,200,50,50,true);
  64.  
  65. }
  66. }

Example Output





Suggested Reading

Oracle Magazine
Contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more.
Cost: FREE

View/Subscribe
NASA Tech Briefs
Features exclusive reports of innovations developed by NASA and its industry partners/contractors that can be applied to develop new/improved products and solve engineering or manufacturing problems.
Cost: FREE

View/Subscribe
FierceBiotech IT
Is a free, easy to read weekly email service that brings must read biotech IT news to senior biotech, pharma, and IT executives.
Cost: FREE

View/Subscribe
Simply SQL
Simply SQL is a practical step-by-step guide to writing SQL.
Cost: FREE

View/Subscribe
Simply JavaScript
Packed with full-color examples, Simply JavaScript is all you need to start programming in JavaScript the right way.
Cost: FREE

View/Subscribe
PCMag.com's What's New Now
Lance Ulanoff, Editor in Chief of the PC Magazine Network, brings you this twice-weekly roundup of the latest top tech stories, the best new product reviews, plus special offers from Ziff Davis and its partners.
Cost: FREE

View/Subscribe

Could not find what you are looking for? Search Java Examples