{"id":27129,"date":"2021-05-11T23:10:05","date_gmt":"2021-05-12T03:10:05","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/iftag-java-ifconditiontag-java-ifthentag-java-and-ifelsetag-java-custom-tags-that-make-use-of-tag-nesting-programming-code-examples-java-j2ee-j2me-applets-and-basic-graphics\/"},"modified":"2021-05-11T23:10:05","modified_gmt":"2021-05-12T03:10:05","slug":"iftag-java-ifconditiontag-java-ifthentag-java-and-ifelsetag-java-custom-tags-that-make-use-of-tag-nesting-programming-code-examples-java-j2ee-j2me-applets-and-basic-graphics","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=27129","title":{"rendered":"IfTag.java, IfConditionTag.java, IfThenTag.java, and IfElseTag.java, Custom tags that make use of tag nesting #Programming Code Examples #Java\/J2EE\/J2ME #Applets and Basic Graphics"},"content":{"rendered":"<pre>\nIfTag.java, IfConditionTag.java, IfThenTag.java, and IfElseTag.java, Custom tags that make use of tag nesting\n\n\nIfTag.java\n\npackage cwp.tags;\n\nimport javax.servlet.jsp.*;\nimport javax.servlet.jsp.tagext.*;\nimport java.io.*;\nimport javax.servlet.*;\n\n\/** A tag that acts like an if\/then\/else.\n *  &lt;P&gt;\n *  Taken from Core Web Programming Java 2 Edition\n *  from Prentice Hall and Sun Microsystems Press,\n *  .\n *  May be freely used or adapted.\n *\/\n\npublic class IfTag extends TagSupport {\n  private boolean condition;\n  private boolean hasCondition = false;\n\n  public void setCondition(boolean condition) {\n    this.condition = condition;\n    hasCondition = true;\n  }\n\n  public boolean getCondition() {\n    return(condition);\n  }\n\n  public void setHasCondition(boolean flag) {\n    this.hasCondition = flag;\n  }\n\n  \/** Has the condition field been explicitly set? *\/\n\n  public boolean hasCondition() {\n    return(hasCondition);\n  }\n\n  public int doStartTag() {\n    return(EVAL_BODY_INCLUDE);\n  }\n}\n\n\npackage cwp.tags;\n\nimport javax.servlet.jsp.*;\nimport javax.servlet.jsp.tagext.*;\nimport java.io.*;\nimport javax.servlet.*;\n\n\/** The condition part of an if tag.\n *  &lt;P&gt;\n *  Taken from Core Web Programming Java 2 Edition\n *  from Prentice Hall and Sun Microsystems Press,\n *  .\n *  May be freely used or adapted.\n *\/\n\npublic class IfConditionTag extends BodyTagSupport {\n  public int doStartTag() throws JspTagException {\n    IfTag parent =\n      (IfTag)findAncestorWithClass(this, IfTag.class);\n    if (parent == null) {\n      throw new JspTagException(&quot;condition not inside if&quot;);\n    }\n    return(EVAL_BODY_TAG);\n  }\n\n  public int doAfterBody() {\n    IfTag parent =\n      (IfTag)findAncestorWithClass(this, IfTag.class);\n    String bodyString = getBodyContent().getString();\n    if (bodyString.trim().equals(&quot;true&quot;)) {\n      parent.setCondition(true);\n    } else {\n      parent.setCondition(false);\n    }\n    return(SKIP_BODY);\n  }\n}\n\npackage cwp.tags;\n\nimport javax.servlet.jsp.*;\nimport javax.servlet.jsp.tagext.*;\nimport java.io.*;\nimport javax.servlet.*;\n\n\/** The else part of an if tag.\n *  &lt;P&gt;\n *  Taken from Core Web Programming Java 2 Edition\n *  from Prentice Hall and Sun Microsystems Press,\n *  .\n *  May be freely used or adapted.\n *\/\n\npublic class IfElseTag extends BodyTagSupport {\n  public int doStartTag() throws JspTagException {\n    IfTag parent =\n      (IfTag)findAncestorWithClass(this, IfTag.class);\n    if (parent == null) {\n      throw new JspTagException(&quot;else not inside if&quot;);\n    } else if (!parent.hasCondition()) {\n      String warning =\n        &quot;condition tag must come before else tag&quot;;\n      throw new JspTagException(warning);\n    }\n    return(EVAL_BODY_TAG);\n  }\n\n  public int doAfterBody() {\n    IfTag parent =\n      (IfTag)findAncestorWithClass(this, IfTag.class);\n    if (!parent.getCondition()) {\n      try {\n        BodyContent body = getBodyContent();\n        JspWriter out = body.getEnclosingWriter();\n        out.print(body.getString());\n      } catch(IOException ioe) {\n        System.out.println(&quot;Error in IfElseTag: &quot; + ioe);\n      }\n    }\n    return(SKIP_BODY);\n  }\n}\n\npackage cwp.tags;\n\nimport javax.servlet.jsp.*;\nimport javax.servlet.jsp.tagext.*;\nimport java.io.*;\nimport javax.servlet.*;\n\n\/** The then part of an if tag.\n *  &lt;P&gt;\n *  Taken from Core Web Programming Java 2 Edition\n *  from Prentice Hall and Sun Microsystems Press,\n *  .\n *  May be freely used or adapted.\n *\/\n\npublic class IfThenTag extends BodyTagSupport {\n  public int doStartTag() throws JspTagException {\n    IfTag parent =\n      (IfTag)findAncestorWithClass(this, IfTag.class);\n    if (parent == null) {\n      throw new JspTagException(&quot;then not inside if&quot;);\n    } else if (!parent.hasCondition()) {\n      String warning =\n        &quot;condition tag must come before then tag&quot;;\n      throw new JspTagException(warning);\n    }\n    return(EVAL_BODY_TAG);\n  }\n\n  public int doAfterBody() {\n    IfTag parent =\n      (IfTag)findAncestorWithClass(this, IfTag.class);\n    if (parent.getCondition()) {\n      try {\n        BodyContent body = getBodyContent();\n        JspWriter out = body.getEnclosingWriter();\n        out.print(body.getString());\n      } catch(IOException ioe) {\n        System.out.println(&quot;Error in IfThenTag: &quot; + ioe);\n      }\n    }\n    return(SKIP_BODY);\n  }\n}\n\n\n\n\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=10286<br \/> Categories:Programming Code Examples, Java\/J2EE\/J2ME, Applets and Basic Graphics<br \/>Tags:Java\/J2EE\/J2MEApplets and Basic Graphics<br \/> Post Data:2017-01-02 16:04:31<\/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>IfTag.java, IfConditionTag.java, IfThenTag.java, and IfElseTag.java, Custom tags that make use of tag nesting IfTag.java package cwp.tags; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import java.io.*; import javax.servlet.*; \/** A tag that acts like an if\/then\/else. * &lt;P&gt; * Taken from Core Web Programming Java 2 Edition * from Prentice Hall and Sun Microsystems Press, * . * May &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=27129\">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-27129","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":10473,"url":"http:\/\/bangla.sitestree.com\/?p=10473","url_meta":{"origin":27129,"position":0},"title":"IfTag.java, IfConditionTag.java, IfThenTag.java, and IfElseTag.java, Custom tags that make use of tag nesting","author":"","date":"August 28, 2015","format":false,"excerpt":"IfTag.java, IfConditionTag.java, IfThenTag.java, and IfElseTag.java, Custom tags that make use of tag nesting IfTag.java package cwp.tags; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import java.io.*; import javax.servlet.*; \/** A tag that acts like an if\/then\/else. \u00a0*\u00a0 <P> \u00a0*\u00a0 Taken from Core Web Programming Java 2 Edition \u00a0*\u00a0 from Prentice Hall and Sun Microsystems\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":27192,"url":"http:\/\/bangla.sitestree.com\/?p=27192","url_meta":{"origin":27129,"position":1},"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":27152,"url":"http:\/\/bangla.sitestree.com\/?p=27152","url_meta":{"origin":27129,"position":2},"title":"Loading Images #Programming Code Examples #Java\/J2EE\/J2ME #Applets and Basic Graphics","author":"Author-Check- Article-or-Video","date":"May 12, 2021","format":false,"excerpt":"JavaMan1.java Applet that loads an image from a relative URL. ************************************************************* import java.applet.Applet; import java.awt.*; \/** An applet that loads an image from a relative URL. * >>>>>>>>>>>>>>>>>>> public class JavaMan1 extends Applet { private Image javaMan; public void init() { javaMan = getImage(getCodeBase(),\"images\/Java-Man.gif\"); } public void paint(Graphics g) {\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":10487,"url":"http:\/\/bangla.sitestree.com\/?p=10487","url_meta":{"origin":27129,"position":3},"title":"Loading Images","author":"","date":"August 29, 2015","format":false,"excerpt":"JavaMan1.java Applet that loads an image from a relative URL. ************************************************************* import java.applet.Applet; import java.awt.*; \/** An applet that loads an image from a relative URL. \u00a0* >>>>>>>>>>>>>>>>>>> public class JavaMan1 extends Applet { \u00a0 private Image javaMan; \u00a0 public void init() { \u00a0\u00a0\u00a0 javaMan = getImage(getCodeBase(),\"images\/Java-Man.gif\"); \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":[]},{"id":26856,"url":"http:\/\/bangla.sitestree.com\/?p=26856","url_meta":{"origin":27129,"position":4},"title":"DOM example that represents the basic structure of an XML document as a JTree #Programming Code Examples #Java\/J2EE\/J2ME #JavaScript","author":"Author-Check- Article-or-Video","date":"May 3, 2021","format":false,"excerpt":"\/\/XMLTree.java \/\/Uses the following files Uses the following files: * XMLFrame.java:Swing application to select an XML document and display in a JTree. ExtensionFileFilter.java Allows you to specify which file extensions will be displayed in a JFileChooser. test.xml Default file loaded if none selected by user. perennials.xml and perennials.dtd Data on\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":10425,"url":"http:\/\/bangla.sitestree.com\/?p=10425","url_meta":{"origin":27129,"position":5},"title":"The class that actually gets the strings over the network by means of an ObjectInputStream via HTTP tunneling.","author":"","date":"August 28, 2015","format":false,"excerpt":"import java.net.*; import java.io.*; \/** When this class is built, it returns a value \u00a0*\u00a0 immediately, but this value returns false for isDone \u00a0*\u00a0 and null for getQueries. Meanwhile, it starts a Thread \u00a0*\u00a0 to request an array of query strings from the server, \u00a0*\u00a0 reading them in one fell\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\/27129","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=27129"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/27129\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=27129"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=27129"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=27129"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}