home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1998 September / dppcpro0998.iso / Rwc / Sybase / Install.exe / samples.z / form_socket.wxf < prev    next >
Encoding:
Text File  |  1998-03-25  |  11.3 KB  |  426 lines

  1. Save Format v2.3(19971110)
  2. @begin Form "Form_Socket"
  3.  
  4.  @begin Object "Powersoft Java AWT 1.10::java.applet.Applet"
  5.   DesignName Form_Socket;
  6.   @begin ClassProperties
  7. @begin-code BaseClassList
  8.  
  9. extends java.applet.Applet
  10.  
  11. @end-code;
  12.   @end;
  13.   @begin Properties
  14.    @begin DesignProperties
  15.     Style "cf0000";
  16.     DesignRect 29,59,328,230;
  17.    @end;
  18.    @begin ObjectProperties
  19.     font "Dialog-Plain-12";
  20.     LayoutManager "powersoft.powerj.ui.ResizePercentageLayout";
  21.     foreground "java.awt.Color.black";
  22.     background "java.awt.Color.lightGray";
  23.     SerializationData "";
  24.    @end;
  25.   @end;
  26.   @begin Events
  27.    @begin Event "powersoft.powerj.event.Object.objectCreated"
  28. @begin-code SourceCode "powersoft.powerj.event.Object.objectCreated"
  29.  
  30.     public boolean Form_Socket_objectCreated(powersoft.powerj.event.EventData event)
  31.     {
  32.         textf_server.setText( "localhost" );
  33.         textf_port.setText( String.valueOf( DEFAULT_PORT ) );
  34.         cb_connect.requestFocus();   
  35.         
  36.         return false;
  37.     }
  38.  
  39. @end-code;
  40.    @end;
  41.   @end;
  42.   @begin UserFunctions
  43.    @begin UserFunction "Form_Socket()"
  44.     @begin Definition
  45. @begin-code SourceCode "Form_Socket()"
  46.  
  47.     public Form_Socket()
  48.     {
  49.         super();
  50.     }
  51.  
  52. @end-code;
  53.     @end;
  54.    @end;
  55.    @begin UserFunction "processEvent(java.awt.AWTEvent event)"
  56.     @begin Definition
  57. @begin-code SourceCode "processEvent(java.awt.AWTEvent event)"
  58.  
  59.     public void processEvent(java.awt.AWTEvent event)
  60.     {
  61.  
  62.         defaultProcessEvent(event);
  63.     }
  64.  
  65. @end-code;
  66.     @end;
  67.    @end;
  68.    @begin UserFunction "unhandledEvent( String listenerName, String methodName, java.lang.Object event )"
  69.     @begin Definition
  70. @begin-code SourceCode "unhandledEvent( String listenerName, String methodName, java.lang.Object event )"
  71.  
  72.     public void unhandledEvent( String listenerName, String methodName, java.lang.Object event )
  73.     {
  74.  
  75.     }
  76.  
  77. @end-code;
  78.     @end;
  79.    @end;
  80.    @begin UserFunction "getContentPane()"
  81.     @begin Definition
  82. @begin-code SourceCode "getContentPane()"
  83.  
  84.     public java.awt.Container getContentPane()
  85.     {
  86.         return this;
  87.     }
  88.  
  89. @end-code;
  90.     @end;
  91.    @end;
  92.   @end;
  93.   @begin CodeBlocks
  94.    @begin CodeBlock "HppPrefix"
  95.     FunctionScope 1;
  96. @begin-code SourceCode "Imports()"
  97.  
  98. // add your custom import statements here
  99.  
  100. import java.net.*;
  101. import java.io.*;
  102. import powersoft.powerj.util.*;
  103.  
  104. @end-code;
  105.    @end;
  106.    @begin CodeBlock "ClassContents"
  107.     FunctionScope 1;
  108. @begin-code SourceCode "Data Members()"
  109.  
  110.     // add your data members here
  111.     java.net.Socket     _s;
  112.     DataInputStream     _input; // input to this socket from the server
  113.     PrintStream         _output;   // output from this socket to the server
  114.     StreamListener      _listener; // listens for input from server using 'input'
  115.     Debug               _dbLog;
  116.     
  117.     public static final int DEFAULT_PORT = 1777;
  118.  
  119.  
  120.     class StreamListener extends Thread
  121.     {
  122.  
  123.         public StreamListener( DataInputStream input, java.awt.List outputArea ) {
  124.             _input = input;
  125.             _outputArea = outputArea;
  126.             start();
  127.         }
  128.  
  129.         public void run() {
  130.             String          msgFromServer;
  131.  
  132.             try {
  133.                 for(;;) {
  134.                     msgFromServer = _input.readLine(); // blocks on server.
  135.                     if( msgFromServer == null ) break;
  136.                     _outputArea.add( msgFromServer );
  137.                 }
  138.             } catch( IOException e ) {
  139.                 _outputArea.add( e.toString() );
  140.             } catch( NullPointerException e ) {
  141.                 _outputArea.add( e.toString() );
  142.                 _dbLog.log( e.getMessage() );
  143.                 e.printStackTrace();
  144.             } finally {
  145.                 _outputArea.add( "Connection closed by server" );
  146.             }
  147.         }
  148.         // add your data members here
  149.         DataInputStream     _input; // input to this socket from the server
  150.         java.awt.List       _outputArea;
  151.  
  152.     }
  153.  
  154. @end-code;
  155.    @end;
  156.    @begin CodeBlock "GeneratedClassContents"
  157.     FunctionScope 1;
  158.     GeneratedFunction 1;
  159. @begin-code SourceCode "Not Applicable for Java()"
  160.  
  161.  
  162. @end-code;
  163.    @end;
  164.    @begin CodeBlock "CppPrefix"
  165.     FunctionScope 1;
  166.     GeneratedFunction 1;
  167. @begin-code SourceCode "Not Applicable for Java()"
  168.  
  169.  
  170. @end-code;
  171.    @end;
  172.   @end;
  173.   @begin Objects
  174.    @begin Object "Powersoft Java AWT 1.10::java.awt.TextField"
  175.     DesignName textf_server;
  176.     @begin Properties
  177.      @begin DesignProperties
  178.       ResID 100;
  179.       DesignRect 5,20,140,14;
  180.      @end;
  181.      @begin ObjectProperties
  182.       font "Dialog-Plain-12";
  183.       foreground "java.awt.Color.black";
  184.       background "java.awt.Color.white";
  185.       SerializationData "";
  186.      @end;
  187.     @end;
  188.    @end;
  189.    @begin Object "Powersoft Java AWT 1.10::java.awt.TextField"
  190.     DesignName textf_port;
  191.     @begin Properties
  192.      @begin DesignProperties
  193.       ResID 100;
  194.       TabIndex 1;
  195.       DesignRect 155,20,45,14;
  196.      @end;
  197.      @begin ObjectProperties
  198.       font "Dialog-Plain-12";
  199.       foreground "java.awt.Color.black";
  200.       background "java.awt.Color.white";
  201.       SerializationData "";
  202.      @end;
  203.     @end;
  204.    @end;
  205.    @begin Object "Powersoft Java AWT 1.10::java.awt.Button"
  206.     DesignName cb_connect;
  207.     @begin Properties
  208.      @begin DesignProperties
  209.       ResID 100;
  210.       TabIndex 2;
  211.       DesignRect 210,20,50,14;
  212.      @end;
  213.      @begin ObjectProperties
  214.       font "Dialog-Plain-12";
  215.       foreground "java.awt.Color.black";
  216.       background "java.awt.Color.lightGray";
  217.       SerializationData "";
  218.       label "Connect";
  219.      @end;
  220.     @end;
  221.     @begin Events
  222.      @begin Event "java.awt.event.Action.actionPerformed"
  223. @begin-code SourceCode "java.awt.event.Action.actionPerformed"
  224.  
  225.     public void cb_connect_actionPerformed( java.awt.event.ActionEvent event )
  226.     {
  227.         String          hostName = textf_server.getText();
  228.         Integer         port = new Integer( textf_port.getText() );
  229.         
  230.         _dbLog = new Debug();
  231.  
  232.         try {
  233.             _s = new java.net.Socket( hostName, port.intValue() );
  234.             lb_1.add( "Connected to " + hostName);
  235.             _input = new DataInputStream( _s.getInputStream() );
  236.             _output = new PrintStream( _s.getOutputStream() );
  237.         }
  238.         catch ( UnknownHostException e) {
  239.             _dbLog.log( "UnknownHostException thrown while creating socket." );
  240.         }
  241.         catch ( IOException e) {
  242.             _dbLog.log( "IOException thrown while creating socket." );
  243.         }
  244.  
  245.         _listener = new StreamListener( _input, lb_1 );
  246.     }
  247.  
  248. @end-code;
  249.      @end;
  250.     @end;
  251.    @end;
  252.    @begin Object "Powersoft Java AWT 1.10::java.awt.Button"
  253.     DesignName cb_disconnect;
  254.     @begin Properties
  255.      @begin DesignProperties
  256.       ResID 100;
  257.       TabIndex 3;
  258.       DesignRect 265,20,50,14;
  259.      @end;
  260.      @begin ObjectProperties
  261.       font "Dialog-Plain-12";
  262.       foreground "java.awt.Color.black";
  263.       background "java.awt.Color.lightGray";
  264.       SerializationData "";
  265.       label "Disconnect";
  266.      @end;
  267.     @end;
  268.     @begin Events
  269.      @begin Event "java.awt.event.Action.actionPerformed"
  270. @begin-code SourceCode "java.awt.event.Action.actionPerformed"
  271.  
  272.     public void cb_disconnect_actionPerformed( java.awt.event.ActionEvent event )
  273.     {
  274.         try {
  275.             _output.println( "Attempting to close client side socket" );
  276.             _s.close();
  277.             lb_1.add( "Disconnected successfully" );
  278.         } catch( IOException e ) {
  279.             _dbLog.log( "IOException while closing client side socket" );
  280.         }
  281.     }
  282.  
  283. @end-code;
  284.      @end;
  285.     @end;
  286.    @end;
  287.    @begin Object "Powersoft Java AWT 1.10::java.awt.TextField"
  288.     DesignName textf_msg;
  289.     @begin Properties
  290.      @begin DesignProperties
  291.       ResID 100;
  292.       TabIndex 4;
  293.       DesignRect 5,60,265,14;
  294.      @end;
  295.      @begin ObjectProperties
  296.       font "Dialog-Plain-12";
  297.       foreground "java.awt.Color.black";
  298.       background "java.awt.Color.white";
  299.       SerializationData "";
  300.      @end;
  301.     @end;
  302.    @end;
  303.    @begin Object "Powersoft Java AWT 1.10::java.awt.Button"
  304.     DesignName cb_send;
  305.     @begin Properties
  306.      @begin DesignProperties
  307.       ResID 100;
  308.       TabIndex 5;
  309.       DesignRect 275,60,40,14;
  310.      @end;
  311.      @begin ObjectProperties
  312.       font "Dialog-Plain-12";
  313.       foreground "java.awt.Color.black";
  314.       background "java.awt.Color.lightGray";
  315.       SerializationData "";
  316.       label "Send";
  317.      @end;
  318.     @end;
  319.     @begin Events
  320.      @begin Event "java.awt.event.Action.actionPerformed"
  321. @begin-code SourceCode "java.awt.event.Action.actionPerformed"
  322.  
  323.     public void cb_send_actionPerformed( java.awt.event.ActionEvent event )
  324.     {
  325.         // Dump the contents of the message text box to the output 
  326.         // stream i.e., to the socket on the server.
  327.         _output.println( textf_msg.getText() );
  328.         // Clear the message box.
  329.         textf_msg.setText( "" );
  330.  
  331.     }
  332.  
  333. @end-code;
  334.      @end;
  335.     @end;
  336.    @end;
  337.    @begin Object "Powersoft Java AWT 1.10::java.awt.List"
  338.     DesignName lb_1;
  339.     @begin Properties
  340.      @begin DesignProperties
  341.       ResID 100;
  342.       TabIndex 6;
  343.       DesignRect 5,100,310,70;
  344.      @end;
  345.      @begin ObjectProperties
  346.       font "Dialog-Plain-12";
  347.       foreground "java.awt.Color.black";
  348.       background "java.awt.Color.white";
  349.       SerializationData "";
  350.      @end;
  351.      @begin ComponentProperties "lb_1"
  352.      @end;
  353.     @end;
  354.    @end;
  355.    @begin Object "Powersoft Java AWT 1.10::java.awt.Label"
  356.     DesignName label_1;
  357.     @begin Properties
  358.      @begin DesignProperties
  359.       ResID 100;
  360.       TabIndex 7;
  361.       DesignRect 5,45,80,10;
  362.      @end;
  363.      @begin ObjectProperties
  364.       font "Dialog-Plain-12";
  365.       text "Message for server:";
  366.       foreground "java.awt.Color.black";
  367.       background "java.awt.Color.lightGray";
  368.       SerializationData "";
  369.      @end;
  370.     @end;
  371.    @end;
  372.    @begin Object "Powersoft Java AWT 1.10::java.awt.Label"
  373.     DesignName label_2;
  374.     @begin Properties
  375.      @begin DesignProperties
  376.       ResID 100;
  377.       TabIndex 8;
  378.       DesignRect 5,85,35,10;
  379.      @end;
  380.      @begin ObjectProperties
  381.       font "Dialog-Plain-12";
  382.       text "Log:";
  383.       foreground "java.awt.Color.black";
  384.       background "java.awt.Color.lightGray";
  385.       SerializationData "";
  386.      @end;
  387.     @end;
  388.    @end;
  389.    @begin Object "Powersoft Java AWT 1.10::java.awt.Label"
  390.     DesignName label_3;
  391.     @begin Properties
  392.      @begin DesignProperties
  393.       ResID 100;
  394.       TabIndex 9;
  395.       DesignRect 5,10,50,10;
  396.      @end;
  397.      @begin ObjectProperties
  398.       font "Dialog-Plain-12";
  399.       text "Server name:";
  400.       foreground "java.awt.Color.black";
  401.       background "java.awt.Color.lightGray";
  402.       SerializationData "";
  403.      @end;
  404.     @end;
  405.    @end;
  406.    @begin Object "Powersoft Java AWT 1.10::java.awt.Label"
  407.     DesignName label_4;
  408.     @begin Properties
  409.      @begin DesignProperties
  410.       ResID 100;
  411.       TabIndex 10;
  412.       DesignRect 155,10,20,10;
  413.      @end;
  414.      @begin ObjectProperties
  415.       font "Dialog-Plain-12";
  416.       text "Port:";
  417.       foreground "java.awt.Color.black";
  418.       background "java.awt.Color.lightGray";
  419.       SerializationData "";
  420.      @end;
  421.     @end;
  422.    @end;
  423.   @end;
  424.  @end;
  425. @end;
  426.