{"id":26882,"date":"2021-05-04T23:10:05","date_gmt":"2021-05-05T03:10:05","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/illustrates-the-effect-of-different-transparency-programming-code-examples-java-j2ee-j2me-drawing\/"},"modified":"2021-05-04T23:10:05","modified_gmt":"2021-05-05T03:10:05","slug":"illustrates-the-effect-of-different-transparency-programming-code-examples-java-j2ee-j2me-drawing","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=26882","title":{"rendered":"Illustrates the effect of different transparency #Programming Code Examples #Java\/J2EE\/J2ME #Drawing"},"content":{"rendered":"<pre>\n~~~~~~~~~~~~~~~~~~~\nTransparencyExample.java Illustrates the effect of different transparency (alpha) values when drawing a shape.\n~~~~~~~~~~~~~~~~~~~\nimport javax.swing.*;\nimport java.awt.*;\nimport java.awt.geom.*;\n\n\/** An illustration of the use of AlphaComposite to make\n *  partially transparent drawings.\n *\n **********************************\n\npublic class TransparencyExample extends JPanel {\n  private static int gap=10, width=60, offset=20,\n                     deltaX=gap+width+offset;\n  private Rectangle\n    blueSquare = new Rectangle(gap+offset, gap+offset, width,\n                               width),\n    redSquare = new Rectangle(gap, gap, width, width);\n\n  private AlphaComposite makeComposite(float alpha) {\n    int type = AlphaComposite.SRC_OVER;\n    return(AlphaComposite.getInstance(type, alpha));\n  }\n\n  private void drawSquares(Graphics2D g2d, float alpha) {\n    Composite originalComposite = g2d.getComposite();\n    g2d.setPaint(Color.blue);\n    g2d.fill(blueSquare);\n    g2d.setComposite(makeComposite(alpha));\n    g2d.setPaint(Color.red);\n    g2d.fill(redSquare);\n    g2d.setComposite(originalComposite);\n  }\n\n  public void paintComponent(Graphics g) {\n    super.paintComponent(g);\n    Graphics2D g2d = (Graphics2D)g;\n    for(int i=0; i&lt;11; i++) {\n      drawSquares(g2d, i*0.1F);\n      g2d.translate(deltaX, 0);\n    }\n  }\n\n  public static void main(String[] args) {\n    String title = &quot;Transparency example: alpha of the top &quot; +\n                   &quot;(red) square ranges from 0.0 at the left &quot; +\n                   &quot;to 1.0 at the right. Bottom (blue) square &quot; + \n                   &quot;is opaque.&quot;;\n    WindowUtilities.openInJFrame(new TransparencyExample(),\n                                 11*deltaX + 2*gap,\n                                 deltaX + 3*gap,\n                                 title, Color.lightGray);\n  }\n}\n&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;\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=10374<br \/> Categories:Programming Code Examples, Java\/J2EE\/J2ME, Drawing<br \/>Tags:Java\/J2EE\/J2MEDrawing<br \/> Post Data:2017-01-02 16:04:35<\/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>~~~~~~~~~~~~~~~~~~~ TransparencyExample.java Illustrates the effect of different transparency (alpha) values when drawing a shape. ~~~~~~~~~~~~~~~~~~~ import javax.swing.*; import java.awt.*; import java.awt.geom.*; \/** An illustration of the use of AlphaComposite to make * partially transparent drawings. * ********************************** public class TransparencyExample extends JPanel { private static int gap=10, width=60, offset=20, deltaX=gap+width+offset; private Rectangle blueSquare = new &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=26882\">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-26882","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":10404,"url":"http:\/\/bangla.sitestree.com\/?p=10404","url_meta":{"origin":26882,"position":0},"title":"Illustrates the effect of different transparency","author":"","date":"August 28, 2015","format":false,"excerpt":"~~~~~~~~~~~~~~~~~~~ TransparencyExample.java Illustrates the effect of different transparency (alpha) values when drawing a shape. ~~~~~~~~~~~~~~~~~~~ import javax.swing.*; import java.awt.*; import java.awt.geom.*; \/** An illustration of the use of AlphaComposite to make \u00a0*\u00a0 partially transparent drawings. \u00a0* \u00a0********************************** public class TransparencyExample extends JPanel { \u00a0 private static int gap=10, width=60, offset=20,\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":10417,"url":"http:\/\/bangla.sitestree.com\/?p=10417","url_meta":{"origin":26882,"position":1},"title":"ShearExample.java. Illustrates the effect of applying a shear transformation prior to drawing a square","author":"","date":"August 28, 2015","format":false,"excerpt":"import javax.swing.*; import java.awt.*; import java.awt.geom.*; \/** An example of shear transformations on a rectangle. \u00a0* \u00a0*********************** public class ShearExample extends JPanel { \u00a0 private static int gap=10, width=100; \u00a0 private Rectangle rect = new Rectangle(gap, gap, 100, 100); \u00a0 public void paintComponent(Graphics g) { \u00a0\u00a0\u00a0 super.paintComponent(g); \u00a0\u00a0\u00a0 Graphics2D g2d\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":26894,"url":"http:\/\/bangla.sitestree.com\/?p=26894","url_meta":{"origin":26882,"position":2},"title":"ShearExample.java. Illustrates the effect of applying a shear transformation prior to drawing a square #Programming Code Examples #Java\/J2EE\/J2ME #Drawing","author":"Author-Check- Article-or-Video","date":"May 4, 2021","format":false,"excerpt":"import javax.swing.*; import java.awt.*; import java.awt.geom.*; \/** An example of shear transformations on a rectangle. * *********************** public class ShearExample extends JPanel { private static int gap=10, width=100; private Rectangle rect = new Rectangle(gap, gap, 100, 100); public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D)g; for (int i=0;\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":26860,"url":"http:\/\/bangla.sitestree.com\/?p=26860","url_meta":{"origin":26882,"position":3},"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":[]},{"id":10329,"url":"http:\/\/bangla.sitestree.com\/?p=10329","url_meta":{"origin":26882,"position":4},"title":"Position circles down the diagonal so that their borders","author":"","date":"August 26, 2015","format":false,"excerpt":"import java.awt.*; import java.applet.Applet; \/** Position circles down the diagonal so that their borders \u00a0*\u00a0 just touch. Illustrates that AWT components are \u00a0*\u00a0 rectangular and opaque. \u00a0 *\/ public class CircleTest2 extends Applet { \u00a0 public void init() { \u00a0\u00a0\u00a0 setBackground(Color.lightGray); \u00a0\u00a0\u00a0 setLayout(null); \/\/ Turn off layout manager. \u00a0\u00a0\u00a0 Circle\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":10279,"url":"http:\/\/bangla.sitestree.com\/?p=10279","url_meta":{"origin":26882,"position":5},"title":"BetterCircleTest.java","author":"","date":"August 26, 2015","format":false,"excerpt":"********************** BetterCircleTest.java ********************** import java.awt.*; import java.applet.Applet; \/** Position circles down the diagonal so that their borders \u00a0*\u00a0 just touch. Illustrates that Java 1.1 lightweight \u00a0*\u00a0 components can be partially transparent. \u00a0* \u00a0 *\/ public class BetterCircleTest extends Applet { \u00a0 public void init() { \u00a0\u00a0\u00a0 setBackground(Color.lightGray); \u00a0\u00a0\u00a0 setLayout(null); \u00a0\u00a0\u00a0\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":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/26882","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=26882"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/26882\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=26882"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=26882"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=26882"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}