Draw Rounded Corner Rectangle & Square in Applet Window Example

  1. /*
  2. Draw Rounded Corner Rectangle & Square in Applet Window Example
  3. This java example shows how to draw rounded corner rectangles and squares
  4. in an applet window using drawRoundRect method of Graphics class. It also
  5. shows how to draw a filled rounded corner rectangles and squares using
  6. fillRoundRect method of Graphics class.
  7. */
  8.  
  9. /*
  10. <applet code="DrawRoundedRectExample" width=500 height=500>
  11. </applet>
  12. */
  13.  
  14.  
  15. import java.applet.Applet;
  16. import java.awt.Color;
  17. import java.awt.Graphics;
  18.  
  19. public class DrawRoundedRectExample extends Applet{
  20.  
  21. public void paint(Graphics g){
  22.  
  23. //set color to red
  24. setForeground(Color.red);
  25.  
  26. /*
  27. * to draw a rounded corner rectangle in an applet window use,
  28. * void drawRoundRect(int x1,int y1, int width, int height, int arcWidth, int arcHeight)
  29. * method.
  30. *
  31. * This method draws a rounded corner rectangle of specified width and
  32. * height at (x1,y1)
  33. */
  34.  
  35. //this will draw a round cornered rectangle of width 50 & height 100 at (10,10)
  36. g.drawRoundRect(10,10,50,100,10,10);
  37.  
  38. /*
  39. * If you speficy same width and height, the drawRoundRect method
  40. * will draw a round cornered square!
  41. */
  42.  
  43. //this will draw a round cornered square
  44. g.drawRoundRect(100,100,50,50,10,10);
  45.  
  46. /*
  47. * To draw a filled round cornered rectangle or square use
  48. * fillRoundRect(int x1,int y1, int width, int height, int arcWidht, int arcHeight)
  49. * method of Graphics class.
  50. */
  51.  
  52. //set color to blue
  53. //setForeground(Color.blue);
  54.  
  55. //draw filled rounded corner rectangle
  56. g.fillRoundRect(200,20,50,100,10,10);
  57.  
  58. //draw filled square
  59. g.fillRoundRect(200,200,50,50,10,10);
  60. }
  61. }

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




Feel Tired? Read Jokes & Inspirational Stories, Play Games!