{"id":27020,"date":"2021-05-08T23:10:06","date_gmt":"2021-05-09T03:10:06","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/uses-a-filedialog-to-choose-the-file-to-display-programming-code-examples-java-j2ee-j2me-awt-components\/"},"modified":"2021-05-08T23:10:06","modified_gmt":"2021-05-09T03:10:06","slug":"uses-a-filedialog-to-choose-the-file-to-display-programming-code-examples-java-j2ee-j2me-awt-components","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=27020","title":{"rendered":"Uses a FileDialog to choose the file to display #Programming Code Examples #Java\/J2EE\/J2ME #AWT Components"},"content":{"rendered":"<pre>\nDisplayFile.java \n****************\nimport java.awt.*;\nimport java.awt.event.*;\nimport java.io.*;\n\n\/** Uses a FileDialog to choose the file to display. \n ***************\n \npublic class DisplayFile extends CloseableFrame \n                         implements ActionListener {\n                                \n  public static void main(String[] args) {\n    new DisplayFile();\n  }\n\n  private Button loadButton;\n  private TextArea fileArea;\n  private FileDialog loader;\n\n  public DisplayFile() {\n    super(&quot;Using FileDialog&quot;);\n    loadButton = new Button(&quot;Display File&quot;);\n    loadButton.addActionListener(this);\n    Panel buttonPanel = new Panel();\n    buttonPanel.add(loadButton);\n    add(buttonPanel, BorderLayout.SOUTH);\n    fileArea = new TextArea();\n    add(&quot;Center&quot;, fileArea);\n    loader = new FileDialog(this, &quot;Browse&quot;, FileDialog.LOAD);\n    \/\/ Default file extension: .java.\n    loader.setFile(&quot;*.java&quot;);\n    setSize(350, 450);\n    setVisible(true);\n  }\n\n  \/** When the button is clicked, a file dialog is opened. When \n   * the file dialog is closed, load the file it referenced.\n   *\/\n  \n  public void actionPerformed(ActionEvent event) {\n      loader.show();\n      displayFile(loader.getFile());\n  }\n\n  public void displayFile(String filename) {\n    try {\n      File file = new File(filename);\n      FileInputStream in = new FileInputStream(file);\n      int fileLength = (int)file.length();\n      byte[] fileContents = new byte[fileLength];\n      in.read(fileContents);\n      String fileContentsString = new String(fileContents);\n      fileArea.setText(fileContentsString);\n    } catch(IOException ioe) {\n      fileArea.setText(&quot;IOError: &quot; + ioe);\n    }\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<\/pre>\n<p>Note: Brought from our old site: http:\/\/www.salearningschool.com\/example_codes\/ on Jan 2nd, 2017 From: http:\/\/sitestree.com\/?p=10331<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>DisplayFile.java **************** import java.awt.*; import java.awt.event.*; import java.io.*; \/** Uses a FileDialog to choose the file to display. *************** public class DisplayFile extends CloseableFrame implements ActionListener { public static void main(String[] args) { new DisplayFile(); } private Button loadButton; private TextArea fileArea; private FileDialog loader; public DisplayFile() { super(&quot;Using FileDialog&quot;); loadButton = new Button(&quot;Display File&quot;); &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=27020\">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_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[1917],"tags":[],"class_list":["post-27020","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":10343,"url":"http:\/\/bangla.sitestree.com\/?p=10343","url_meta":{"origin":27020,"position":0},"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":10423,"url":"http:\/\/bangla.sitestree.com\/?p=10423","url_meta":{"origin":27020,"position":1},"title":"An applet that reads arrays of strings packaged inside a QueryCollection and places them in a scrolling TextArea.","author":"","date":"August 28, 2015","format":false,"excerpt":"import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.net.*; \/** Applet reads arrays of strings packaged inside \u00a0*\u00a0 a QueryCollection and places them in a scrolling \u00a0*\u00a0 TextArea. The QueryCollection obtains the strings \u00a0*\u00a0 by means of a serialized object input stream \u00a0*\u00a0 connected to the QueryGenerator servlet. \u00a0* \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":10487,"url":"http:\/\/bangla.sitestree.com\/?p=10487","url_meta":{"origin":27020,"position":2},"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":10339,"url":"http:\/\/bangla.sitestree.com\/?p=10339","url_meta":{"origin":27020,"position":3},"title":"A Frame that lets you draw circles with mouse clicks","author":"","date":"August 26, 2015","format":false,"excerpt":"SavedFrame.java **************** A Frame that lets you draw circles with mouse clicks \/\/************** import java.awt.*; import java.awt.event.*; import java.io.*; \/** A Frame that lets you draw circles with mouse clicks \u00a0*\u00a0 and then save the Frame and all circles to disk. \u00a0* public class SavedFrame 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 implements ActionListener\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":27062,"url":"http:\/\/bangla.sitestree.com\/?p=27062","url_meta":{"origin":27020,"position":4},"title":"An applet that reads arrays of strings packaged inside a QueryCollection and places them in a scrolling TextArea. #Programming Code Examples #Java\/J2EE\/J2ME #Applets and Basic Graphics","author":"Author-Check- Article-or-Video","date":"May 9, 2021","format":false,"excerpt":"import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.net.*; \/** Applet reads arrays of strings packaged inside * a QueryCollection and places them in a scrolling * TextArea. The QueryCollection obtains the strings * by means of a serialized object input stream * connected to the QueryGenerator servlet. * * Taken\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":27020,"position":5},"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":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/27020","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=27020"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/27020\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=27020"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=27020"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=27020"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}