{"id":27223,"date":"2021-05-14T23:10:07","date_gmt":"2021-05-15T03:10:07","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/listevent2-java-programming-code-examples-java-j2ee-j2me-advanced-swing\/"},"modified":"2021-05-14T23:10:07","modified_gmt":"2021-05-15T03:10:07","slug":"listevent2-java-programming-code-examples-java-j2ee-j2me-advanced-swing","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=27223","title":{"rendered":"ListEvent2.java #Programming Code Examples #Java\/J2EE\/J2ME #Advanced Swing"},"content":{"rendered":"<pre>\n# ListEvents.java Uses the following classes:\n\n    * CloseableFrame.java\n    * SelectionReporter.java\n    * ActionReporter.java\n\/.\/.\/.\/.\/.\/.\/.\/.\/.\/.\/.\/.\/\nimport java.awt.event.*;\n\n\/.\/.\/.\/.\/.\/.\/\n\npublic class ListEvents2 extends ListEvents {\n  public static void main(String[] args) {\n    new ListEvents2();\n  }\n\n  \/** Extends ListEvents with the twist that\n   *  typing any of the letters of &quot;JAVA&quot; or &quot;java&quot;\n   *  over the language list will result in &quot;Java&quot;\n   *  being selected\n   *\/\n\n  public ListEvents2() {\n    super();\n    \/\/ Create a KeyAdapter and attach it to languageList.\n    \/\/ Since this is an inner class, it has access\n    \/\/ to nonpublic data (such as the ListEvent's\n    \/\/ protected showJava method).\n    KeyAdapter javaChooser = new KeyAdapter() {\n      public void keyPressed(KeyEvent event) {\n        int key = event.getKeyChar();\n        if (&quot;JAVAjava&quot;.indexOf(key) != -1) {\n          showJava();\n        }\n      }\n    };\n    languageList.addKeyListener(javaChooser);\n  }\n}\n\n***************************\nimport java.awt.*;\nimport java.awt.event.*;\n\n\/** A class to demonstrate list selection\/deselection\n *  and action events.\n *\n \/*******************\/.&gt;\n\npublic class ListEvents extends CloseableFrame {\n  public static void main(String[] args) {\n    new ListEvents();\n  }\n\n  protected List languageList;\n  private TextField selectionField, actionField;\n  private String selection = &quot;[NONE]&quot;, action;\n\n  \/** Build a Frame with list of language choices\n   *  and two textfields to show the last selected\n   *  and last activated items from this list.\n   *\/\n  public ListEvents() {\n    super(&quot;List Events&quot;);\n    setFont(new Font(&quot;Serif&quot;, Font.BOLD, 16));\n    add(makeLanguagePanel(), BorderLayout.WEST);\n    add(makeReportPanel(), BorderLayout.CENTER);\n    pack();\n    setVisible(true);\n  }\n\n  \/\/ Create Panel containing List with language choices.\n  \/\/ Constructor puts this at left side of Frame.\n  \n  private Panel makeLanguagePanel() {\n    Panel languagePanel = new Panel();\n    languagePanel.setLayout(new BorderLayout());\n    languagePanel.add(new Label(&quot;Choose Language&quot;), \n                      BorderLayout.NORTH);\n    languageList = new List(3);\n    String[] languages =\n      { &quot;Ada&quot;, &quot;C&quot;, &quot;C++&quot;, &quot;Common Lisp&quot;, &quot;Eiffel&quot;,\n        &quot;Forth&quot;, &quot;Fortran&quot;, &quot;Java&quot;, &quot;Pascal&quot;,\n        &quot;Perl&quot;, &quot;Scheme&quot;, &quot;Smalltalk&quot; };\n    for(int i=0; i&lt;languages .length; i++) {\n      languageList.add(languages[i]);\n    }\n    showJava();\n    languagePanel.add(&quot;Center&quot;, languageList);\n    return(languagePanel);\n  }\n\n  \/\/ Creates Panel with two labels and two textfields.\n  \/\/ The first will show the last selection in List; the\n  \/\/ second, the last item activated. The constructor puts\n  \/\/ this Panel at the right of Frame.\n\n  private Panel makeReportPanel() {\n    Panel reportPanel = new Panel();\n    reportPanel.setLayout(new GridLayout(4, 1));\n    reportPanel.add(new Label(&quot;Last Selection:&quot;));\n    selectionField = new TextField();\n    SelectionReporter selectionReporter =\n      new SelectionReporter(selectionField);\n    languageList.addItemListener(selectionReporter);\n    reportPanel.add(selectionField);\n    reportPanel.add(new Label(&quot;Last Action:&quot;));\n    actionField = new TextField();\n    ActionReporter actionReporter = \n      new ActionReporter(actionField);\n    languageList.addActionListener(actionReporter);\n    reportPanel.add(actionField);\n    return(reportPanel);\n  }\n\n  \/** Select and show &quot;Java&quot;. *\/\n  \n  protected void showJava() {\n    languageList.select(7);\n    languageList.makeVisible(7);\n  }\n}\n*********************\nSelectionReporter.java\n*********************\nimport java.awt.*;\nimport java.awt.event.*;\n\n\/** Whenever an item is selected, it is displayed\n *  in the textfield that was supplied to the\n *  SelectionReporter constructor.\n *\n *******************************\npublic class SelectionReporter implements ItemListener {\n  private TextField selectionField;\n\n  public SelectionReporter(TextField selectionField) {\n    this.selectionField = selectionField;\n  }\n\n  public void itemStateChanged(ItemEvent event) {\n    if (event.getStateChange() == event.SELECTED) {\n      List source = (List)event.getSource();\n      selectionField.setText(source.getSelectedItem());\n    } else\n      selectionField.setText(&quot;&quot;);\n  }\n}\n*********************\nActionReporter.java\n*******************\nimport java.awt.*;\nimport java.awt.event.*;\n\n\/** Whenever an item is activated, it is displayed\n *  in the textfield that was supplied to the\n *  ActionReporter constructor.\n *\n *************************\n\npublic class ActionReporter implements ActionListener {\n  private TextField actionField;\n\n  public ActionReporter(TextField actionField) {\n    this.actionField = actionField;\n  }\n\n  public void actionPerformed(ActionEvent event) {\n    List source = (List)event.getSource();\n    actionField.setText(source.getSelectedItem());\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=10340<br \/> Categories:Programming Code Examples, Java\/J2EE\/J2ME, Advanced Swing<br \/>Tags:Java\/J2EE\/J2MEAdvanced Swing<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># ListEvents.java Uses the following classes: * CloseableFrame.java * SelectionReporter.java * ActionReporter.java \/.\/.\/.\/.\/.\/.\/.\/.\/.\/.\/.\/.\/ import java.awt.event.*; \/.\/.\/.\/.\/.\/.\/ public class ListEvents2 extends ListEvents { public static void main(String[] args) { new ListEvents2(); } \/** Extends ListEvents with the twist that * typing any of the letters of &quot;JAVA&quot; or &quot;java&quot; * over the language list will result &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=27223\">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-27223","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":10288,"url":"http:\/\/bangla.sitestree.com\/?p=10288","url_meta":{"origin":27223,"position":0},"title":"ListEvent2.java","author":"","date":"August 26, 2015","format":false,"excerpt":"# ListEvents.java Uses the following classes: \u00a0\u00a0\u00a0 * CloseableFrame.java \u00a0\u00a0\u00a0 * SelectionReporter.java \u00a0\u00a0\u00a0 * ActionReporter.java \/.\/.\/.\/.\/.\/.\/.\/.\/.\/.\/.\/.\/ import java.awt.event.*; \/.\/.\/.\/.\/.\/.\/ public class ListEvents2 extends ListEvents { \u00a0 public static void main(String[] args) { \u00a0\u00a0\u00a0 new ListEvents2(); \u00a0 } \u00a0 \/** Extends ListEvents with the twist that \u00a0\u00a0 *\u00a0 typing any of\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":10299,"url":"http:\/\/bangla.sitestree.com\/?p=10299","url_meta":{"origin":27223,"position":1},"title":"Adds typing to the freehand drawing.","author":"","date":"August 26, 2015","format":false,"excerpt":"import java.applet.Applet; import java.awt.*; import java.awt.event.*; \/** A better whiteboard that lets you enter \u00a0*\u00a0 text in addition to freehand drawing. \u00a0* \u00a0 \u00a0****************** public class Whiteboard extends SimpleWhiteboard { \u00a0 protected FontMetrics fm; \u00a0 public void init() { \u00a0\u00a0\u00a0 super.init(); \u00a0\u00a0\u00a0 Font font = new Font(\"Serif\", Font.BOLD, 20); \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":10391,"url":"http:\/\/bangla.sitestree.com\/?p=10391","url_meta":{"origin":27223,"position":2},"title":"A TextField that uses key events to correct the spelling of the names of computer languages entered into it","author":"","date":"August 28, 2015","format":false,"excerpt":"import java.awt.*; import java.awt.event.*; \/** A spelling-correcting TextField for entering \u00a0*\u00a0 a language name. \u00a0* \u00a0 \u00a0******************* public class LanguageField extends TextField { \u00a0 private String[] substrings = \u00a0\u00a0\u00a0 { \"\", \"J\", \"Ja\", \"Jav\", \"Java\" }; \u00a0 public LanguageField() { \u00a0\u00a0\u00a0 addKeyListener(new SpellingCorrector()); \u00a0\u00a0\u00a0 addActionListener(new WordCompleter()); \u00a0\u00a0\u00a0 addFocusListener(new SubliminalAdvertiser()); \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":26773,"url":"http:\/\/bangla.sitestree.com\/?p=26773","url_meta":{"origin":27223,"position":3},"title":"A TextField that uses key events to correct the spelling of the names of computer languages entered into it #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.awt.*; import java.awt.event.*; \/** A spelling-correcting TextField for entering * a language name. * ******************* public class LanguageField extends TextField { private String[] substrings = { \"\", \"J\", \"Ja\", \"Jav\", \"Java\" }; public LanguageField() { addKeyListener(new SpellingCorrector()); addActionListener(new WordCompleter()); addFocusListener(new SubliminalAdvertiser()); } \/\/ Put caret at end of field.\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":27241,"url":"http:\/\/bangla.sitestree.com\/?p=27241","url_meta":{"origin":27223,"position":4},"title":"Adds typing to the freehand drawing. #Programming Code Examples #Java\/J2EE\/J2ME #Advanced Swing","author":"Author-Check- Article-or-Video","date":"May 15, 2021","format":false,"excerpt":"import java.applet.Applet; import java.awt.*; import java.awt.event.*; \/** A better whiteboard that lets you enter * text in addition to freehand drawing. * ****************** public class Whiteboard extends SimpleWhiteboard { protected FontMetrics fm; public void init() { super.init(); Font font = new Font(\"Serif\", Font.BOLD, 20); setFont(font); fm = getFontMetrics(font); addKeyListener(new CharDrawer());\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":10363,"url":"http:\/\/bangla.sitestree.com\/?p=10363","url_meta":{"origin":27223,"position":5},"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":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/27223","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=27223"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/27223\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=27223"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=27223"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=27223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}