{"id":27022,"date":"2021-05-08T23:10:06","date_gmt":"2021-05-09T03:10:06","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/handling-events-programming-code-examples-java-j2ee-j2me-awt-components\/"},"modified":"2021-05-08T23:10:06","modified_gmt":"2021-05-09T03:10:06","slug":"handling-events-programming-code-examples-java-j2ee-j2me-awt-components","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=27022","title":{"rendered":"Handling Events #Programming Code Examples #Java\/J2EE\/J2ME #AWT Components"},"content":{"rendered":"<pre>\n***********************************    \n* ActionExample1.java Inherits from CloseableFrame.java and uses SetSizeButton.java.\n    * ActionExample2.java Inherits from CloseableFrame.java.\n    **********************************************************\nActionExample1.java\n*******************\nimport java.awt.*;\n\npublic class ActionExample1 extends CloseableFrame {\n  public static void main(String[] args) {\n    new ActionExample1();\n  }\n\n  public ActionExample1() {\n    super(&quot;Handling Events in Component&quot;);\n    setLayout(new FlowLayout());\n    setFont(new Font(&quot;Serif&quot;, Font.BOLD, 18));\n    add(new SetSizeButton(300, 200));\n    add(new SetSizeButton(400, 300));\n    add(new SetSizeButton(500, 400));\n    setSize(400, 300);\n    setVisible(true);\n  }\n}\n********************\nCloseableFrame.java \n********************\nimport java.awt.*;\nimport java.awt.event.*;\n\n\/** A Frame that you can actually quit. Used as the starting \n *  point for most Java 1.1 graphical applications.\n ***********************\n\npublic class CloseableFrame extends Frame {\n  public CloseableFrame(String title) {\n    super(title);\n    enableEvents(AWTEvent.WINDOW_EVENT_MASK);\n  }\n\n  \/** Since we are doing something permanent, we need\n   *  to call super.processWindowEvent <b>first<\/b>.\n   *\/\n  \n  public void processWindowEvent(WindowEvent event) {\n    super.processWindowEvent(event); \/\/ Handle listeners.\n    if (event.getID() == WindowEvent.WINDOW_CLOSING) {\n      \/\/ If the frame is used in an applet, use dispose().\n      System.exit(0);\n    }\n  }\n}\n**********************\nSetSizeButton.java\n**********************\nimport java.awt.*;\nimport java.awt.event.*;\n\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\npublic class SetSizeButton extends Button \n                           implements ActionListener {\n  private int width, height;\n\n  public SetSizeButton(int width, int height) {\n    super(&quot;Resize to &quot; + width + &quot;x&quot; + height);\n    this.width = width;\n    this.height = height;\n    addActionListener(this);\n  }\n\n  public void actionPerformed(ActionEvent event) {\n    getParent().setSize(width, height);\n    getParent().invalidate();\n    getParent().validate();\n  }\n}\n***********************\nActionExample2.java\n***********************\nimport java.awt.*;\nimport java.awt.event.*;\n\n\/***********\/\npublic class ActionExample2 extends CloseableFrame\n                            implements ActionListener {\n  public static void main(String[] args) {\n    new ActionExample2();\n  }\n\n  private Button button1, button2, button3;\n\n  public ActionExample2() {\n    super(&quot;Handling Events in Other Object&quot;);\n    setLayout(new FlowLayout());\n    setFont(new Font(&quot;Serif&quot;, Font.BOLD, 18));\n    button1 = new Button(&quot;Resize to 300x200&quot;);\n    button2 = new Button(&quot;Resize to 400x300&quot;);\n    button3 = new Button(&quot;Resize to 500x400&quot;);\n    button1.addActionListener(this);\n    button2.addActionListener(this);\n    button3.addActionListener(this);\n    add(button1);\n    add(button2);\n    add(button3);\n    setSize(400, 300);\n    setVisible(true);\n  }\n\n  public void actionPerformed(ActionEvent event) {\n    if (event.getSource() == button1) {\n      updateLayout(300, 200);\n    } else if (event.getSource() == button2) {\n      updateLayout(400, 300);\n    } else if (event.getSource() == button3) {\n      updateLayout(500, 400);\n    }\n  }\n  \n  private void updateLayout(int width, int height) {\n    setSize(width, height);\n    invalidate();\n    validate();\n  }\n}\n****************\/&gt;\nCloseableFrame.java.\n****************\/&gt;&lt; import java.awt.*;\nimport java.awt.event.*;\n\n\/** A Frame that you can actually quit. Used as the starting \n *  point for most Java 1.1 graphical applications.\n *\n *********************\n\npublic class CloseableFrame extends Frame {\n  public CloseableFrame(String title) {\n    super(title);\n    enableEvents(AWTEvent.WINDOW_EVENT_MASK);\n  }\n\n  \/** Since we are doing something permanent, we need\n   *  to call super.processWindowEvent <b>first.\n   *\/\n  \n  public void processWindowEvent(WindowEvent event) {\n    super.processWindowEvent(event); \/\/ Handle listeners.\n    if (event.getID() == WindowEvent.WINDOW_CLOSING) {\n      \/\/ If the frame is used in an applet, use dispose().\n      System.exit(0);\n    }\n  }\n}\n***************\n<\/b><\/pre>\n<p>Note: Brought from our old site: http:\/\/www.salearningschool.com\/example_codes\/ on Jan 2nd, 2017 From: http:\/\/sitestree.com\/?p=10332<br \/> Categories:Programming Code Examples, Java\/J2EE\/J2ME, AWT Components<br \/>Tags:Java\/J2EE\/J2MEAWT Components<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>*********************************** * ActionExample1.java Inherits from CloseableFrame.java and uses SetSizeButton.java. * ActionExample2.java Inherits from CloseableFrame.java. ********************************************************** ActionExample1.java ******************* import java.awt.*; public class ActionExample1 extends CloseableFrame { public static void main(String[] args) { new ActionExample1(); } public ActionExample1() { super(&quot;Handling Events in Component&quot;); setLayout(new FlowLayout()); setFont(new Font(&quot;Serif&quot;, Font.BOLD, 18)); add(new SetSizeButton(300, 200)); add(new SetSizeButton(400, 300)); add(new SetSizeButton(500, &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=27022\">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-27022","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":10345,"url":"http:\/\/bangla.sitestree.com\/?p=10345","url_meta":{"origin":27022,"position":0},"title":"Handling Events","author":"","date":"August 27, 2015","format":false,"excerpt":"***********************************\u00a0\u00a0 \u00a0 * ActionExample1.java Inherits from CloseableFrame.java and uses SetSizeButton.java. \u00a0\u00a0\u00a0 * ActionExample2.java Inherits from CloseableFrame.java. \u00a0\u00a0\u00a0 ********************************************************** ActionExample1.java ******************* import java.awt.*; public class ActionExample1 extends CloseableFrame { \u00a0 public static void main(String[] args) { \u00a0\u00a0\u00a0 new ActionExample1(); \u00a0 } \u00a0 public ActionExample1() { \u00a0\u00a0\u00a0 super(\"Handling Events in Component\"); \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":[]},{"id":10363,"url":"http:\/\/bangla.sitestree.com\/?p=10363","url_meta":{"origin":27022,"position":1},"title":"ReverseLabels.java Inherits from CloseableFrame.java and uses ReversibleLabel.java.","author":"","date":"August 27, 2015","format":false,"excerpt":"ReverseLabels.java Inherits from CloseableFrame.java and uses ReversibleLabel.java. ********************** ReverseLabels.java ********************** import java.awt.*; ****************** public class ReverseLabels extends CloseableFrame { \u00a0 public static void main(String[] args) { \u00a0\u00a0\u00a0 new ReverseLabels(); \u00a0 } \u00a0 public ReverseLabels() { \u00a0\u00a0\u00a0 super(\"Reversible Labels\"); \u00a0\u00a0\u00a0 setLayout(new FlowLayout()); \u00a0\u00a0\u00a0 setBackground(Color.lightGray); \u00a0\u00a0\u00a0 setFont(new Font(\"Serif\", Font.BOLD, 18)); \u00a0\u00a0\u00a0 ReversibleLabel\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":27050,"url":"http:\/\/bangla.sitestree.com\/?p=27050","url_meta":{"origin":27022,"position":2},"title":"ReverseLabels.java Inherits from CloseableFrame.java and uses ReversibleLabel.java. #Programming Code Examples #Java\/J2EE\/J2ME #AWT Components","author":"Author-Check- Article-or-Video","date":"May 9, 2021","format":false,"excerpt":"ReverseLabels.java Inherits from CloseableFrame.java and uses ReversibleLabel.java. ********************** ReverseLabels.java ********************** import java.awt.*; ****************** public class ReverseLabels extends CloseableFrame { public static void main(String[] args) { new ReverseLabels(); } public ReverseLabels() { super(\"Reversible Labels\"); setLayout(new FlowLayout()); setBackground(Color.lightGray); setFont(new Font(\"Serif\", Font.BOLD, 18)); ReversibleLabel label1 = new ReversibleLabel(\"Black on White\", Color.white, Color.black); add(label1);\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":10357,"url":"http:\/\/bangla.sitestree.com\/?p=10357","url_meta":{"origin":27022,"position":3},"title":"Lists.java","author":"","date":"August 27, 2015","format":false,"excerpt":"Lists.java Inherits from CloseableFrame.java. \/.\/.\/.\/.\/.\/.\/.\/.\/.\/ import java.awt.*; \/*****************\/ public class Lists extends CloseableFrame { \u00a0 public static void main(String[] args) { \u00a0\u00a0\u00a0 new Lists(); \u00a0 } \u00a0 public Lists() { \u00a0\u00a0\u00a0 super(\"Lists\"); \u00a0\u00a0\u00a0 setLayout(new FlowLayout()); \u00a0\u00a0\u00a0 setBackground(Color.lightGray); \u00a0\u00a0\u00a0 setFont(new Font(\"SansSerif\", Font.BOLD, 18)); \u00a0\u00a0\u00a0 List list1 = new List(3, false); \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":[]},{"id":10286,"url":"http:\/\/bangla.sitestree.com\/?p=10286","url_meta":{"origin":27022,"position":4},"title":"Checkboxes","author":"","date":"August 26, 2015","format":false,"excerpt":"Checkboxes.java Inherits from CloseableFrame.java. ****************** import java.awt.*; \/.\/.\/.\/.\/.\/.\/.\/.\/.\/ public class Checkboxes extends CloseableFrame { \u00a0 public static void main(String[] args) { \u00a0\u00a0\u00a0 new Checkboxes(); \u00a0 } \u00a0 public Checkboxes() { \u00a0\u00a0\u00a0 super(\"Checkboxes\"); \u00a0\u00a0\u00a0 setFont(new Font(\"SansSerif\", Font.BOLD, 18)); \u00a0\u00a0\u00a0 setLayout(new GridLayout(0, 2)); \u00a0\u00a0\u00a0 Checkbox box; \u00a0\u00a0\u00a0 for(int i=0; i<12; i++) {\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":10349,"url":"http:\/\/bangla.sitestree.com\/?p=10349","url_meta":{"origin":27022,"position":5},"title":"ButtonExample.java Uses the following","author":"","date":"August 27, 2015","format":false,"excerpt":"\/.\/.\/.\/.\/.\/.\/.\/.\/.\/ # ButtonExample.java Uses the following classes: \u00a0\u00a0\u00a0 * CloseableFrame.java \u00a0\u00a0\u00a0 * FgReporter.java \u00a0\u00a0\u00a0 * BgReporter.java \u00a0\u00a0\u00a0 * SizeReporter.java ****************** ButtonExample.java ****************** import java.awt.*; import java.awt.event.*; \/.\/.\/.\/.\/.\/.\/.\/.\/.\/.\/ public class ButtonExample extends CloseableFrame { \u00a0 public static void main(String[] args) { \u00a0\u00a0\u00a0 new ButtonExample(); \u00a0 } \u00a0 public ButtonExample() { \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\/27022","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=27022"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/27022\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=27022"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=27022"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=27022"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}