Try posting your question to the comp.java.programmer group
this list is about Java on Linux .
Cheers
chris
Mario Jorge Nunes Filipe wrote:
> Hi
>
> I'm creating an applet to show an outline in the form of a Jtree.
>
> I created a class outline that supposedly parses a string and creates
> the outline in memory, allowing me to write it out as string, or as a
> tree.
>
> The Outline class is in the attached file. I call this outline in the
> following way :
>
> out1 = new Outline("(No1,body1,(No2,Body2,(No3,Body3)),(No4,Body4))(No5,
> Body5)(No6, Body6)");
>
> DefaultMutableTreeNode root1 = out1.toTree();
> DefaultMutableTreeNode root2 = out1.toTree();
>
> When i run the above i only get
>
> No6
> No6
>
> and i was expecting to get
>
> No1
> No5
> No6
>
> What am i doing wrong ?
>
> I should add that i'm extremely newbie on this java thing and as such
> the code is horrible, uggly, probablu not very much OO, etc
>
> Thanks
> --
> Mario Filipe
> [EMAIL PROTECTED]
> http://neptuno.sc.uevora.pt/~mjnf
>
> ------------------------------------------------------------------------
> import java.awt.*;
> import java.awt.event.*;
> import javax.swing.*;
> import javax.swing.tree.*;
> import javax.swing.event.*;
> import javax.swing.JTree;
> import javax.swing.tree.DefaultMutableTreeNode;
> import javax.swing.tree.DefaultTreeModel;
>
> public class Outline{
> private Outline prev, next, child;
> private String title, body;
>
> private Outline(String source, Outline previous){
> int len = source.length();
> int ciclo = 0;
> int npars = 0;
> int initialPos = -1;
> int finalPos = -1;
> if (len != 0){ // Se a string é vazia, não vale a pena estar a fazer nada
>
> // Agora percorre-se a string toda á procura dos nós que são filhos da raiz
> while (ciclo < len){
> if (source.charAt(ciclo) == '('){
> npars ++;
> if (npars == 1 && initialPos == -1) initialPos = ciclo;
> }
> if (source.charAt(ciclo) == ')'){
> npars --;
> if (npars == 0 && finalPos == -1) finalPos = ciclo +1;
> }
> if (initialPos != -1 && finalPos != -1){
> // já se encontrou o que define um nó
> String no = new String(source.substring(initialPos, finalPos));
> int start = 1;
> int stop = no.indexOf(",");
> title = no.substring(start, stop);
> start = stop + 1;
> stop = no.indexOf(",", start);
> if (stop == -1) stop = no.length() -1;
> body = no.substring(start, stop);
> if (stop != no.length() -1) // tem filhos
> child = new Outline(no.substring(stop +1, no.length()-1));
> prev = previous;
> next = new Outline(source.substring(finalPos, source.length()), this);
> initialPos = -1;
> finalPos = -1;
> }
> ciclo ++;
> } // while
> }
> }
>
> public Outline(String source){
> int len = source.length();
> int ciclo = 0;
> int npars = 0;
> int initialPos = -1;
> int finalPos = -1;
> if (len != 0){ // Se a string é vazia, não vale a pena estar a fazer nada
>
> // Agora percorre-se a string toda á procura dos nós que são filhos da raiz
> while (ciclo < len){
> if (source.charAt(ciclo) == '('){
> npars ++;
> if (npars == 1 && initialPos == -1) initialPos = ciclo;
> }
> if (source.charAt(ciclo) == ')'){
> npars --;
> if (npars == 0 && finalPos == -1) finalPos = ciclo +1;
> }
> if (initialPos != -1 && finalPos != -1){
> // já se encontrou o que define um nó
> String no = new String(source.substring(initialPos, finalPos));
> int start = 1;
> int stop = no.indexOf(",");
> title = no.substring(start, stop);
> start = stop + 1;
> stop = no.indexOf(",", start);
> if (stop == -1) stop = no.length() -1;
> body = no.substring(start, stop);
> if (stop != no.length() -1) // tem filhos
> child = new Outline(no.substring(stop +1, no.length()-1));
> prev = null;
> next = new Outline(source.substring(finalPos, source.length()), this);
> initialPos = -1;
> finalPos = -1;
> }
> ciclo ++;
> } // while
>
> }
> }
>
> public String toString(){
> return null;
> }
>
> private DefaultMutableTreeNode toTree(DefaultMutableTreeNode myRoot){
> return null;
> }
>
> public DefaultMutableTreeNode toTree(){
> DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
> Outline here = this;
> while (here.prev != null) here = here.prev;
> while (here.next != null){
> System.out.println(here.title);
> here = here.next;
> }
> return root;
> }
>
> private DefaultMutableTreeNode toTree(int i){
> return null;
> }
>
> public Outline add(Outline Father, Outline Son){
> return null;
> }
>
> public Outline remove(Outline wich){
> return null;
> }
>
> public Outline edit (Outline wich){
> return null;
> }
>
> }
----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]