// // URLtimestable class // part of the set of documents known as Java no sugar. // Copyright (c) 1996 Sunil Gupta, sunil@magnetic.demon.co.uk // placed into the public domain by the author // import java.awt.*; import java.io.*; import java.net.*; import java.applet.*; import java.util.*; import UrlPostConnection; import Document; public class URLtimestable extends Applet { //******************************************************************* // instance variables //******************************************************************* static final String HOSTPARAM = "HOSTNAME"; static final String PORTPARAM = "PORTNAME"; TextArea textarea; TextField txt_number, txt_count; Button btn_doit; //******************************************************************* // applet methods //******************************************************************* public void init() { GridBagConstraints c; GridBagLayout layout; Label label; //--------BUILD THE USER INTERFACE------------------------- layout = new GridBagLayout(); this.setLayout( layout ); //--------------------------------------------------------- label = new Label("Number"); c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; c.gridwidth=1; c.gridheight=1; c.fill = GridBagConstraints.HORIZONTAL; layout.setConstraints(label,c); this.add(label); label = new Label("Count"); c = new GridBagConstraints(); c.gridx = 0; c.gridy = 1; c.gridwidth=1; c.gridheight=1; c.fill = GridBagConstraints.HORIZONTAL; layout.setConstraints(label,c); this.add(label); //--------------------------------------------------------- txt_number = new TextField(); c = new GridBagConstraints(); c.gridx = 1; c.gridy = 0; c.gridwidth=1; c.gridheight=1; c.fill = GridBagConstraints.HORIZONTAL; layout.setConstraints(txt_number,c); this.add(txt_number); txt_count = new TextField(); c = new GridBagConstraints(); c.gridx = 1; c.gridy = 1; c.gridwidth=1; c.gridheight=1; c.fill = GridBagConstraints.HORIZONTAL; layout.setConstraints(txt_count,c); this.add(txt_count); //--------------------------------------------------------- textarea = new TextArea(); c = new GridBagConstraints(); c.gridx = 0; c.gridy = 2; c.gridwidth=2; c.gridheight=2; c.fill = GridBagConstraints.BOTH; layout.setConstraints(textarea,c); this.add(textarea); //------------------------add button-------------------- btn_doit = new Button("Do it"); c = new GridBagConstraints(); c.gridx = 2; c.gridy = 0; c.gridwidth=1; c.gridheight=1; c.fill = GridBagConstraints.HORIZONTAL; layout.setConstraints(btn_doit,c); this.add(btn_doit); } public boolean action(Event event, Object arg) { if (event.target == btn_doit) { do_times_url(); return true; } return (false) ; } // // date is a safe choice since most httpd's implement this // private void do_times_url() throws NumberFormatException { URL applet_url; String protocol, data_line; String num,count; DataInputStream in_stream; PrintStream out_stream; UrlPostConnection connection; String script = "/cgi-bin/timestable.pl"; String hostname, port_string; int port; Document document; Enumeration result_data; //------------------------------------------------------------------ // clear out any text // textarea.setText(""); //------------------------------------------------------------------ // make sure applet is running from httpd // applet_url = this.getDocumentBase(); protocol = applet_url.getProtocol(); if ( ! protocol.equals("http") ) { textarea.appendText( "This applet isnt being run from a server\n" + "and will not work unless you switch off the security\n" + "restrictions on your browser\n" ); hostname = getParameter(HOSTPARAM); if (hostname == null) { textarea.appendText("You need to supply a hostname in the " + HOSTPARAM + " paramater\n"); return; } port_string = getParameter(PORTPARAM); if ( port_string == null) port = 80; else port = Integer.parseInt(port_string); } else { textarea.appendText("Applet is on a server\n"); hostname = applet_url.getHost(); port = applet_url.getPort(); } //------------------------------------------------------------------ // BUILD URL netscape doesnt support POST so have to use a custom class. // connection = new UrlPostConnection(hostname, port, script); connection.setProperty("number", txt_number.getText() ); connection.setProperty("count", txt_count.getText() ); textarea.appendText( "Attempting to use URL " + connection.toString()+ "\n"); try { document = connection.sendData(); } catch (IOException e) { textarea.appendText("unable to connect to \n " + e +"\n"); return; } //------------------------------------------------------------------ // All was well if this point was reached, display string data" // result_data = document.body(); while (result_data.hasMoreElements()) { data_line = (String) result_data.nextElement(); textarea.appendText(data_line +"\n"); } } }
file: /Techref/language/java/nosugar/comms/code/URLtimestable.java, 5KB, , updated: 1996/10/10 10:08, local time: 2024/12/26 07:02,
3.14.249.191:LOG IN
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://massmind.ecomorder.com/techref/language/java/nosugar/comms/code/URLtimestable.java"> language java nosugar comms code URLtimestable</A> |
Did you find what you needed? |
Welcome to ecomorder.com! |
Welcome to massmind.ecomorder.com! |
.