{"id":26890,"date":"2021-05-04T23:10:05","date_gmt":"2021-05-05T03:10:05","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/linestyles-java-provides-examples-of-the-available-styles-for-joining-line-segments-programming-code-examples-java-j2ee-j2me-drawing\/"},"modified":"2021-05-04T23:10:05","modified_gmt":"2021-05-05T03:10:05","slug":"linestyles-java-provides-examples-of-the-available-styles-for-joining-line-segments-programming-code-examples-java-j2ee-j2me-drawing","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=26890","title":{"rendered":"LineStyles.java Provides examples of the available styles for joining line segments #Programming Code Examples #Java\/J2EE\/J2ME #Drawing"},"content":{"rendered":"<pre>\nimport javax.swing.*;\nimport java.awt.*;\nimport java.awt.geom.*;\n\n\/** A demonstration of different controls when joining two line\n *  segments. The style of the line end point is controlled\n *  through the capStyle parameter.\n *\n ************************************\n\npublic class LineStyles extends JPanel {\n  private GeneralPath path;\n  private static int x = 30, deltaX = 150, y = 300,\n                     deltaY = 250, thickness = 40;\n  private Circle p1Large, p1Small, p2Large, p2Small,\n                 p3Large, p3Small;\n  private int compositeType = AlphaComposite.SRC_OVER;\n  private AlphaComposite transparentComposite =\n    AlphaComposite.getInstance(compositeType, 0.4F);\n  private int[] caps =\n    { BasicStroke.CAP_SQUARE, BasicStroke.CAP_BUTT,\n      BasicStroke.CAP_ROUND };\n  private String[] capNames =\n    { &quot;CAP_SQUARE&quot;, &quot;CAP_BUTT&quot;, &quot;CAP_ROUND&quot; };\n  private int[] joins =\n    { BasicStroke.JOIN_MITER, BasicStroke.JOIN_BEVEL,\n      BasicStroke.JOIN_ROUND };\n  private String[] joinNames =\n    { &quot;JOIN_MITER&quot;, &quot;JOIN_BEVEL&quot;, &quot;JOIN_ROUND&quot; };\n\n  public LineStyles() {\n    path = new GeneralPath();\n    path.moveTo(x, y);\n    p1Large = new Circle(x, y, thickness\/2);\n    p1Small = new Circle(x, y, 2);\n    path.lineTo(x + deltaX, y - deltaY);\n    p2Large = new Circle(x + deltaX, y - deltaY, thickness\/2);\n    p2Small = new Circle(x + deltaX, y - deltaY, 2);\n    path.lineTo(x + 2*deltaX, y);\n    p3Large = new Circle(x + 2*deltaX, y, thickness\/2);\n    p3Small = new Circle(x + 2*deltaX, y, 2);\n    setFont(new Font(&quot;SansSerif&quot;, Font.BOLD, 20));\n  }\n\n  public void paintComponent(Graphics g) {\n    super.paintComponent(g);\n    Graphics2D g2d = (Graphics2D)g;\n    g2d.setColor(Color.lightGray);\n    for(int i=0; i&lt;caps .length; i++) {\n      BasicStroke stroke =\n        new BasicStroke(thickness, caps[i], joins[i]);\n      g2d.setStroke(stroke);\n      g2d.draw(path);\n      labelEndPoints(g2d, capNames[i], joinNames[i]);\n      g2d.translate(3*x + 2*deltaX, 0);\n    }\n  }\n\n  \/\/ Draw translucent circles to illustrate actual end points.\n  \/\/ Include text labels for cap\/join style.\n  private void labelEndPoints(Graphics2D g2d, String capLabel,\n                              String joinLabel) {\n    Paint origPaint = g2d.getPaint();\n    Composite origComposite = g2d.getComposite();\n    g2d.setPaint(Color.black);\n    g2d.setComposite(transparentComposite);\n    g2d.fill(p1Large);\n    g2d.fill(p2Large);\n    g2d.fill(p3Large);\n    g2d.setPaint(Color.yellow);\n    g2d.setComposite(origComposite);\n    g2d.fill(p1Small);\n    g2d.fill(p2Small);\n    g2d.fill(p3Small);\n    g2d.setPaint(Color.black);\n    g2d.drawString(capLabel, x + thickness - 5, y + 5);\n    g2d.drawString(joinLabel, x + deltaX + thickness - 5,\n                   y - deltaY);\n    g2d.setPaint(origPaint);\n  }\n\n  public static void main(String[] args) {\n    WindowUtilities.openInJFrame(new LineStyles(),\n                                 9*x + 6*deltaX, y + 60);\n  }\n}\n\nclass Circle extends Ellipse2D.Double {\n  public Circle(double centerX, double centerY, double radius) {\n    super(centerX - radius, centerY - radius, 2.0*radius,\n          2.0*radius);\n  }\n}\n<\/pre>\n<p>Note: Brought from our old site: http:\/\/www.salearningschool.com\/example_codes\/ on Jan 2nd, 2017 From: http:\/\/sitestree.com\/?p=10379<br \/> Categories:Programming Code Examples, Java\/J2EE\/J2ME, Drawing<br \/>Tags:Java\/J2EE\/J2MEDrawing<br \/> Post Data:2017-01-02 16:04:39<\/p>\n<p>\t\tShop Online: <a href='https:\/\/www.ShopForSoul.com\/' target='new' rel=\"noopener\">https:\/\/www.ShopForSoul.com\/<\/a><br \/>\n\t\t(Big Data, Cloud, Security, Machine Learning): Courses: <a href='http:\/\/Training.SitesTree.com' target='new' rel=\"noopener\"> http:\/\/Training.SitesTree.com<\/a><br \/>\n\t\tIn Bengali: <a href='http:\/\/Bangla.SaLearningSchool.com' target='new' rel=\"noopener\">http:\/\/Bangla.SaLearningSchool.com<\/a><br \/>\n\t\t<a href='http:\/\/SitesTree.com' target='new' rel=\"noopener\">http:\/\/SitesTree.com<\/a><br \/>\n\t\t8112223 Canada Inc.\/JustEtc: <a href='http:\/\/JustEtc.net' target='new' rel=\"noopener\">http:\/\/JustEtc.net (Software\/Web\/Mobile\/Big-Data\/Machine Learning) <\/a><br \/>\n\t\tShop Online: <a href='https:\/\/www.ShopForSoul.com'> https:\/\/www.ShopForSoul.com\/<\/a><br \/>\n\t\tMedium: <a href='https:\/\/medium.com\/@SayedAhmedCanada' target='new' rel=\"noopener\"> https:\/\/medium.com\/@SayedAhmedCanada <\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>import javax.swing.*; import java.awt.*; import java.awt.geom.*; \/** A demonstration of different controls when joining two line * segments. The style of the line end point is controlled * through the capStyle parameter. * ************************************ public class LineStyles extends JPanel { private GeneralPath path; private static int x = 30, deltaX = 150, y = 300, &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=26890\">Continue reading<\/a><\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1917],"tags":[],"class_list":["post-26890","post","type-post","status-publish","format-standard","hentry","category-fromsitestree-com","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":10413,"url":"http:\/\/bangla.sitestree.com\/?p=10413","url_meta":{"origin":26890,"position":0},"title":"LineStyles.java Provides examples of the available styles for joining line segments","author":"","date":"August 28, 2015","format":false,"excerpt":"import javax.swing.*; import java.awt.*; import java.awt.geom.*; \/** A demonstration of different controls when joining two line \u00a0*\u00a0 segments. The style of the line end point is controlled \u00a0*\u00a0 through the capStyle parameter. \u00a0* \u00a0************************************ public class LineStyles extends JPanel { \u00a0 private GeneralPath path; \u00a0 private static int x =\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26777,"url":"http:\/\/bangla.sitestree.com\/?p=26777","url_meta":{"origin":26890,"position":1},"title":"An applet that permits freehand drawing #Programming Code Examples #Java\/J2EE\/J2ME #Mouse and Keyboard Events","author":"Author-Check- Article-or-Video","date":"May 1, 2021","format":false,"excerpt":"import java.applet.Applet; import java.awt.*; import java.awt.event.*; \/** An applet that lets you perform freehand drawing. * **************** public class SimpleWhiteboard extends Applet { protected int lastX=0, lastY=0; public void init() { setBackground(Color.white); setForeground(Color.blue); addMouseListener(new PositionRecorder()); addMouseMotionListener(new LineDrawer()); } protected void record(int x, int y) { lastX = x; lastY =\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":27192,"url":"http:\/\/bangla.sitestree.com\/?p=27192","url_meta":{"origin":26890,"position":2},"title":"JTable Examples #Programming Code Examples #Java\/J2EE\/J2ME #Advanced Swing","author":"Author-Check- Article-or-Video","date":"May 13, 2021","format":false,"excerpt":"# JTableSimpleExample.java Simple table that takes column names and data from arrays of Strings. import java.awt.*; import javax.swing.*; \/** Simple JTable example that uses a String array for the * table header and table data. * *\/ public class JTableSimpleExample extends JFrame { public static void main(String[] args) { new\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10395,"url":"http:\/\/bangla.sitestree.com\/?p=10395","url_meta":{"origin":26890,"position":3},"title":"An applet that permits freehand drawing","author":"","date":"August 28, 2015","format":false,"excerpt":"import java.applet.Applet; import java.awt.*; import java.awt.event.*; \/** An applet that lets you perform freehand drawing. \u00a0* \u00a0 \u00a0**************** public class SimpleWhiteboard extends Applet { \u00a0 protected int lastX=0, lastY=0; \u00a0 public void init() { \u00a0\u00a0\u00a0 setBackground(Color.white); \u00a0\u00a0\u00a0 setForeground(Color.blue); \u00a0\u00a0\u00a0 addMouseListener(new PositionRecorder()); \u00a0\u00a0\u00a0 addMouseMotionListener(new LineDrawer()); \u00a0 } \u00a0 protected void record(int\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10269,"url":"http:\/\/bangla.sitestree.com\/?p=10269","url_meta":{"origin":26890,"position":4},"title":"JTable Examples","author":"","date":"August 26, 2015","format":false,"excerpt":"# JTableSimpleExample.java Simple table that takes column names and data from arrays of Strings. import java.awt.*; import javax.swing.*; \/** Simple JTable example that uses a String array for the \u00a0*\u00a0 table header and table data. \u00a0* \u00a0*\/ public class JTableSimpleExample extends JFrame { \u00a0 public static void main(String[] args) {\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26860,"url":"http:\/\/bangla.sitestree.com\/?p=26860","url_meta":{"origin":26890,"position":5},"title":"Multithreaded Graphics and Double Buffering #Programming Code Examples #Java\/J2EE\/J2ME #Java Threads","author":"Author-Check- Article-or-Video","date":"May 3, 2021","format":false,"excerpt":"ShipSimulation.java Illustrates the basic approach of multithreaded graphics whereas a thread adjusts parameters affecting the appearance of the graphics and then calls repaint to schedule an update of the display. import java.applet.Applet; import java.awt.*; public class ShipSimulation extends Applet implements Runnable { ... public void run() { Ship s; for(int\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/26890","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=26890"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/26890\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=26890"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=26890"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=26890"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}