{"id":27062,"date":"2021-05-09T23:10:06","date_gmt":"2021-05-10T03:10:06","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/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\/"},"modified":"2021-05-09T23:10:06","modified_gmt":"2021-05-10T03:10:06","slug":"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","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=27062","title":{"rendered":"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"},"content":{"rendered":"<pre>\nimport java.applet.Applet;\nimport java.awt.*;\nimport java.awt.event.*;\nimport java.net.*;\n\n\/** Applet reads arrays of strings packaged inside\n *  a QueryCollection and places them in a scrolling\n *  TextArea. The QueryCollection obtains the strings\n *  by means of a serialized object input stream\n *  connected to the QueryGenerator servlet.\n *  <p>\n *  Taken from Core Web Programming Java 2 Edition\n *  from Prentice Hall and Sun Microsystems Press,\n  *  May be freely used or adapted.\n *\/\n\npublic class ShowQueries extends Applet\n                         implements ActionListener, Runnable {\n  private TextArea queryArea;\n  private Button startButton, stopButton, clearButton;\n  private QueryCollection currentQueries;\n  private QueryCollection nextQueries;\n  private boolean isRunning = false;\n  private String address =\n    &quot;\/servlet\/cwp.QueryGenerator&quot;;\n  private URL currentPage;\n  \n  public void init() {\n    setBackground(Color.white);\n    setLayout(new BorderLayout());\n    queryArea = new TextArea();\n    queryArea.setFont(new Font(&quot;Serif&quot;, Font.PLAIN, 14));\n    add(queryArea, BorderLayout.CENTER);\n    Panel buttonPanel = new Panel();\n    Font buttonFont = new Font(&quot;SansSerif&quot;, Font.BOLD, 16);\n    startButton = new Button(&quot;Start&quot;);\n    startButton.setFont(buttonFont);\n    startButton.addActionListener(this);\n    buttonPanel.add(startButton);\n    stopButton = new Button(&quot;Stop&quot;);\n    stopButton.setFont(buttonFont);\n    stopButton.addActionListener(this);\n    buttonPanel.add(stopButton);\n    clearButton = new Button(&quot;Clear TextArea&quot;);\n    clearButton.setFont(buttonFont);\n    clearButton.addActionListener(this);\n    buttonPanel.add(clearButton);\n    add(buttonPanel, BorderLayout.SOUTH);\n    currentPage = getCodeBase();\n    \/\/ Request a set of sample queries. They\n    \/\/ are loaded in a background thread, and\n    \/\/ the applet checks to see if they have finished\n    \/\/ loading before trying to extract the strings.\n    currentQueries = new QueryCollection(address, currentPage);\n    nextQueries = new QueryCollection(address, currentPage);\n  }\n\n  \/** If you press the &quot;Start&quot; button, the system\n   *  starts a background thread that displays\n   *  the queries in the TextArea. Pressing &quot;Stop&quot;\n   *  halts the process, and &quot;Clear&quot; empties the\n   *  TextArea.\n   *\/\n \n  public void actionPerformed(ActionEvent event) {\n    if (event.getSource() == startButton) {\n      if (!isRunning) {\n        Thread queryDisplayer = new Thread(this);\n        isRunning = true;\n        queryArea.setText(&quot;&quot;);\n        queryDisplayer.start();\n        showStatus(&quot;Started display thread...&quot;);\n      } else {\n        showStatus(&quot;Display thread already running...&quot;);\n      }\n    } else if (event.getSource() == stopButton) {\n      isRunning = false;\n      showStatus(&quot;Stopped display thread...&quot;);\n    } else if (event.getSource() == clearButton) {\n      queryArea.setText(&quot;&quot;);\n    }\n  }\n\n  \/** The background thread takes the currentQueries\n   *  object and every half-second places one of the queries\n   *  the object holds into the bottom of the TextArea. When\n   *  all of the queries have been shown, the thread copies\n   *  the value of the nextQueries object into\n   *  currentQueries, sends a new request to the server\n   *  in order to repopulate nextQueries, and repeats\n   *  the process.\n   *\/\n\n  public void run() {\n    while(isRunning) {\n      showQueries(currentQueries);\n      currentQueries = nextQueries;\n      nextQueries = new QueryCollection(address, currentPage);\n    }\n  }\n\n  private void showQueries(QueryCollection queryEntry) {\n    \/\/ If request has been sent to server but the result\n    \/\/ isn't back yet, poll every second. This should\n    \/\/ happen rarely but is possible with a slow network\n    \/\/ connection or an overloaded server.\n    while(!queryEntry.isDone()) {\n      showStatus(&quot;Waiting for data from server...&quot;);\n      pause(1);\n    }\n    showStatus(&quot;Received data from server...&quot;);\n    String[] queries = queryEntry.getQueries();\n    String linefeed = &quot;n&quot;;\n    \/\/ Put a string into TextArea every half-second.\n    for(int i=0; i&lt;queries .length; i++) {\n      if (!isRunning) {\n        return;\n      }\n      queryArea.append(queries[i]);\n      queryArea.append(linefeed);\n      pause(0.5);\n    }\n  }\n\n  public void pause(double seconds) {\n    try {\n      Thread.sleep((long)(seconds*1000));\n    } catch(InterruptedException ie) {}\n  }\n}\n<\/p><\/pre>\n<p>Note: Brought from our old site: http:\/\/www.salearningschool.com\/example_codes\/ on Jan 2nd, 2017 From: http:\/\/sitestree.com\/?p=10263<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:28<\/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>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 from Core Web Programming Java &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=27062\">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-27062","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":10423,"url":"http:\/\/bangla.sitestree.com\/?p=10423","url_meta":{"origin":27062,"position":0},"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":10425,"url":"http:\/\/bangla.sitestree.com\/?p=10425","url_meta":{"origin":27062,"position":1},"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":[]},{"id":27064,"url":"http:\/\/bangla.sitestree.com\/?p=27064","url_meta":{"origin":27062,"position":2},"title":"The class that actually gets the strings over the network by means of an ObjectInputStream via HTTP tunneling. #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.net.*; import java.io.*; \/** When this class is built, it returns a value * immediately, but this value returns false for isDone * and null for getQueries. Meanwhile, it starts a Thread * to request an array of query strings from the server, * reading them in one fell\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":10308,"url":"http:\/\/bangla.sitestree.com\/?p=10308","url_meta":{"origin":27062,"position":3},"title":"Message.java Applet that reads customization parameters from an HTML file","author":"","date":"August 26, 2015","format":false,"excerpt":"******************* Message.java Applet that reads customization parameters from an HTML file ******************* import java.applet.Applet; import java.awt.*; **************** \u00a0 public class Message extends Applet { \u00a0 private int fontSize; \u00a0 private String message; \u00a0 \u00a0 public void init() { \u00a0\u00a0\u00a0 setBackground(Color.black); \u00a0\u00a0\u00a0 setForeground(Color.white); \u00a0\u00a0 \u00a0 \u00a0\u00a0\u00a0 \/\/ Base font size on\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":27249,"url":"http:\/\/bangla.sitestree.com\/?p=27249","url_meta":{"origin":27062,"position":4},"title":"Message.java Applet that reads customization parameters from an HTML file #Programming Code Examples #Java\/J2EE\/J2ME #Advanced Swing","author":"Author-Check- Article-or-Video","date":"May 15, 2021","format":false,"excerpt":"******************* Message.java Applet that reads customization parameters from an HTML file ******************* import java.applet.Applet; import java.awt.*; **************** public class Message extends Applet { private int fontSize; private String message; public void init() { setBackground(Color.black); setForeground(Color.white); \/\/ Base font size on window height. fontSize = getSize().height - 10; setFont(new Font(\"SansSerif\", Font.BOLD,\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":10419,"url":"http:\/\/bangla.sitestree.com\/?p=10419","url_meta":{"origin":27062,"position":5},"title":"An applet that searches multiple search engines, displaying the results in side-by-side frame cells.","author":"","date":"August 28, 2015","format":false,"excerpt":"Using Applets as Front Ends to Server-Side Programs ************************************************** SearchApplet.java An applet that searches multiple search engines, \u00a0displaying the results in side-by-side frame cells. Uses the following files: SearchSpec.javaParallelSearches.htmlSearchAppletFrame.htmlGoogleResultsFrame.htmlInfoseekResultsFrame.htmlLycosResultsFrame.html *************************************************** \/\/ import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.net.*; \/\/ \/** An applet that reads a value from a TextField,\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\/27062","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=27062"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/27062\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=27062"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=27062"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=27062"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}