{"id":680,"date":"2021-01-10T21:59:42","date_gmt":"2021-01-10T21:59:42","guid":{"rendered":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/?page_id=680"},"modified":"2021-01-10T22:30:20","modified_gmt":"2021-01-10T22:30:20","slug":"shapes","status":"publish","type":"page","link":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/graphics-programming\/shapes\/","title":{"rendered":"Shapes"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a21c3035f558\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a21c3035f558\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/graphics-programming\/shapes\/#Simple_Shapes\" >Simple Shapes<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/graphics-programming\/shapes\/#Outline_Shapes\" >Outline Shapes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/graphics-programming\/shapes\/#Filled_Shapes\" >Filled Shapes<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/graphics-programming\/shapes\/#Java_2D_Shapes\" >Java 2D Shapes<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/graphics-programming\/shapes\/#Simple_Example\" >Simple Example<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/graphics-programming\/shapes\/#The_Java_2D_Demo\" >The Java 2D Demo<\/a><\/li><\/ul><\/nav><\/div>\n\n<p class=\"wp-block-paragraph\">Originally, Java only provided relatively simple support for drawing shapes.&nbsp; This support was provided in the&nbsp;<strong><code>java.awt.Graphics<\/code><\/strong>&nbsp;class, and was very limited:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>You could only draw a limited set of shapes:<ul><li>Lines, rectangles, ellipses, etc.<\/li><\/ul><\/li><li>You could not vary the line thickness.&nbsp; It was always set at 1.<\/li><li>You could not rotate, or otherwise transform the shapes.&nbsp;<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Then, in JDK 1.2, a richer level of support was added for drawing shapes.&nbsp; It was called the <em>Java 2D library<\/em>.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Simple_Shapes\"><\/span>Simple Shapes<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Here are some examples of how you can use the original, relatively primitive, support for drawing provided by the <strong><code>java.awt.Graphics<\/code><\/strong> class:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Outline shapes<\/li><li>Filled shapes<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Outline_Shapes\"><\/span>Outline Shapes<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s an example of how you can draw&nbsp;<strong><em>outline shapes<\/em><\/strong>&nbsp;using the original, primitive AWT drawing support:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; highlight: [6,16,17,18,19,20,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107]; title: ; quick-code: false; notranslate\" title=\"\">\npackage swingExamples;\n\nimport java.awt.Color;\nimport java.awt.Container;\nimport java.awt.Graphics;\nimport java.awt.Polygon;\n\nimport javax.swing.JFrame;\nimport javax.swing.JPanel;\n\nclass ShapesDisplayPanel extends JPanel\n{\n  public void paintComponent(Graphics g)\n  {\n    super.paintComponent(g);\n    int cx = 5;\n    int cy = 5;\n    cy = drawPolys(g, cx, cy);\n    cy = drawRects(g, cx, cy);\n    cy = drawOvals(g, cx, cy);\n  }\n  \n  private int drawPolys(Graphics g, int cx, int cy)\n  {\n    int r = 45;     \/\/ radius of circle\n    cx += r;\n    cy += r;\n    int angle = 30;\n    \n    int dx = (int)(r * Math.cos(angle * Math.PI\/180));\n    int dy = (int)(r * Math.sin(angle * Math.PI\/180));\n    \n    g.drawLine(cx, cy, cx + dx, cy + dy);\n    g.drawLine(cx, cy, cx + dx, cy - dy);\n    g.drawArc(cx - r, cy - r, 2 * r, 2 * r, angle, 360 - 2*angle);\n    \n    Polygon poly = new Polygon();\n    cx += 100;\n    for (int i = 0; i &lt; 5; i++)\n    {\n      poly.addPoint((int)(cx + r * Math.cos(i * 2 * Math.PI\/5)),\n          (int)(cy + r * Math.sin(i * 2 * Math.PI\/5)));\n    }\n    g.setColor(Color.RED);\n    g.drawPolygon(poly);\n    \n    poly = new Polygon();\n    cx += 100;\n    for (int i = 0; i &lt; 360; i++)\n    {\n      double t = i\/360.0;\n      poly.addPoint((int)(cx + r * t * Math.cos(8 * t * Math.PI)),\n          (int)(cy + r * t * Math.sin(8 * t * Math.PI)));\n    }\n    g.setColor(Color.BLUE);\n    g.drawPolygon(poly);\n    \n    return cy + r + 10;\n  }\n  \n  private int drawRects(Graphics g, int cx, int cy)\n  {\n    int width = 80;\n    int height = 30;\n    \n    g.setColor(Color.MAGENTA);\n    g.drawRect(cx, cy, width, height);\n    \n    cx += 100;\n    g.setColor(Color.GREEN);\n    g.drawRoundRect(cx, cy, width, height, 15, 15);\n    \n    cx += 100;\n    g.setColor(Color.PINK);\n    g.draw3DRect(cx, cy, width, height, true);\n    \n    cx += 100;\n    g.draw3DRect(cx, cy, width, height, false);\n    \n    return cy + height + 10;\n  }\n  \n  private int drawOvals(Graphics g, int cx, int cy)\n  {\n    int width = 80;\n    int height = 30;\n    \n    g.setColor(Color.MAGENTA);\n    g.drawOval(cx, cy, width, height);\n    \n    cx += 100;\n    height = 80;\n    g.setColor(Color.BLUE);\n    g.drawArc(cx, cy, width, height, 0, 360);\n    \n    cx += 100;\n    g.setColor(Color.BLACK);\n    g.drawOval(cx, cy, width, height);\n    \n    cx += 100;\n    height = 100;\n    g.setColor(Color.ORANGE);\n    g.drawOval(cx, cy, width, height);\n    \n    return cy + height + 10;\n  }\n}\n\nclass ShapesDisplayFrame extends JFrame\n{\n  public ShapesDisplayFrame()\n  {\n    setTitle(&quot;ShapesDisplay&quot;);\n    setSize(400, 280);\n    setDefaultCloseOperation(EXIT_ON_CLOSE);\n    Container contentPane = getContentPane();\n    contentPane.add( new ShapesDisplayPanel() );\n  }\n}\n\npublic class ShapesDisplay\n{\n  public static void main(String&#x5B;] args)\n  {\n    ShapesDisplayFrame frame = new ShapesDisplayFrame();\n    frame.setVisible(true);\n  }\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">which produces:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"400\" height=\"280\" src=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-content\/uploads\/2021\/01\/OutlineShapesDisplay.gif\" alt=\"\" class=\"wp-image-684\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Filled_Shapes\"><\/span>Filled Shapes<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The previous example can be easily modified to create&nbsp;<strong><em>filled shapes<\/em><\/strong>, by changing the calls made in <strong>ShapesDisplayPanel<\/strong>:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; highlight: [34,44,55,66,70,74,77,88,93,97,102]; title: ; quick-code: false; notranslate\" title=\"\">\npackage swingExamples;\n\nimport java.awt.Color;\nimport java.awt.Container;\nimport java.awt.Dimension;\nimport java.awt.Graphics;\nimport java.awt.Polygon;\n\nimport javax.swing.JFrame;\nimport javax.swing.JPanel;\n\nclass FilledShapesDisplayPanel extends JPanel\n{\n    public void paintComponent(Graphics g)\n    {\n        super.paintComponent(g);\n        int cx = 5;\n        int cy = 5;\n        cy = drawPolys(g, cx, cy);\n        cy = drawRects(g, cx, cy);\n        cy = drawOvals(g, cx, cy);\n    }\n\n    private int drawPolys(Graphics g, int cx, int cy)\n    {\n        int r = 45;     \/\/ radius of circle\n        cx += r;\n        cy += r;\n        int angle = 30;\n\n        int dx = (int)(r * Math.cos(angle * Math.PI\/180));\n        int dy = (int)(r * Math.sin(angle * Math.PI\/180));\n\n        g.fillArc(cx - r, cy - r, 2*r, 2*r, angle, 360 - 2*angle);\n\n        Polygon poly = new Polygon();\n        cx += 100;\n        for (int i = 0; i &lt; 5; i++)\n        {\n            poly.addPoint((int)(cx + r * Math.cos(i * 2 * Math.PI\/5)),\n                          (int)(cy + r * Math.sin(i * 2 * Math.PI\/5)));\n        }\n        g.setColor(Color.RED);\n        g.fillPolygon(poly);\n\n        poly = new Polygon();\n        cx += 100;\n        for (int i = 0; i &lt; 360; i++)\n        {\n            double t = i\/360.0;\n            poly.addPoint((int)(cx + r * t * Math.cos(8 * t * Math.PI)),\n                          (int)(cy + r * t * Math.sin(8 * t * Math.PI)));\n        }\n        g.setColor(Color.BLUE);\n        g.fillPolygon(poly);\n\n        return cy + r + 10;\n    }\n\n    private int drawRects(Graphics g, int cx, int cy)\n    {\n        int width = 80;\n        int height = 30;\n\n        g.setColor(Color.MAGENTA);\n        g.fillRect(cx, cy, width, height);\n\n        cx += 100;\n        g.setColor(Color.GREEN);\n        g.fillRoundRect(cx, cy, width, height, 15, 15);\n\n        cx += 100;\n        g.setColor(Color.PINK);\n        g.fill3DRect(cx, cy, width, height, true);\n\n        cx += 100;\n        g.fill3DRect(cx, cy, width, height, false);\n\n        return cy + height + 10;\n    }\n\n    private int drawOvals(Graphics g, int cx, int cy)\n    {\n        int width = 80;\n        int height = 30;\n\n        g.setColor(Color.MAGENTA);\n        g.fillOval(cx, cy, width, height);\n\n        cx += 100;\n        height = 80;\n        g.setColor(Color.BLUE);\n        g.fillArc(cx, cy, width, height, 0, 360);\n\n        cx += 100;\n        g.setColor(Color.BLACK);\n        g.fillOval(cx, cy, width, height);\n\n        cx += 100;\n        height = 100;\n        g.setColor(Color.ORANGE);\n        g.fillOval(cx, cy, width, height);\n\n        return cy + height + 10;\n    }\n}\n\nclass FilledShapesDisplayFrame extends JFrame\n{\n    public FilledShapesDisplayFrame()\n    {\n        setTitle(&quot;FilledShapesDisplay&quot;);\n        setSize(400, 280);\n        setDefaultCloseOperation(EXIT_ON_CLOSE);\n        Container contentPane = getContentPane();\n        contentPane.add( new FilledShapesDisplayPanel() );\n    }\n}\n\npublic class FilledShapesDisplay\n{\n  public static void main(String&#x5B;] args)\n  {\n    FilledShapesDisplayFrame frame = new FilledShapesDisplayFrame();\n    frame.setVisible(true);\n  }\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">which produces:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large\"><img decoding=\"async\" width=\"400\" height=\"280\" src=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-content\/uploads\/2021\/01\/FilledShapesDisplay.gif\" alt=\"\" class=\"wp-image-689\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:26px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Java_2D_Shapes\"><\/span>Java 2D Shapes<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Here is some introductory information on drawing shapes using <em>Java 2D<\/em>.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong><em><u>Note:<\/u><\/em><\/strong>&nbsp;Entire books have been written on just this subject, so we won&#8217;t go into great detail on Java 2D in this course.<\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Java 2D<\/em> provides the ability to:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Draw shapes whose classes use inheritance to&nbsp;share attributes and behavior:<ul><li><strong>Line2D<\/strong>, <strong>Rectangle2D<\/strong>, <strong>Ellipse2D<\/strong><\/li><\/ul><\/li><li>Draw more complex shapes:<ul><li>Arcs, quadratic and cubic curves, etc.<\/li><\/ul><\/li><li>Draw user-defined shapes, using the same inheritance support<\/li><li>Draw lines with different thicknesses, different &#8220;strokes&#8221; (dotted, dashed, etc)<\/li><li>Fill shapes with more complex fillings, such as patterns and blends.<\/li><li>Perform transformations on those shapes such as rotation, shift, stretch, etc.<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Simple_Example\"><\/span>Simple Example<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">To use Java 2D graphics, the same basic principles apply as for the older, more primitive, approach:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Override the&nbsp;<code><strong>paintComponent<\/strong><\/code>&nbsp;method.<\/li><li>Write your rendering code inside your&nbsp;<code><strong>paintComponent<\/strong><\/code>&nbsp;method.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The major difference is that you must obtain an object of the&nbsp;<strong><code>java.awt.Graphics2<\/code><\/strong>&nbsp;class.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s an example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; highlight: [23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70]; title: ; quick-code: false; notranslate\" title=\"\">\npackage swingExamples;\n\nimport java.awt.BasicStroke;\nimport java.awt.Color;\nimport java.awt.Container;\nimport java.awt.GradientPaint;\nimport java.awt.Graphics;\nimport java.awt.Graphics2D;\n\nimport java.awt.geom.Ellipse2D;\nimport java.awt.geom.Line2D;\nimport java.awt.geom.Rectangle2D;\n\nimport javax.swing.JFrame;\nimport javax.swing.JPanel;\n\nclass Java2DShapesDisplayPanel extends JPanel\n{\n  public void paintComponent(Graphics g)\n  {\n    super.paintComponent(g);\n    \n    Graphics2D g2 = (Graphics2D) g;\n    \n    \/\/ Create a BasicStroke for drawing outlines\n    BasicStroke stroke = new BasicStroke(3.0F,\n        BasicStroke.CAP_ROUND,\n        BasicStroke.JOIN_ROUND);\n    g2.setStroke(stroke);\n    \n    \/\/ Draw a rectangle\n    double leftX = 100;\n    double topY = 100;\n    double width = 200;\n    double height = 150;\n    Rectangle2D rect = new Rectangle2D.Double(leftX, topY, width, height);\n    g2.setPaint(Color.GRAY);\n    g2.draw(rect);\n    \n    \/\/ Draw the enclosed ellipse, with a gradient fill\n    Ellipse2D ellipse = new Ellipse2D.Double();\n    ellipse.setFrame(rect);\n    GradientPaint gp = new GradientPaint(120, 100, Color.RED,\n                                         170, 190, Color.ORANGE);\n    g2.setPaint(gp);\n    g2.fill(ellipse);\n    \n    \/\/ Draw a diagonal line, with a different stroke\n    stroke = new BasicStroke(7.0F, BasicStroke.CAP_BUTT,\n                                   BasicStroke.JOIN_ROUND);\n    g2.setStroke(stroke);\n    g2.setPaint(Color.GREEN);\n    g2.draw( new Line2D.Double(leftX, topY, \n                               leftX + width, topY + height) );\n    \n    \/\/ Draw a circle with the same center, using a dashed stroke\n    stroke = new BasicStroke(3.0F,\n                             BasicStroke.CAP_BUTT,\n                             BasicStroke.JOIN_BEVEL,\n                             0, new float&#x5B;] {12, 12}, 0);\n    g2.setStroke(stroke);\n    \n    double centerX = rect.getCenterX();\n    double centerY = rect.getCenterY();\n    double radius = 150;\n    Ellipse2D circle = new Ellipse2D.Double();\n    circle.setFrameFromCenter(centerX, centerY,\n        centerX + radius, centerY + radius);\n    g2.setPaint(Color.BLUE);\n    g2.draw(circle);\n  }\n}\n\nclass Java2DShapesDisplayFrame extends JFrame\n{\n  public Java2DShapesDisplayFrame()\n  {\n    setTitle(&quot;Java2D Shapes Display&quot;);\n    setSize(400, 400);\n    setDefaultCloseOperation(EXIT_ON_CLOSE);\n    Container contentPane = getContentPane();\n    contentPane.add( new Java2DShapesDisplayPanel() );\n  }\n}\n\npublic class Java2DShapesDisplay\n{\n  public static void main(String&#x5B;] args)\n  {\n    Java2DShapesDisplayFrame frame = new Java2DShapesDisplayFrame();\n    frame.setVisible(true);\n  }\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">which produces the following output:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large\"><img decoding=\"async\" width=\"400\" height=\"400\" src=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-content\/uploads\/2021\/01\/Java2dDisplay.gif\" alt=\"\" class=\"wp-image-695\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:19px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"The_Java_2D_Demo\"><\/span>The Java 2D Demo<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To give you some idea of the power (and potential complexity!) of Java 2D graphics, you can run the Java 2D demo. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Java 2 (aka 1.2) includes a sample program that demonstrates many of the features of the API. To run it, navigate to the&nbsp;<em><strong>demo\/jfc\/Java2D<\/strong><\/em>&nbsp;directory in the JDK installation directory. Then run the&nbsp;<strong>Java2Demo<\/strong>&nbsp;class. For example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">C:&gt; <strong>cd \\jdk1.2\\demo\\jfc\\Java2D<\/strong>\nC:&gt; <strong>java Java2Demo<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">which should bring up something like this:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"730\" height=\"570\" src=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-content\/uploads\/2021\/01\/java2d-demo03.gif\" alt=\"\" class=\"wp-image-699\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:33px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">You can find a variety of Demonstrations of Java&#8217;s capabilities <a href=\"https:\/\/download.oracle.com\/otn_hosted_doc\/jdeveloper\/904preview\/jdk14doc\/docs\/relnotes\/demos.html\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Originally, Java only provided relatively simple support for drawing shapes.&nbsp; This support was provided in the&nbsp;java.awt.Graphics&nbsp;class, and was very limited: You could only draw a limited set of shapes: Lines, rectangles, ellipses, etc. You could not vary the line thickness.&nbsp; It was always set at 1. You could not rotate, or otherwise transform the shapes.&nbsp; [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":67,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_eb_attr":"","_uag_custom_page_level_css":"","ocean_post_layout":"left-sidebar","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"ocs-course-topics-sidebar","ocean_second_sidebar":"0","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"0","ocean_custom_header_template":"0","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"0","ocean_menu_typo_font_family":"0","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"0","footnotes":""},"class_list":["post-680","page","type-page","status-publish","hentry","entry"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"ocean-thumb-m":false,"ocean-thumb-ml":false,"ocean-thumb-l":false},"uagb_author_info":{"display_name":"Bryan Higgs","author_link":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/author\/bryan\/"},"uagb_comment_info":0,"uagb_excerpt":"Originally, Java only provided relatively simple support for drawing shapes.&nbsp; This support was provided in the&nbsp;java.awt.Graphics&nbsp;class, and was very limited: You could only draw a limited set of shapes: Lines, rectangles, ellipses, etc. You could not vary the line thickness.&nbsp; It was always set at 1. You could not rotate, or otherwise transform the shapes.&nbsp;&hellip;","_links":{"self":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/pages\/680","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/comments?post=680"}],"version-history":[{"count":12,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/pages\/680\/revisions"}],"predecessor-version":[{"id":701,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/pages\/680\/revisions\/701"}],"up":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/pages\/67"}],"wp:attachment":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/media?parent=680"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}