home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / sybase / starbuck / samples.z / form2.wxf < prev    next >
Text File  |  1996-12-08  |  11KB  |  459 lines

  1. Save Format v1.3
  2. @begin Form "Form2"
  3.  Exported 0;
  4.  Abstract 0;
  5.  Interface 0;
  6.  PackageName "";
  7.  
  8.  @begin Object "WJava_powersoft__dot__jcm__dot__ui__dot__Applet"
  9.   Font "Dialog-Plain-8";
  10.   ControlScope "Private";
  11.   BackColor "Color.lightGray";
  12.   ForeColor "Color.black";
  13.   Text "Java Chat";
  14.   Visible "1";
  15.   DataSource "NULL";
  16.   DataColumns "";
  17.   BoundControl "0";
  18.   @begin Event "Create"
  19.    GencodeSrcLine 167;
  20.    FunctionName "Form2_Create";
  21.   @end;
  22.   @begin Event "Destroy"
  23.    GencodeSrcLine 174;
  24.    FunctionName "Form2_Destroy";
  25.   @end;
  26.   @begin UserFunction "Form2(powersoft.jcm.ui.AWTAppletEx applet)"
  27.    Compiler 1;
  28.    GencodeSrcLine 162;
  29.    FunctionName "Form2::Form2(powersoft.jcm.ui.AWTAppletEx applet)";
  30.   @end;
  31.   ResID 102;
  32.   DesignName Form2;
  33.   TabIndex 0;
  34.   DesignRect 153,134,263,231;
  35.  @end;
  36.  
  37.  @begin Object "WJava_powersoft__dot__jcm__dot__net__dot__Socket"
  38.   Asynchronous "1";
  39.   @begin Event "SocketConnect"
  40.    GencodeSrcLine 184;
  41.    FunctionName "socket_1_SocketConnect";
  42.   @end;
  43.   @begin Event "SocketDataArrival"
  44.    GencodeSrcLine 191;
  45.    FunctionName "socket_1_SocketDataArrival";
  46.   @end;
  47.   @begin Event "SocketError"
  48.    GencodeSrcLine 220;
  49.    FunctionName "socket_1_SocketError";
  50.   @end;
  51.   @begin Event "SocketHostResolved"
  52.    GencodeSrcLine 231;
  53.    FunctionName "socket_1_SocketHostResolved";
  54.   @end;
  55.   @begin Event "SocketSendComplete"
  56.    GencodeSrcLine 239;
  57.    FunctionName "socket_1_SocketSendComplete";
  58.   @end;
  59.   ResID 100;
  60.   DesignName socket_1;
  61.   TabIndex 0;
  62.   DesignRect 240,5,19,17;
  63.  @end;
  64.  
  65.  @begin Object "WJava_powersoft__dot__jcm__dot__ui__dot__Label"
  66.   Font "<Inherited>";
  67.   BackColor "Color.lightGray";
  68.   ForeColor "Color.black";
  69.   Text "S&erver:";
  70.   Visible "1";
  71.   DataSource "NULL";
  72.   DataColumns "";
  73.   BoundControl "0";
  74.   ResID 101;
  75.   DesignName label_1;
  76.   TabIndex 1;
  77.   DesignRect 5,5,40,15;
  78.  @end;
  79.  
  80.  @begin Object "WJava_powersoft__dot__jcm__dot__ui__dot__TextBox"
  81.   Font "<Inherited>";
  82.   PasswordCharacter "0";
  83.   BackColor "Color.white";
  84.   ForeColor "Color.black";
  85.   Text "";
  86.   Visible "1";
  87.   DataSource "NULL";
  88.   DataColumns "";
  89.   BoundControl "0";
  90.   ResID 102;
  91.   DesignName textb_1;
  92.   TabIndex 2;
  93.   DesignRect 5,20,145,15;
  94.  @end;
  95.  
  96.  @begin Object "WJava_powersoft__dot__jcm__dot__ui__dot__CommandButton"
  97.   Font "<Inherited>";
  98.   BackColor "Color.lightGray";
  99.   ForeColor "Color.black";
  100.   Text "&Connect";
  101.   Visible "1";
  102.   DataSource "NULL";
  103.   DataColumns "";
  104.   BoundControl "0";
  105.   @begin Event "Click"
  106.    GencodeSrcLine 246;
  107.    FunctionName "cb_1_Click";
  108.   @end;
  109.   ResID 103;
  110.   DesignName cb_1;
  111.   TabIndex 3;
  112.   DesignRect 155,20,40,14;
  113.  @end;
  114.  
  115.  @begin Object "WJava_powersoft__dot__jcm__dot__ui__dot__CommandButton"
  116.   Font "<Inherited>";
  117.   BackColor "Color.lightGray";
  118.   ForeColor "Color.black";
  119.   Text "&Disconnect";
  120.   Visible "1";
  121.   DataSource "NULL";
  122.   DataColumns "";
  123.   BoundControl "0";
  124.   @begin Event "Click"
  125.    GencodeSrcLine 260;
  126.    FunctionName "cb_2_Click";
  127.   @end;
  128.   ResID 104;
  129.   DesignName cb_2;
  130.   TabIndex 4;
  131.   DesignRect 200,20,45,14;
  132.  @end;
  133.  
  134.  @begin Object "WJava_powersoft__dot__jcm__dot__ui__dot__ListBox"
  135.   Font "<Inherited>";
  136.   Sort "0";
  137.   DataTrackRow "0";
  138.   DataBindAsLookup "0";
  139.   DataLookupSource "NULL";
  140.   DataLookupColumns "";
  141.   BackColor "Color.white";
  142.   ForeColor "Color.black";
  143.   Text "";
  144.   Visible "1";
  145.   DataSource "NULL";
  146.   DataColumns "";
  147.   BoundControl "0";
  148.   ResID 105;
  149.   DesignName lb_1;
  150.   TabIndex 5;
  151.   DesignRect 5,55,200,75;
  152.  @end;
  153.  
  154.  @begin Object "WJava_powersoft__dot__jcm__dot__ui__dot__Label"
  155.   Font "<Inherited>";
  156.   BackColor "Color.lightGray";
  157.   ForeColor "Color.black";
  158.   Text "&Log:";
  159.   Visible "1";
  160.   DataSource "NULL";
  161.   DataColumns "";
  162.   BoundControl "0";
  163.   ResID 106;
  164.   DesignName label_2;
  165.   TabIndex 6;
  166.   DesignRect 5,40,30,15;
  167.  @end;
  168.  
  169.  @begin Object "WJava_powersoft__dot__jcm__dot__ui__dot__CommandButton"
  170.   Font "<Inherited>";
  171.   BackColor "Color.lightGray";
  172.   ForeColor "Color.black";
  173.   Text "C&lear";
  174.   Visible "1";
  175.   DataSource "NULL";
  176.   DataColumns "";
  177.   BoundControl "0";
  178.   @begin Event "Click"
  179.    GencodeSrcLine 269;
  180.    FunctionName "cb_3_Click";
  181.   @end;
  182.   ResID 107;
  183.   DesignName cb_3;
  184.   TabIndex 7;
  185.   DesignRect 210,55,40,14;
  186.  @end;
  187.  
  188.  @begin Object "WJava_powersoft__dot__jcm__dot__ui__dot__TextBox"
  189.   WTextBoxMultiLine 1;
  190.   Font "<Inherited>";
  191.   PasswordCharacter "0";
  192.   BackColor "Color.white";
  193.   ForeColor "Color.black";
  194.   Text "";
  195.   Visible "1";
  196.   DataSource "NULL";
  197.   DataColumns "";
  198.   BoundControl "0";
  199.   ResID 108;
  200.   DesignName textb_2;
  201.   TabIndex 8;
  202.   DesignRect 5,150,200,50;
  203.  @end;
  204.  
  205.  @begin Object "WJava_powersoft__dot__jcm__dot__ui__dot__Label"
  206.   Font "<Inherited>";
  207.   BackColor "Color.lightGray";
  208.   ForeColor "Color.black";
  209.   Text "&Message:";
  210.   Visible "1";
  211.   DataSource "NULL";
  212.   DataColumns "";
  213.   BoundControl "0";
  214.   ResID 109;
  215.   DesignName label_3;
  216.   TabIndex 9;
  217.   DesignRect 5,135,45,15;
  218.  @end;
  219.  
  220.  @begin Object "WJava_powersoft__dot__jcm__dot__ui__dot__CommandButton"
  221.   Font "<Inherited>";
  222.   BackColor "Color.lightGray";
  223.   ForeColor "Color.black";
  224.   Text "&Send";
  225.   Visible "1";
  226.   DataSource "NULL";
  227.   DataColumns "";
  228.   BoundControl "0";
  229.   @begin Event "Click"
  230.    GencodeSrcLine 276;
  231.    FunctionName "cb_4_Click";
  232.   @end;
  233.   ResID 110;
  234.   DesignName cb_4;
  235.   TabIndex 10;
  236.   DesignRect 210,150,40,14;
  237.  @end;
  238.  
  239.  @begin HPPPrefixBlock
  240. @begin-code HPPPrefix
  241.  
  242. // add your custom import statements here
  243.  
  244. @end-code;
  245.   GencodeSrcLine 16;
  246.  @end;
  247.  
  248.  @begin ClassContentsBlock
  249. @begin-code ClassContents
  250.  
  251.     private final int MAX_BUFFER_SIZE = 512;
  252.  
  253.     private int _line_number;
  254.     private int _lines_to_send;
  255.  
  256.     private int _recv_buffer_index = 0;
  257.     private byte[] _recv_buffer = new byte[ MAX_BUFFER_SIZE ];
  258.  
  259. @end-code;
  260.   GencodeSrcLine 316;
  261.  @end;
  262.  
  263. @begin-code BaseClassList
  264.  
  265. extends powersoft.jcm.ui.Applet
  266.  
  267. @end-code;
  268.  
  269. @begin-code GeneratedClassContents
  270.  
  271.  
  272. @end-code;
  273.  
  274. @begin-code Code "Form2::Form2(powersoft.jcm.ui.AWTAppletEx applet)"
  275.  
  276.     public @CLASSNAME@(powersoft.jcm.ui.AWTAppletEx applet)
  277.     {
  278.         super(applet);
  279.     }
  280.  
  281. @end-code;
  282.  
  283. @begin-code Code "Form2_Create"
  284.  
  285.     public boolean Form2_Create(powersoft.jcm.event.CreateEvent event)
  286.     {
  287.         textb_1.setText( socket_1.getLocalHostName() );    
  288.         
  289.         return false;
  290.     }
  291.  
  292. @end-code;
  293.  
  294. @begin-code Code "Form2_Destroy"
  295.  
  296.     public boolean Form2_Destroy(powersoft.jcm.event.DestroyEvent event)
  297.     {
  298.         if ( socket_1.getType() ==
  299.                  powersoft.jcm.net.Socket.SockSTREAM ) {
  300.             socket_1.close();    
  301.         }
  302.         
  303.         return false;
  304.     }
  305.  
  306. @end-code;
  307.  
  308. @begin-code Code "socket_1_SocketConnect"
  309.  
  310.     public boolean socket_1_SocketConnect(powersoft.jcm.event.SocketConnectEvent event)
  311.     {
  312.         lb_1.add( "Connected." );    
  313.         
  314.         return false;
  315.     }
  316.  
  317. @end-code;
  318.  
  319. @begin-code Code "socket_1_SocketDataArrival"
  320.  
  321.     public boolean socket_1_SocketDataArrival(powersoft.jcm.event.SocketDataArrivalEvent event)
  322.     {
  323.         int bytes_read;
  324.         byte[] buffer = new byte[ MAX_BUFFER_SIZE ];
  325.         byte b;
  326.         String line;
  327.  
  328.         //lb_1.add( "Data arrival " + event.getBytesReceived() );
  329.         bytes_read = socket_1.receive( buffer, event.getBytesReceived() );
  330.         if ( bytes_read < 0 ) {
  331.             lb_1.add( "*** Receive error!" );
  332.         } else {
  333.             for ( int i = 0; i < bytes_read; i += 1 ) {
  334.                 b = buffer[i];
  335.                 if ( b == '\n' ) {
  336.                     _recv_buffer[ _recv_buffer_index ] = 0;
  337.                     line = new String( _recv_buffer, 0, 0, _recv_buffer_index );
  338.                     lb_1.add( line );
  339.                     _recv_buffer_index = 0;
  340.                 } else if ( b == 0 ) {
  341.                 } else {
  342.                     _recv_buffer[ _recv_buffer_index++ ] = b;
  343.                 }
  344.             }
  345.         }
  346.         
  347.         return false;
  348.     }
  349.  
  350. @end-code;
  351.  
  352. @begin-code Code "socket_1_SocketError"
  353.  
  354.     public boolean socket_1_SocketError(powersoft.jcm.event.SocketErrorEvent event)
  355.     {
  356.         byte error = event.getError();
  357.         
  358.         if ( error != powersoft.jcm.net.Socket.SockEIsCreated ) {
  359.             lb_1.add( "*** Socket Error: " + error ); 
  360.         }
  361.         
  362.         return false;
  363.     }
  364.  
  365. @end-code;
  366.  
  367. @begin-code Code "socket_1_SocketHostResolved"
  368.  
  369.     public boolean socket_1_SocketHostResolved(powersoft.jcm.event.SocketHostResolvedEvent event)
  370.     {
  371.         lb_1.add( "Host resolved.  Connecting..." );
  372.         socket_1.connect();
  373.         
  374.         return false;
  375.     }
  376.  
  377. @end-code;
  378.  
  379. @begin-code Code "socket_1_SocketSendComplete"
  380.  
  381.     public boolean socket_1_SocketSendComplete(powersoft.jcm.event.SocketSendCompleteEvent event)
  382.     {
  383.         textb_2.setText( "" );
  384.         
  385.         return false;
  386.     }
  387.  
  388. @end-code;
  389.  
  390. @begin-code Code "cb_1_Click"
  391.  
  392.     public boolean cb_1_Click(powersoft.jcm.event.ClickEvent event)
  393.     {
  394.         String host = textb_1.getText();
  395.  
  396.         socket_1.create( powersoft.jcm.net.Socket.SockSTREAM );
  397.         if ( socket_1.getRemotePort() != 1777 ) {
  398.             socket_1.setRemotePort( 1777 );
  399.         }
  400.         socket_1.setRemoteHostName( host );
  401.         lb_1.add( "Looking up " + host );
  402.         
  403.         return false;
  404.     }
  405.  
  406. @end-code;
  407.  
  408. @begin-code Code "cb_2_Click"
  409.  
  410.     public boolean cb_2_Click(powersoft.jcm.event.ClickEvent event)
  411.     {
  412.         if ( socket_1.close() ) {
  413.             lb_1.add( "Connection closed." );
  414.         }
  415.         
  416.         return false;
  417.     }
  418.  
  419. @end-code;
  420.  
  421. @begin-code Code "cb_3_Click"
  422.  
  423.     public boolean cb_3_Click(powersoft.jcm.event.ClickEvent event)
  424.     {
  425.         lb_1.deleteAll();    
  426.         
  427.         return false;
  428.     }
  429.  
  430. @end-code;
  431.  
  432. @begin-code Code "cb_4_Click"
  433.  
  434.     public boolean cb_4_Click(powersoft.jcm.event.ClickEvent event)
  435.     {
  436.         byte[] buffer = new byte[ MAX_BUFFER_SIZE ];
  437.         int len;
  438.         String msg;
  439.         
  440.         _line_number = 0;
  441.         _lines_to_send = textb_2.getLineCount();
  442.       //if ( _line_number < _lines_to_send ) {
  443.             msg = textb_2.getText();
  444.             // There is no getText( int ) method for TextBox
  445.             // right now; for now
  446.             // extract _line_number line from msg
  447.             len = msg.length();
  448.             msg = msg + "\n";
  449.             len += 1;
  450.             msg.getBytes( 0, len, buffer, 0 );
  451.             socket_1.send( buffer, len );
  452.       //}
  453.         
  454.         return false;
  455.     }
  456.  
  457. @end-code;
  458. @end;
  459.