home *** CD-ROM | disk | FTP | other *** search
- Save Format v2.3(19971110)
- @begin Form "Form_Socket"
-
- @begin Object "Powersoft Java AWT 1.10::java.applet.Applet"
- DesignName Form_Socket;
- @begin ClassProperties
- @begin-code BaseClassList
-
- extends java.applet.Applet
-
- @end-code;
- @end;
- @begin Properties
- @begin DesignProperties
- Style "cf0000";
- DesignRect 29,59,328,230;
- @end;
- @begin ObjectProperties
- font "Dialog-Plain-12";
- LayoutManager "powersoft.powerj.ui.ResizePercentageLayout";
- foreground "java.awt.Color.black";
- background "java.awt.Color.lightGray";
- SerializationData "";
- @end;
- @end;
- @begin Events
- @begin Event "powersoft.powerj.event.Object.objectCreated"
- @begin-code SourceCode "powersoft.powerj.event.Object.objectCreated"
-
- public boolean Form_Socket_objectCreated(powersoft.powerj.event.EventData event)
- {
- textf_server.setText( "localhost" );
- textf_port.setText( String.valueOf( DEFAULT_PORT ) );
- cb_connect.requestFocus();
-
- return false;
- }
-
- @end-code;
- @end;
- @end;
- @begin UserFunctions
- @begin UserFunction "Form_Socket()"
- @begin Definition
- @begin-code SourceCode "Form_Socket()"
-
- public Form_Socket()
- {
- super();
- }
-
- @end-code;
- @end;
- @end;
- @begin UserFunction "processEvent(java.awt.AWTEvent event)"
- @begin Definition
- @begin-code SourceCode "processEvent(java.awt.AWTEvent event)"
-
- public void processEvent(java.awt.AWTEvent event)
- {
-
- defaultProcessEvent(event);
- }
-
- @end-code;
- @end;
- @end;
- @begin UserFunction "unhandledEvent( String listenerName, String methodName, java.lang.Object event )"
- @begin Definition
- @begin-code SourceCode "unhandledEvent( String listenerName, String methodName, java.lang.Object event )"
-
- public void unhandledEvent( String listenerName, String methodName, java.lang.Object event )
- {
-
- }
-
- @end-code;
- @end;
- @end;
- @begin UserFunction "getContentPane()"
- @begin Definition
- @begin-code SourceCode "getContentPane()"
-
- public java.awt.Container getContentPane()
- {
- return this;
- }
-
- @end-code;
- @end;
- @end;
- @end;
- @begin CodeBlocks
- @begin CodeBlock "HppPrefix"
- FunctionScope 1;
- @begin-code SourceCode "Imports()"
-
- // add your custom import statements here
-
- import java.net.*;
- import java.io.*;
- import powersoft.powerj.util.*;
-
- @end-code;
- @end;
- @begin CodeBlock "ClassContents"
- FunctionScope 1;
- @begin-code SourceCode "Data Members()"
-
- // add your data members here
- java.net.Socket _s;
- DataInputStream _input; // input to this socket from the server
- PrintStream _output; // output from this socket to the server
- StreamListener _listener; // listens for input from server using 'input'
- Debug _dbLog;
-
- public static final int DEFAULT_PORT = 1777;
-
-
- class StreamListener extends Thread
- {
-
- public StreamListener( DataInputStream input, java.awt.List outputArea ) {
- _input = input;
- _outputArea = outputArea;
- start();
- }
-
- public void run() {
- String msgFromServer;
-
- try {
- for(;;) {
- msgFromServer = _input.readLine(); // blocks on server.
- if( msgFromServer == null ) break;
- _outputArea.add( msgFromServer );
- }
- } catch( IOException e ) {
- _outputArea.add( e.toString() );
- } catch( NullPointerException e ) {
- _outputArea.add( e.toString() );
- _dbLog.log( e.getMessage() );
- e.printStackTrace();
- } finally {
- _outputArea.add( "Connection closed by server" );
- }
- }
- // add your data members here
- DataInputStream _input; // input to this socket from the server
- java.awt.List _outputArea;
-
- }
-
- @end-code;
- @end;
- @begin CodeBlock "GeneratedClassContents"
- FunctionScope 1;
- GeneratedFunction 1;
- @begin-code SourceCode "Not Applicable for Java()"
-
-
- @end-code;
- @end;
- @begin CodeBlock "CppPrefix"
- FunctionScope 1;
- GeneratedFunction 1;
- @begin-code SourceCode "Not Applicable for Java()"
-
-
- @end-code;
- @end;
- @end;
- @begin Objects
- @begin Object "Powersoft Java AWT 1.10::java.awt.TextField"
- DesignName textf_server;
- @begin Properties
- @begin DesignProperties
- ResID 100;
- DesignRect 5,20,140,14;
- @end;
- @begin ObjectProperties
- font "Dialog-Plain-12";
- foreground "java.awt.Color.black";
- background "java.awt.Color.white";
- SerializationData "";
- @end;
- @end;
- @end;
- @begin Object "Powersoft Java AWT 1.10::java.awt.TextField"
- DesignName textf_port;
- @begin Properties
- @begin DesignProperties
- ResID 100;
- TabIndex 1;
- DesignRect 155,20,45,14;
- @end;
- @begin ObjectProperties
- font "Dialog-Plain-12";
- foreground "java.awt.Color.black";
- background "java.awt.Color.white";
- SerializationData "";
- @end;
- @end;
- @end;
- @begin Object "Powersoft Java AWT 1.10::java.awt.Button"
- DesignName cb_connect;
- @begin Properties
- @begin DesignProperties
- ResID 100;
- TabIndex 2;
- DesignRect 210,20,50,14;
- @end;
- @begin ObjectProperties
- font "Dialog-Plain-12";
- foreground "java.awt.Color.black";
- background "java.awt.Color.lightGray";
- SerializationData "";
- label "Connect";
- @end;
- @end;
- @begin Events
- @begin Event "java.awt.event.Action.actionPerformed"
- @begin-code SourceCode "java.awt.event.Action.actionPerformed"
-
- public void cb_connect_actionPerformed( java.awt.event.ActionEvent event )
- {
- String hostName = textf_server.getText();
- Integer port = new Integer( textf_port.getText() );
-
- _dbLog = new Debug();
-
- try {
- _s = new java.net.Socket( hostName, port.intValue() );
- lb_1.add( "Connected to " + hostName);
- _input = new DataInputStream( _s.getInputStream() );
- _output = new PrintStream( _s.getOutputStream() );
- }
- catch ( UnknownHostException e) {
- _dbLog.log( "UnknownHostException thrown while creating socket." );
- }
- catch ( IOException e) {
- _dbLog.log( "IOException thrown while creating socket." );
- }
-
- _listener = new StreamListener( _input, lb_1 );
- }
-
- @end-code;
- @end;
- @end;
- @end;
- @begin Object "Powersoft Java AWT 1.10::java.awt.Button"
- DesignName cb_disconnect;
- @begin Properties
- @begin DesignProperties
- ResID 100;
- TabIndex 3;
- DesignRect 265,20,50,14;
- @end;
- @begin ObjectProperties
- font "Dialog-Plain-12";
- foreground "java.awt.Color.black";
- background "java.awt.Color.lightGray";
- SerializationData "";
- label "Disconnect";
- @end;
- @end;
- @begin Events
- @begin Event "java.awt.event.Action.actionPerformed"
- @begin-code SourceCode "java.awt.event.Action.actionPerformed"
-
- public void cb_disconnect_actionPerformed( java.awt.event.ActionEvent event )
- {
- try {
- _output.println( "Attempting to close client side socket" );
- _s.close();
- lb_1.add( "Disconnected successfully" );
- } catch( IOException e ) {
- _dbLog.log( "IOException while closing client side socket" );
- }
- }
-
- @end-code;
- @end;
- @end;
- @end;
- @begin Object "Powersoft Java AWT 1.10::java.awt.TextField"
- DesignName textf_msg;
- @begin Properties
- @begin DesignProperties
- ResID 100;
- TabIndex 4;
- DesignRect 5,60,265,14;
- @end;
- @begin ObjectProperties
- font "Dialog-Plain-12";
- foreground "java.awt.Color.black";
- background "java.awt.Color.white";
- SerializationData "";
- @end;
- @end;
- @end;
- @begin Object "Powersoft Java AWT 1.10::java.awt.Button"
- DesignName cb_send;
- @begin Properties
- @begin DesignProperties
- ResID 100;
- TabIndex 5;
- DesignRect 275,60,40,14;
- @end;
- @begin ObjectProperties
- font "Dialog-Plain-12";
- foreground "java.awt.Color.black";
- background "java.awt.Color.lightGray";
- SerializationData "";
- label "Send";
- @end;
- @end;
- @begin Events
- @begin Event "java.awt.event.Action.actionPerformed"
- @begin-code SourceCode "java.awt.event.Action.actionPerformed"
-
- public void cb_send_actionPerformed( java.awt.event.ActionEvent event )
- {
- // Dump the contents of the message text box to the output
- // stream i.e., to the socket on the server.
- _output.println( textf_msg.getText() );
- // Clear the message box.
- textf_msg.setText( "" );
-
- }
-
- @end-code;
- @end;
- @end;
- @end;
- @begin Object "Powersoft Java AWT 1.10::java.awt.List"
- DesignName lb_1;
- @begin Properties
- @begin DesignProperties
- ResID 100;
- TabIndex 6;
- DesignRect 5,100,310,70;
- @end;
- @begin ObjectProperties
- font "Dialog-Plain-12";
- foreground "java.awt.Color.black";
- background "java.awt.Color.white";
- SerializationData "";
- @end;
- @begin ComponentProperties "lb_1"
- @end;
- @end;
- @end;
- @begin Object "Powersoft Java AWT 1.10::java.awt.Label"
- DesignName label_1;
- @begin Properties
- @begin DesignProperties
- ResID 100;
- TabIndex 7;
- DesignRect 5,45,80,10;
- @end;
- @begin ObjectProperties
- font "Dialog-Plain-12";
- text "Message for server:";
- foreground "java.awt.Color.black";
- background "java.awt.Color.lightGray";
- SerializationData "";
- @end;
- @end;
- @end;
- @begin Object "Powersoft Java AWT 1.10::java.awt.Label"
- DesignName label_2;
- @begin Properties
- @begin DesignProperties
- ResID 100;
- TabIndex 8;
- DesignRect 5,85,35,10;
- @end;
- @begin ObjectProperties
- font "Dialog-Plain-12";
- text "Log:";
- foreground "java.awt.Color.black";
- background "java.awt.Color.lightGray";
- SerializationData "";
- @end;
- @end;
- @end;
- @begin Object "Powersoft Java AWT 1.10::java.awt.Label"
- DesignName label_3;
- @begin Properties
- @begin DesignProperties
- ResID 100;
- TabIndex 9;
- DesignRect 5,10,50,10;
- @end;
- @begin ObjectProperties
- font "Dialog-Plain-12";
- text "Server name:";
- foreground "java.awt.Color.black";
- background "java.awt.Color.lightGray";
- SerializationData "";
- @end;
- @end;
- @end;
- @begin Object "Powersoft Java AWT 1.10::java.awt.Label"
- DesignName label_4;
- @begin Properties
- @begin DesignProperties
- ResID 100;
- TabIndex 10;
- DesignRect 155,10,20,10;
- @end;
- @begin ObjectProperties
- font "Dialog-Plain-12";
- text "Port:";
- foreground "java.awt.Color.black";
- background "java.awt.Color.lightGray";
- SerializationData "";
- @end;
- @end;
- @end;
- @end;
- @end;
- @end;
-