import java.applet.*;
import java.awt.*;
import java.io.*;
import java.net.*;
import java.awt.image.*;
import java.util.*;
import java.lang.*;



public class BSCOutline extends Applet   
{
        private Image			P_Icon[];
        private String			P_OutlineFile = "outline.out";
        private Color			P_FontColour = Color.black;
        private Color			P_BackColour = Color.white;
        private Color			P_SelectColour = Color.red;
        private String			P_Target = "_top";
        private boolean			P_ShowLines = true;
        private boolean			P_ShowIcons = true;

        private int				SelectedNode = 0;
        public int				NumLines;
        private String			Title[];
        private int				Level[];
        private int				Icon[];
        private int				CodFunc[];
        private boolean			Hidden[];
        private int				Map[];
        private String			JumpToURL[];
        private boolean			Wider[];

        private boolean			ImagesLoaded;
        private MediaTracker	img_tracker;
        private int				NumImages;

        private int				MaxWidth;
        private int				MaxHeight;
        private int				LineHeight;
        private int				IndentSize;
        private Font			NewFont;
        private Image			Buf;
        private Graphics		gBuf;
        private int				FontDescent;
        private int				Width, Height;
        private int				BH;
        private int				dy, dx;
        private Scrollbar		vBar, hBar;
        private boolean			ShowHSB = false;
        private int				ShowIt = 0;
        private int				FoldIcons;
        TextField tfMessage = new TextField();
        int paramDepart;
        //Applet Max Values
        //Set these to whatever you think is the max you need.
        //(The smaller the better for speed)
        private int				MaxIcons = 100;
        private int				MaxNodes = 1601;

        public BSCOutline()
        {
        }

        public String[][] getParameterInfo()
        {
                String[][] info =
                {
                        { "FoldXO", "String", "Icon Filename relative to Outline.Class file, X is Icon number" },
                        { "FoldXC", "String", "Icon Filename relative to Outline.Class file, X is Icon number" },
                        { "IconX", "String", "Icon Filename relative to Outline.Class file, X is Icon number" },
                        { "OutlineFile", "String", "Outline Data Filename" },
                        { "FontFace", "String", "Font Name e.g. Arial" },
                        { "FontStyle", "int", "Font Style, 1=Bold, 2=Italic, 3=Bold/Italic" },
                        { "FontSize", "int", "Font Size in Points" },
                        { "FontColour", "String", "Font Colour in Hexidecimal RGB e.g. FFFFFF for black" },
                        { "BackColour", "String", "Background Colour in Hexidecimal RGB e.g. 000000 for white" },
                        { "SelectColour", "String", "Selection Colour in Hexidecimal RGB e.g. 000000 for white" },
                        { "ShowLines", "String", "1 Shows Lines, 0 Hides" },
                        { "ShowIcons", "String", "1 Shows Icons, 0 Hides" },
                        { "DataX", "String", "Data Lines, X is line number" },
                        { "License", "String", "Registration code" },
                        { "Target", "String", "Target Frame" }
                };
                return info;		
        }

        public String getAppletInfo()
        {
                return "Name: BSCOutline v2.20\r\n" +
                                "Author: Simon Daykin\r\n" +
                                "Company: Byte-Sized Computing\r\n" +
                                "e-mail : Simon@Byte-Sized.com\r\n" +
                                "Date   : 31st December 1997\r\n" +
                                "Copyright 1996-1998 Byte-Sized Computing";
        }


        public void init() 
        {
                String			P_FontFace = "Arial";
                int				P_FontStyle = 0;
                int				P_FontSize = 12;
                //Get the images
                setLayout(new BorderLayout());
                GetIcons();

                String param = getParameter("OutlineFile");
                if (param != null)
                        P_OutlineFile = param;

                param = getParameter("FontFace");
                if (param != null)
                        P_FontFace = param;
 
                param = getParameter("FontStyle");
                if (param != null) 
                        P_FontStyle = Integer.parseInt(param);

                param = getParameter("FontSize");
                if (param != null)
                        P_FontSize = Integer.parseInt(param);

                param = getParameter("FontColour");
                if (param != null)
                        P_FontColour = new Color(Integer.parseInt(param, 16));

                param = getParameter("BackColour");
                if (param != null)
                        P_BackColour = new Color(Integer.parseInt(param, 16));

                param = getParameter("SelectColour");
                if (param != null)
                        P_SelectColour = new Color(Integer.parseInt(param, 16));

                param = getParameter("Target");
                if (param != null)
                        P_Target = param;

                param = getParameter("ShowLines");
                if (param != null) {
                        P_ShowLines = ((Integer.parseInt(param) == 1)) ? true : false;
                }

                param = getParameter("ShowIcons");
                if (param != null) {
                        P_ShowIcons = ((Integer.parseInt(param) == 1)) ? true : false;
                }


                String sParam;
                sParam = getParameter("codDepto");
                Integer auxParam = new Integer(sParam);
                paramDepart = auxParam.intValue();	
        //----------------------------------------------------------------------
                // Define other arrays
                Title = new String[MaxNodes];
                JumpToURL = new String[MaxNodes];
                Level = new int[MaxNodes];
                Icon = new int[MaxNodes];
                Hidden = new boolean[MaxNodes];
                Map = new int[MaxNodes];
                Wider = new boolean[MaxNodes];
                CodFunc = new int[MaxNodes];

  
        Width = size().width;
        Height = size().height;

                Font NewFont = new Font(P_FontFace, P_FontStyle, P_FontSize);
                LineHeight =  (getFontMetrics(NewFont).getHeight())+4;
                IndentSize = (P_ShowLines == true) ? LineHeight : LineHeight/2;
                BH = LineHeight/4;
                FontDescent = (getFontMetrics(NewFont).getDescent());

                //input data
                LoadLines();
//		parseFile();
                inicializaValores();
                CheckIcons();

                for (int i=1; i<=NumLines; i++) {
                        int CurrentWidth = ((1+Level[i])*LineHeight);
                        CurrentWidth += getFontMetrics(NewFont).stringWidth(Title[i]);
                        Wider[i] = (CurrentWidth > Width);
                        if (CurrentWidth > MaxWidth) MaxWidth = CurrentWidth;
                }

                if (MaxWidth<Width) MaxWidth=Width;
                MaxWidth +=16;

                if (Height > ((NumLines+1)*LineHeight) ){
                        MaxHeight = Height;
                }
                else {
                        MaxHeight = ((NumLines+1)*LineHeight);
                }

  
        Buf = createImage(MaxWidth, MaxHeight);
        gBuf = Buf.getGraphics();

                gBuf.setFont(NewFont);
                // Set up scroll bars
                vBar = new Scrollbar(Scrollbar.VERTICAL, 0, Height, 0, (MaxHeight-Height));
                hBar = new Scrollbar(Scrollbar.HORIZONTAL, 0, Width, 0, (MaxWidth-Width));
                setLayout(null);
                add(vBar);
                add(hBar);
                vBar.hide();
                hBar.hide();
                vBar.reshape(Width-16,0,16,Height);
                hBar.reshape(0,Height-16,Width-16,16);
                vBar.setValues(vBar.getValue(), Height, 0,(MaxHeight-Height)+16)	;
                hBar.setValues(hBar.getValue(), Width, 0, (MaxWidth-Width)+16);
                vBar.setLineIncrement(LineHeight);
                vBar.setPageIncrement(Height);
                hBar.setLineIncrement(IndentSize);
                hBar.setPageIncrement(Width);
                setLayout(new BorderLayout());
                Panel p = new Panel();
                Label l = new Label("batata");
                p.add(l);
                p.add(tfMessage);
//                add("South",p);		

        }// end init()

        public boolean handleEvent(Event e) {
                if (e.target == vBar) {
                        dy = vBar.getValue();
                        repaint();
                }
                else if (e.target == hBar) {
                        dx = hBar.getValue();
                        repaint();
                }
                return super.handleEvent(e);
        }


        public void destroy()
        {
                gBuf.dispose();
        }

        public void paint(Graphics g)
        {
                if (ImagesLoaded) {
                        PaintTree(g);
                }
                else {
                        g.setColor(P_BackColour);
                        g.fillRect(0,0,MaxWidth, MaxHeight);
                        //DrawLogo(g);
                        g.setColor(P_FontColour);
                        g.drawString("Loading Images...", 10, 40);
                        g.drawRect(10,60,size().width-20,20);

                        // Count Images Left to load	
                        int Count;
                        Count=0;
                        while (Count < NumImages) {
                                Count=0;
                                for(int i=0; i<NumImages; i++){
                                        Count += (img_tracker.checkID(i,true) ? 1 : 0);
                                }
                                g.fillRect(12,62,(((size().width-24)/NumImages)*Count),17);
                        }
                        //destroy tracker
                        img_tracker = null;
                        ImagesLoaded = true;
                        PaintTree(g);
                }
        }

        public void PaintTree(Graphics g)
        {
                ShowIt = 0;
                int CurrentX, CurrentY, CurrentLevel;
                ShowHSB = false;
  
                gBuf.setColor(P_BackColour);
                gBuf.fillRect(0,0,MaxWidth, MaxHeight);

                gBuf.setColor(P_FontColour);

                Map = new int[MaxNodes];

                for (int i=1; i<=NumLines; i++){
                        if (!Hidden[i]){
                                ShowIt++;
                                Map[ShowIt] = i;
                                CurrentX = (P_ShowLines == true) ? (Level[i]) * IndentSize : (Level[i]-1) * IndentSize;
                                CurrentY = (ShowIt - 1) * LineHeight;
                                if (i <= NumLines){
                                        if (P_ShowIcons == true) {
                                                gBuf.drawImage(P_Icon[Icon[i]], CurrentX+3, CurrentY+1, (LineHeight-2), (LineHeight-2), P_BackColour, this);
                                                CurrentX += LineHeight;
                                                CurrentY += 2;
                                        }
                                        CurrentX += 4;
                                        CurrentY += (LineHeight - FontDescent - 3);
                                        if ((i==SelectedNode) || (HiliteParent(i))) {
                                                gBuf.setColor(P_SelectColour);
                                        }
                                        else {
                                                gBuf.setColor(P_FontColour);
                                        }
                                        gBuf.drawString (Title[i], CurrentX, CurrentY);
                                        gBuf.setColor(P_FontColour);
                                        ShowHSB = (Wider[i]) ? true : ShowHSB;
                                } //End if
                        }
                        else {
                                CurrentLevel = Level[i];
                                while ((Level[i] > (CurrentLevel-1)) && (i <= NumLines)) i++;
                                i--;
                        } //End else
                } //End for
  
                int i=1;
                while ((Map[i]>0) && (i<=ShowIt)) {
                        if (P_ShowLines == true) {
                                // Draw + - Box
                                CurrentX = (Level[Map[i]]) * IndentSize;
                                CurrentY = (i-1) * LineHeight;
                                if (Level[Map[i]+1] > Level[Map[i]]) {
                                        gBuf.drawRect(CurrentX-(3*BH), CurrentY+BH, BH+BH, BH+BH);
                                        gBuf.drawLine(CurrentX-(3*BH)+2, CurrentY+BH+BH, CurrentX-BH-2, CurrentY+BH+BH);
                                        if (Hidden[Map[i]+1]) gBuf.drawLine(CurrentX-BH-BH, CurrentY+BH+2, CurrentX-BH-BH, CurrentY+BH+BH+BH-2); 
                                        //Draw lines to box
                                        gBuf.drawLine(CurrentX-BH, CurrentY+BH+BH, CurrentX, CurrentY+BH+BH);
                                        if (Map[i] > 1) gBuf.drawLine(CurrentX-BH-BH, CurrentY, CurrentX-BH-BH, CurrentY+BH);
                                        if (Level[Map[i+1]] == Level[Map[i]]) gBuf.drawLine(CurrentX-BH-BH, CurrentY+(3*BH), CurrentX-BH-BH, CurrentY+LineHeight);
                                }
                                else {//Draw Lines
                                        gBuf.drawLine(CurrentX-BH-BH, CurrentY+BH+BH, CurrentX, CurrentY+BH+BH);
                                        if ((Level[Map[i+1]] == Level[Map[i]]) && ((i+1) <= ShowIt) && (i>=2)) {
                                                gBuf.drawLine(CurrentX-BH-BH, CurrentY, CurrentX-BH-BH, CurrentY+LineHeight);
                                        }
                                        else{ // must be last corner!
                                                if (i >=2 ){ // must be last corner!
                                                        gBuf.drawLine(CurrentX-BH-BH, CurrentY, CurrentX-BH-BH, CurrentY+BH+BH);
                                                }
                                                if (i == 1){ // must be First corner!
                                                        gBuf.drawLine(CurrentX-BH-BH, CurrentY+BH+BH, CurrentX-BH-BH, CurrentY+BH+LineHeight);
                                                }
                                        }
                                }
                        }//end if showlines
                        i++;	
                }//end while

                vBar.setValues(vBar.getValue(), Height, 0,(((ShowIt+1)*LineHeight)-Height))	;
//		hBar.setValues(hBar.getValue(), Width, 0,(MaxWidth-Width))	;

                if (ShowHSB) {
                        hBar.show(); 
                }
                else {
                        hBar.hide();
                        dx=0;
                }

                if (((ShowIt+1)*LineHeight) > Height) {
                        vBar.show(); 
                }
                else {
                        vBar.hide();
                        dy=0;
                }
  
                //Draw joiner lines for vertical
        if (P_ShowLines == true) {
                for (int a=ShowIt; a>0; a--) {
                        if (Level[Map[a-1]] > Level[Map[a]]) {
                                for (int p=a-1; p>0; p--) {
                                        if (Level[Map[p]] == Level[Map[a]]) {
                                                CurrentX = (Level[Map[a]]*IndentSize)-BH-BH;
                                                gBuf.drawLine(CurrentX, (a-1)*LineHeight, CurrentX, (p*LineHeight)-BH-2);
                                                p=0;
                                        }
                                }
                        }
                }
        }//end if showlines
        g.drawImage(Buf, -dx, -dy, this);
        } //End paint()

        public void update(Graphics g)
    {
        paint(g);//override because of flicker
    }

        private int ConvertX (int x){
                int X;
                X = ((int)((x+dx) / (IndentSize)));
                X += (P_ShowLines) ? 1:0;
                X += (P_ShowIcons) ? 1:0;
                return X;
        }

        private int ConvertY (int y){
                return ((int)((y+dy) / (LineHeight))) + 1;
        }

        public boolean mouseDown(Event evt, int x, int y)
        {
                int i;
                int X = ConvertX(x);
                int Y = ConvertY(y);

                if (
                        (X < Level[Map[Y]]) || 
                        (Hidden[Map[Y]]) || 
                        (Map[Y]==0) || 
                        ((x>(Width-16)) && ((((ShowIt+1)*LineHeight)>Height) || (dy>0))) ||
                        ((y>(Height-16)) && ShowHSB)
                        ){
                        //Do nothing!
                }		
                else {
                        // Do Something
                        boolean showURL = true;
                        if (((X <= (Level[Map[Y]]+(P_ShowLines ? 1:0)+(P_ShowIcons ? 1:0))) && (Level[Map[Y]+1]>Level[Map[Y]])) || (!(P_ShowLines) && !(P_ShowIcons))) {
                                i = Map[Y];
                                // change icon
                                if (Level[i+1] > Level[i]) Icon[i] = (Hidden[i+1]) ? Icon[i]+1: Icon[i]-1;
                                // Show or Hide Siblings
                                for (i++;((Level[i] >= (Level[Map[Y]]+1)) && (i <= NumLines));i++) {
                                        if (Level[i] == (Level[Map[Y]]+1)) 	Hidden[i] = !Hidden[i];
                                }
                                showURL = false;
                                if (!(P_ShowLines) && !(P_ShowIcons)) showURL = true;
                        } //End if
                        if (showURL) {
                                if (!(JumpToURL[Map[Y]].startsWith(" ") || (JumpToURL[Map[Y]].length() <= 1)) ) {
                                        //open URL!
                                        try { 
                                                getAppletContext().showDocument(new URL(getDocumentBase(), JumpToURL[Map[Y]]), P_Target);
                                                SelectedNode = Map[Y];
                                        }
                                        catch (Exception ex) {
                                        }
                                }
                        } //End if showURL
                        repaint();
                } //End Else

                return true;
        }


        public boolean mouseMove(Event  evt, int  x, int  y)
        {
                int Y = ConvertY(y);
                super.showStatus(JumpToURL[Map[Y]]);
                return true;
        }

    public boolean mouseExit(Event  evt, int  x, int  y)
        {
                super.showStatus("");
                return true;
        }

        private boolean HiliteParent(int i)
        {
                int CurNode=i;
                int CurLevel=Level[CurNode];
                boolean IsInChildren = false;
                for (CurNode++;((Level[CurNode] >= (CurLevel+1)) && (CurNode <= NumLines));CurNode++) 
                        if ((Level[CurNode] == (CurLevel+1)) && (Hidden[CurNode]) && (CurNode==SelectedNode)) IsInChildren=true;	
                return IsInChildren;
        }

        private void parseFile()
        {
                int initial=NumLines;
                boolean DataLines=true;
                while (DataLines) {
                        String param = getParameter("Data" + Integer.toString(NumLines - initial +1));
                        if (param != null){
                                NumLines++;
                                //format
                                // Level | Icon | Hidden | Text | URL |
                                int CurPos = 0;
                                int NextPipe = param.indexOf("|", CurPos);
                                Level[NumLines] = Integer.parseInt(param.substring(CurPos,NextPipe));
                                CurPos = NextPipe+1;
                                NextPipe = param.indexOf("|", CurPos);
                                Icon[NumLines] = Integer.parseInt(param.substring(CurPos,NextPipe));
                                CurPos = NextPipe+1;
                                NextPipe = param.indexOf("|", CurPos);
                                if (Integer.parseInt(param.substring(CurPos,NextPipe)) == 0)
                                        Hidden[NumLines] = false;
                                else
                                        Hidden[NumLines] = true;
                                CurPos = NextPipe+1;
                                NextPipe = param.indexOf("|", CurPos);
                                Title[NumLines] = param.substring(CurPos,NextPipe);
                                CurPos = NextPipe+1;
                                NextPipe = param.indexOf("|", CurPos);
                                JumpToURL[NumLines] = param.substring(CurPos,NextPipe);
                        }
                        else {
                                DataLines = false;
                        }
                }
                if (NumLines < 3) {

                        try {
                                InputStream is = new URL(getDocumentBase(), P_OutlineFile).openStream();
                                StreamTokenizer st = new StreamTokenizer(new BufferedInputStream(is));
                                st.slashStarComments(true);	
                                MaxWidth=0;

                                while (st.ttype != StreamTokenizer.TT_EOF) {
                                        NumLines++;
                                                st.nextToken();
                                                Level[NumLines] = (int)st.nval;
                                                st.nextToken();
                                                Icon[NumLines] = (int)st.nval;
                                                st.nextToken();
                                                if (st.nval == 0) Hidden[NumLines] = false;
                                                else Hidden[NumLines] = true;
                                                st.nextToken();
                                                Title[NumLines] = st.sval;
                                                st.nextToken();
                                                JumpToURL[NumLines] = st.sval;
                                                // Should be EOL
                                }// end of while
                                NumLines--;
                                is.close();
                        }
                        catch (Exception ex) {
                                System.out.println("Error Opening Outline DataFile");
                                showStatus("Error Opening Outline DataFile");
                                System.exit(1);
                        }
                } // end of in NumLines = 0
        }//end of parseFile

        private void CheckIcons(){
                //check icons
                for (int a=1; a<=NumLines; a++){
                        if (Level[a+1] > Level[a]) {
                                //must be folder!
                                if (Icon[a] >= FoldIcons){
                                        showStatus("Icon Error - " + Title[a] + " - Parent with Invalid Icon");
                                        Icon[a] = (Hidden[a + 1] == false) ? 2:1;
                                }
                                else {
                                        if (Icon[a]%2 == 0) {
                                                Icon[a] = (Hidden[a + 1] == false) ? Icon[a] : (Icon[a] += Icon[a]==0 ? 1 : -1);
                                        }
                                        else{
                                                Icon[a] = (Hidden[a + 1] == true) ? Icon[a] : (Icon[a] += Icon[a]==FoldIcons ? -1 : 1);
                                        }
                                }
                        }
                        else {
                                // must be higher than FoldIcons
                                if (Icon[a] < FoldIcons){
                                        showStatus("Icon Error - " + Title[a] + " - Child with Folder Icon");
                                        Icon[a] = FoldIcons;
                                }
                        }
                }
        }


        public void GetIcons()	{
                boolean MoreIcons=true;
                P_Icon = new Image[MaxIcons];
        img_tracker = new MediaTracker(this);
                FoldIcons = 1;
                int	i=1;

                //Get folder icons.
                while (MoreIcons) {
                        String param = getParameter("Fold" + Integer.toString(i)+"C");
                        if (param != null){
                                P_Icon[FoldIcons] = getImage(getDocumentBase(),param);
                                img_tracker.addImage(P_Icon[FoldIcons],i);
                                param = getParameter("Fold" + Integer.toString(i)+"O");
                                if (param != null){
                                        P_Icon[FoldIcons+1] = getImage(getDocumentBase(),param);
                                        img_tracker.addImage(P_Icon[FoldIcons+1],i+1);
                                }
                                FoldIcons +=2;
                                i +=1;
                        }
                        else {
                                MoreIcons = false;
                        }
                }
                //Get Document icons.
                MoreIcons = true;
                i=0;
                while (MoreIcons) {
                        String param = getParameter("Icon" + Integer.toString(i+1));
                        if (param != null){
                                P_Icon[FoldIcons + i] = getImage(getDocumentBase(),param);
                                img_tracker.addImage(P_Icon[FoldIcons + i],FoldIcons + i);
                                i += 1;
                        }
                        else {
                                MoreIcons = false;
                        }
                }
                NumImages = FoldIcons + i - 1; 
        }


        public void LoadLines()
        {
                String strHN = getCodeBase().getHost();
                if (strHN.length() < 2) strHN="local host";
                strHN = strHN.toLowerCase();
                boolean y = true;
                int iLic=0; 
                long num=1;
                String tmpStr;
                String cmp = "1z2y3x4w5v6u7t8s9r0qapbocndmelfkgjhi";
                String param = getParameter("License");
                if (param != null){
                        if (strHN.length() > 1) {
                                for (int a=0; a<=(strHN.length() - 2); a+=2){
                                        String tmp = strHN.substring(a,a+1);
                                        num = num * cmp.indexOf(tmp);
                                }
                        }
                        if (num < 0) num=-num;
                        tmpStr = Long.toString(num);
                        if (tmpStr.length() > 10 ){
                                tmpStr = tmpStr.substring(0,10);
                        }
                        if (param.equalsIgnoreCase(tmpStr)) y=false;
                }

        }


//PARTE DE ACESSO AO BANCO DE DADOS

Socket s = null;
ObjectInputStream input = null;
ObjectOutputStream output = null;
int size;
public void inicializaValores(){
	NumLines = 17;
       int max;
       int size=0;
       String sql1;
       Vector v1,vAux1;
       String nomefunc;
       String nivel;
       sql1 = "select a.nome_funcionario, b.descricao_cargo, b.nivel,a.cod_funcionario,c.cod_superior1 from funcionario a,cargo b,organograma c where a.cod_juncao = " + paramDepart + " and a.cod_cargo = b.cod_cargo and a.cod_funcionario = c.cod_funcionario and a.cod_funcionario in (select cod_funcionario from organograma)";
       v1 = executaSQL(sql1);
       preparaLista(v1);

}

int indexLista;

public void preparaLista(Vector v){
	int index;
	indexLista = 1;
	index = 2;
	size = v.size();
	ordenaLista(index,v);
}


public void ordenaLista(int index,Vector v){
        Vector vAux1;
        String nomeFunc;
        String nivel;
        String codFunc;
        String codSuper;
	String cargo;
        int intCodSuper;
	int intCodChave;
        vAux1 = (Vector)v.elementAt(index);	
        nomeFunc = vAux1.elementAt(0).toString();
        cargo = vAux1.elementAt(1).toString();
        nivel = vAux1.elementAt(2).toString();
        codFunc = vAux1.elementAt(3).toString();
	intCodChave = retornaInt(codFunc);
        colocaValores(nomeFunc,nivel,codFunc,cargo,indexLista);
        indexLista++;
        for(int i=3;i<size;i++){
                vAux1 = (Vector)v.elementAt(i);	
                codSuper = vAux1.elementAt(4).toString();
                intCodSuper = retornaInt(codSuper);
                if(intCodSuper==intCodChave){
			ordenaLista(i,v);
		}
        }


}

public Vector executaSQL(String sql) {
      Vector vSend = null;
      Vector vData = null;
      int numRows = 0;

      tfMessage.setText("Processando...");
      do {

          // Tenta uma conexão via socket
          try {
              s = new Socket("wobj",9999);
          }
          catch(Exception ex) {
              tfMessage.setText("Error: " + ex.getMessage());
              break;
          }

          // Obtém uma Stream para enviar os dados
          try {
              output = new ObjectOutputStream(s.getOutputStream());
          }
          catch(IOException ex) {
              tfMessage.setText("Error: " + ex.getMessage());
              closeSocket(s);
              break;
          }

          // Obtém uma Stream para receber os dados
          try {
              input = new ObjectInputStream(s.getInputStream());
          }
          catch(IOException ex) {
              tfMessage.setText("Error: " + ex.getMessage());
              closeOutputStream(output);
              closeSocket(s);
              break;
          }

          // Monta os dados a serem enviados
          vSend = new Vector();
          vSend.addElement("sun.jdbc.odbc.JdbcOdbcDriver");
          vSend.addElement("jdbc:odbc:vifu0010");
          vSend.addElement("vifu0010");
          vSend.addElement("vifu0010");
          vSend.addElement(sql);

          // Envia os dados ao servidor
          try {
              output.writeObject(vSend);
          }
          catch(Exception ex) {
              tfMessage.setText("Error: " + ex.getMessage());
              closeInputStream(input);
              closeOutputStream(output);
              closeSocket(s);
              break;
          }

          // Recebe os dados do servidor
          try {
              vData = (Vector)input.readObject();
          }
          catch(Exception ex) {
              tfMessage.setText("Error: " + ex.getMessage());
              closeInputStream(input);
              closeOutputStream(output);
              closeSocket(s);
              break;
          }

          numRows = vData.size();
          if (numRows == 0) {
              tfMessage.setText("Nenhum dado disponível");
              break;
          }

      } while(false);
    tfMessage.setText("Terminou .............");

     return vData;
}

private void closeSocket(Socket s) {
  try {
      s.close();
  }
  catch(Exception ex) {
  }
}

private void closeInputStream(InputStream stream) {
  try {
      stream.close();
  }
  catch(Exception ex) {
  }
}

private void closeOutputStream(OutputStream stream) {
  try {
      stream.close();
  }
  catch(Exception ex) {
  }
}



public void colocaValores(String nomefunc,String nivel,String codFunc,String cargo,int index){
       Integer aux1 = new Integer(nivel);
       Integer aux2 = new Integer(codFunc);
       cargo = cargo.trim();
       Level[index] = aux1.intValue();
       Icon[index] = 2;
       Hidden[index] = false;
       Title[index] = cargo + " - " + nomefunc;
       JumpToURL[index] = " ";
       CodFunc[index] = aux2.intValue();

}

public int retornaInt(String valor){
        Integer aux = new Integer(valor);
        return aux.intValue();
}


}//end of applet


