Using Applets as Front Ends to Server-Side Programs ************************************************** SearchApplet.java An applet that searches multiple search engines, displaying 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, * then uses it to build three distinct URLs with embedded * GET data: one each for Google, Infoseek, and Lycos. * The browser is directed to retrieve each of these * URLs, displaying them in side-by-side frame cells. * Note that standard HTML forms cannot automatically * perform multiple submissions in this manner. ** Taken from Core Web Programming Java 2 Edition * from Prentice Hall and Sun Microsystems Press, * May be freely used or adapted. */ public class SearchApplet extends Applet implements ActionListener { private TextField queryField; private Button submitButton; public void init() { setBackground(Color.white); setFont(new Font("Serif", Font.BOLD, 18)); add(new Label("Search String:")); queryField = new TextField(40); queryField.addActionListener(this); add(queryField); submitButton = new Button("Send to Search Engines"); submitButton.addActionListener(this); add(submitButton); } /** Submit data when button is pressed or * user presses Return in the TextField. */ public void actionPerformed(ActionEvent event) { String query = URLEncoder.encode(queryField.getText()); SearchSpec[] commonSpecs = SearchSpec.getCommonSpecs(); // Omitting HotBot (last entry), as they use JavaScript to // pop result to top-level frame. Thus the length-1 below. for(int i=0; i<commonspecs .length-1; i++) { try { SearchSpec spec = commonSpecs[i]; // The SearchSpec class builds URLs of the // form needed by some common search engines. URL searchURL = new URL(spec.makeURL(query, "10")); String frameName = "results" + i; getAppletContext().showDocument(searchURL, frameName); } catch(MalformedURLException mue) {} } } }
Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017 From: http://sitestree.com/?p=10211
Categories:Programming Code Examples, Java/J2EE/J2ME, Applets and Basic Graphics
Tags:Java/J2EE/J2MEApplets and Basic Graphics
Post Data:2017-01-02 16:04:23
Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada