home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 October / Chip_1997-10_cd.bin / tema / sybase / powerj / samples.z / form2.wxf < prev    next >
Text File  |  1997-01-28  |  11KB  |  461 lines

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