{"id":26880,"date":"2021-05-04T23:10:04","date_gmt":"2021-05-05T03:10:04","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/demonstrates-using-a-texturepaint-to-fill-an-shape-with-a-tiled-image-programming-code-examples-java-j2ee-j2me-drawing\/"},"modified":"2021-05-04T23:10:04","modified_gmt":"2021-05-05T03:10:04","slug":"demonstrates-using-a-texturepaint-to-fill-an-shape-with-a-tiled-image-programming-code-examples-java-j2ee-j2me-drawing","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=26880","title":{"rendered":"Demonstrates using a TexturePaint to fill an shape with a tiled image #Programming Code Examples #Java\/J2EE\/J2ME #Drawing"},"content":{"rendered":"<pre>\n^^^^^^^^^^^^^^^^^\nTiledImages.java Demonstrates using a TexturePaint to fill an shape with a tiled image. Uses the following class and images:\n\n    * ImageUtilities.java Simplifies creating a BufferedImage from an image file. \n~~~~~~~~~~~~~~~~~~\nimport javax.swing.*;\nimport java.awt.*;\nimport java.awt.geom.*;\nimport java.awt.image.*;\n\n\/** An example of using TexturePaint to fill objects with tiled\n *  images. Uses the getBufferedImage method of ImageUtilities \n *  to load an Image from a file and turn that into a \n *  BufferedImage.\n *\n ****************\n\npublic class TiledImages extends JPanel {\n  private String dir = System.getProperty(&quot;user.dir&quot;);\n  private String imageFile1 = dir + &quot;\/images\/marty.jpg&quot;;\n  private TexturePaint imagePaint1;\n  private Rectangle imageRect;\n  private String imageFile2 = dir + &quot;\/images\/bluedrop.gif&quot;;\n  private TexturePaint imagePaint2;\n  private int[] xPoints = { 30, 700, 400 };\n  private int[] yPoints = { 30, 30, 600 };\n  private Polygon imageTriangle =\n                    new Polygon(xPoints, yPoints, 3);\n  public TiledImages() {\n    BufferedImage image =\n      ImageUtilities.getBufferedImage(imageFile1, this);\n    imageRect = new Rectangle(235, 70, image.getWidth(),\n                              image.getHeight());\n    imagePaint1 = new TexturePaint(image, imageRect);\n    image = ImageUtilities.getBufferedImage(imageFile2, this);\n    imagePaint2 =\n      new TexturePaint(image, new Rectangle(0, 0, 32, 32));\n  }\n\n  public void paintComponent(Graphics g) {\n    super.paintComponent(g);\n    Graphics2D g2d = (Graphics2D)g;\n    g2d.setPaint(imagePaint2);\n    g2d.fill(imageTriangle);\n    g2d.setPaint(Color.blue);\n    g2d.setStroke(new BasicStroke(5));\n    g2d.draw(imageTriangle);\n    g2d.setPaint(imagePaint1);\n    g2d.fill(imageRect);\n    g2d.setPaint(Color.black);\n    g2d.draw(imageRect);\n  }\n\n  public static void main(String[] args) {\n    WindowUtilities.openInJFrame(new TiledImages(), 750, 650);\n  }\n}\n&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;\nImageUtilities.java Simplifies creating a BufferedImage from an image file.\n&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;\nimport java.awt.*;\nimport java.awt.image.*;\n\n\/** A class that simplifies a few common image operations, in\n *  particular, creating a BufferedImage from an image file and\n *  using MediaTracker to wait until an image or several images\n *  are done loading.\n *\n ********************\n\npublic class ImageUtilities {\n  \n  \/** Create Image from a file, then turn that into a\n   *  BufferedImage.\n   *\/\n\n  public static BufferedImage getBufferedImage(String imageFile,\n                                               Component c) {\n    Image image = c.getToolkit().getImage(imageFile);\n    waitForImage(image, c);\n\n    BufferedImage bufferedImage =\n      new BufferedImage(image.getWidth(c), image.getHeight(c),\n                        BufferedImage.TYPE_INT_RGB);\n    Graphics2D g2d = bufferedImage.createGraphics();\n    g2d.drawImage(image, 0, 0, c);\n    return(bufferedImage);\n  }\n\n  \/** Take an Image associated with a file, and wait until it is\n   *  done loading (just a simple application of MediaTracker).\n   *  If you are loading multiple images, don't use this\n   *  consecutive times; instead, use the version that takes\n   *  an array of images.\n   *\/\n\n  public static boolean waitForImage(Image image, Component c) {\n    MediaTracker tracker = new MediaTracker(c);\n    tracker.addImage(image, 0);\n    try {\n      tracker.waitForAll();\n    } catch(InterruptedException ie) {}\n    return(!tracker.isErrorAny());\n  }\n\n  \/** Take some Images associated with files, and wait until they\n   *  are done loading (just a simple application of\n   *  MediaTracker).\n   *\/\n\n  public static boolean waitForImages(Image[] images, Component c)   {\n    MediaTracker tracker = new MediaTracker(c);\n    for(int i=0; i&lt;images .length; i++)\n      tracker.addImage(images[i], 0);\n    try {\n      tracker.waitForAll();\n    } catch(InterruptedException ie) {}\n    return(!tracker.isErrorAny());\n  }\n}\n&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;\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=10373<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>^^^^^^^^^^^^^^^^^ TiledImages.java Demonstrates using a TexturePaint to fill an shape with a tiled image. Uses the following class and images: * ImageUtilities.java Simplifies creating a BufferedImage from an image file. ~~~~~~~~~~~~~~~~~~ import javax.swing.*; import java.awt.*; import java.awt.geom.*; import java.awt.image.*; \/** An example of using TexturePaint to fill objects with tiled * images. Uses the getBufferedImage &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=26880\">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-26880","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":10402,"url":"http:\/\/bangla.sitestree.com\/?p=10402","url_meta":{"origin":26880,"position":0},"title":"Demonstrates using a TexturePaint to fill an shape with a tiled image","author":"","date":"August 28, 2015","format":false,"excerpt":"^^^^^^^^^^^^^^^^^ TiledImages.java Demonstrates using a TexturePaint to fill an shape with a tiled image. Uses the following class and images: \u00a0\u00a0\u00a0 * ImageUtilities.java Simplifies creating a BufferedImage from an image file. ~~~~~~~~~~~~~~~~~~ import javax.swing.*; import java.awt.*; import java.awt.geom.*; import java.awt.image.*; \/** An example of using TexturePaint to fill objects with\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":10142,"url":"http:\/\/bangla.sitestree.com\/?p=10142","url_meta":{"origin":26880,"position":1},"title":"ImportAttribute.jsp Page that demonstrates the import attribute of the page directive. Uses the ServletUtilities class","author":"","date":"August 9, 2015","format":false,"excerpt":"ImportAttribute.jsp\u00a0 Page that demonstrates the import attribute of the page directive. Uses the ServletUtilities class (Check Servlet Section) <!DOCTYPE HTML PUBLIC \"-\/\/W3C\/\/DTD HTML 4.0 Transitional\/\/EN\"> <!-- Example of the import attribute of the page directive. Taken from Core Web Programming Java 2 Edition from Prentice Hall and Sun Microsystems Press,\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":26814,"url":"http:\/\/bangla.sitestree.com\/?p=26814","url_meta":{"origin":26880,"position":2},"title":"ImportAttribute.jsp  Page that demonstrates the import attribute of the page directive. Uses the ServletUtilities class #Programming Code Examples #Java\/J2EE\/J2ME #JSP","author":"Author-Check- Article-or-Video","date":"May 2, 2021","format":false,"excerpt":"ImportAttribute.jsp Page that demonstrates the import attribute of the page directive. Uses the ServletUtilities class (Check Servlet Section) <!DOCTYPE HTML PUBLIC \"-\/\/W3C\/\/DTD HTML 4.0 Transitional\/\/EN\"> <!-- Example of the import attribute of the page directive. Taken from Core Web Programming Java 2 Edition from Prentice Hall and Sun Microsystems Press,\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":10343,"url":"http:\/\/bangla.sitestree.com\/?p=10343","url_meta":{"origin":26880,"position":3},"title":"Uses a FileDialog to choose the file to display","author":"","date":"August 27, 2015","format":false,"excerpt":"DisplayFile.java **************** import java.awt.*; import java.awt.event.*; import java.io.*; \/** Uses a FileDialog to choose the file to display. \u00a0*************** \u00a0 public class DisplayFile extends CloseableFrame \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 implements ActionListener { \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0 \u00a0 public static void main(String[] args) { \u00a0\u00a0\u00a0 new DisplayFile(); \u00a0 } \u00a0 private Button loadButton; \u00a0 private TextArea\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":10146,"url":"http:\/\/bangla.sitestree.com\/?p=10146","url_meta":{"origin":26880,"position":4},"title":"PluginApplet.jsp Page that demonstrates the use of jsp:plugin.","author":"","date":"August 12, 2015","format":false,"excerpt":"PluginApplet.jsp\u00a0 Page that demonstrates the use of jsp:plugin. Requires you to compile and install PluginApplet.java, TextPanel.java, DrawingPanel.java, and WindowUtilities.java\u00a0 Since these are classes sent to the client to used by applets, the .class files should be in the same directory as the JSP page, not in the WEB-INF\/classes directory where\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":10160,"url":"http:\/\/bangla.sitestree.com\/?p=10160","url_meta":{"origin":26880,"position":5},"title":"ShowMessage.java Servlet that demonstrates the use of initialization parameters.","author":"","date":"August 16, 2015","format":false,"excerpt":"ShowMessage.java\u00a0 Servlet that demonstrates the use of initialization parameters. Remember that, to use this servlet, you have to do three things: \u00a0\u00a0\u00a0 * Put the modified web.xml file in the WEB-INF directory. \u00a0\u00a0\u00a0 * Restart the server. \u00a0\u00a0\u00a0 * Use the registered servlet name (i.e., the URL http:\/\/host\/servlet\/ShowMsg), not the\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\/26880","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=26880"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/26880\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=26880"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=26880"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=26880"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}