So far I have found that Swing UI thread should be used to send data to my
JTextArea.
I tried that and it didnt work.

Im assumming that Swing is too slow to process that output which id not
being sent very fast at all.

-----Original Message-----
From: Gregory, Carlton [mailto:[EMAIL PROTECTED]
Sent: Monday, January 12, 2004 1:47 PM
To: '[EMAIL PROTECTED]'
Subject: Swing Event Handler


The class below RunCommand is Observable the class after that is my
Observer. The Observer does not display the data until the below class
finishes executing not before. Is there a bug with the event handler using
Observable?
Any other ideas?

import java.io.*;
import java.util.*;
public class RunCommand extends Observable {

     static String drvltr = null;
     static String logon  = null;
     static String action = null;
     private static String v = null;
     
public RunCommand(String drive,String auth, String dbaction, Observer ob)
{
    drvltr = drive;
    logon =  auth +"@samsdb.gee as sysdba";
    action = dbaction;
    addObserver(ob);
    }
    
  public void run() {
        String s;
        boolean finished = false;
      while (!finished) {
        try {
           if (action.equals("down")) {
            String[] cmd = {drvltr + ":\\oracle\\ora81\\bin\\sqlplus.exe",
logon,"@C:\\temp\\downdb.sql"};
            Process p = Runtime.getRuntime().exec(cmd);
            
            BufferedReader stdInput = new BufferedReader(new 
                 InputStreamReader(p.getInputStream()));

            BufferedReader stdError = new BufferedReader(new 
                 InputStreamReader(p.getErrorStream()));

            
            // read the output from the command
            
            System.out.println("Here is the standard output of the
command:\n");
            while ((s = stdInput.readLine()) != null) {
                setChanged();
                notifyObservers(s);
                System.out.println(s);
            }
            
            // read any errors from the attempted command

            System.out.println("Here is the standard error of the command
(if any):\n");
            while ((s = stdError.readLine()) != null) {
                setChanged();
                notifyObservers(s);
                System.out.println(s);
            }
            
            
            finished = true;
        }
        
        if (action.equals("up")) {
             String[] cmd = {drvltr + ":\\oracle\\ora81\\bin\\sqlplus.exe",
logon,"@C:\\temp\\strtdb.sql"};
             Process p = Runtime.getRuntime().exec(cmd);
            BufferedReader stdInput = new BufferedReader(new 
                 InputStreamReader(p.getInputStream()));

            BufferedReader stdError = new BufferedReader(new 
                 InputStreamReader(p.getErrorStream()));

            
            // read the output from the command
            
            System.out.println("Here is the standard output of the
command:\n");
            while ((s = stdInput.readLine()) != null) {
                setChanged();
                notifyObservers(s);
                System.out.println(s);
            }
            
            // read any errors from the attempted command

            System.out.println("Here is the standard error of the command
(if any):\n");
            while ((s = stdError.readLine()) != null) {
                setChanged();
                notifyObservers(s);
                System.out.println(s);
            }
            
            
            finished = true;
            // run shutdown command
           
        } // end if
          
        } //end try
        catch (IOException e) {
            System.out.println("exception happened - here's what I know: ");
            e.printStackTrace();
            finished = true;
        } //end catch
        finished = true;
      } // end while
        
  } //end run
} // end class

The observer class is an inner class of a class that builds ther frame ,
panels, ect.,defined as:
class JInstallerTextArea extends JTextArea implements Observer
    {
        public JInstallerTextArea()
        {
            setRows(5);
            setColumns(20);
        }
        public void update(Observable o, Object str)
        {
            append(str.toString());
            append("\n");
         }
     }

_______________________________________________
Swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/swing
_______________________________________________
Swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/swing

Reply via email to