Pamela Ng

Greenhorn
+ Follow
since Dec 20, 2008
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Pamela Ng

Originally posted by Graeme Byers:
"StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code. It is recommended that anyone seeking this functionality use the split method of String or the java.util.regex package instead."

jdk6[/b]/doc/api/java/util/StringTokenizer.html]http://today.java.net/download/jdk6/doc/api/java/util/StringTokenizer.html



So how to do it with split method? Sorry, not very good with java...
13 years ago
Hi,

I have a method which returns a String array of elements, i am going to display in a JList. I use a JSplitPane, the Left Side contains a JTree put in a JScrollPane, the Right Side contains the list of elements from the String array.

How to count the elements using the StringTokenizer? I count the elements from the String array using another method, calling the getElements() method which i created previously.

When i count the elements, i only want to count the Map element once, then the rest, i just skip it and don't include in my counting, i also do not want to display the elements. The count i mean here is counting the total number of elements and accumulate it.

So expected output will be something like this:
Map
mapID
simulationID
mapName
mapDesc
mapLength
mapWidth
mapScale
JunctionList
Junction
junctionID
JunctionList
Junction
junctionType
JunctionList
Junction
xJunction
JunctionList
Junction
yJunction
JunctionList
Junction
jConnectedTo
JunctionList
Junction
jConnectedRoadIn
JunctionList
Junction
TrafficLightList
TrafficLight
trafficID
JunctionList
Junction
TrafficLightList
TrafficLight
trafficType
JunctionList
Junction
TrafficLightList
TrafficLight
xTraffic
JunctionList
Junction
TrafficLightList
TrafficLight
yTraffic
...
...
...
(output not complete)

However, now i found it quite wierd that some elements in between do not show up too.

Currently my output now:
mapID
simulationID
mapName
mapDesc
mapLength
mapWidth
mapScale
JunctionList
junctionID
JunctionList
junctionType
JunctionList
xJunction
JunctionList
yJunction
JunctionList
jConnectedTo
JunctionList
jConnectedRoadIn
JunctionList
TrafficLightList
trafficID
JunctionList
TrafficLightList
trafficType

Why Junction and TrafficLight element are missing?

I just add one more line of code which is:


The codings are as follows:



The code to count the elements:



Any idea what is wrong?
How should i modify my code?
13 years ago
Hi,

Is there a way to just show part of a tree, as in a subtree. I use a JTree to create for eg:

- Map
|___- mapID
|______M2
- simulationID
|______S01
- mapDesc
|______None
- mapLength
|______490
- mapWidth
|______800
- mapScale
|______Scale_25000
- JunctionList
|______- Junction
|______- junctionID
|______- R10
|______- junctionType
|______- ROAD_TYPE_JUNCTION
......
......
|______- jConnectedTo
|______- BS5
......

The JTree is read from an XML document. And it can change dynamically depending on the XML document read, the JTree will show accordingly. There are somemore subnodes for Junction element, but for example, i want to stop at junctionType node. How do i do that? I have read several examples from other forums and tried but to no avail.

Another question: After i display this subtree, i want to link and display the remaining subtree by clicking a button, again display a small section of the subtree, by a count of 10 nodes by a refresh of the JTree. IThe count of nodes i mean by counting the main nodes, those nodes with + or -, Is it possible to do so? How do i do it? The examples i read online only give me the solution for displaying the whole tree and not part of a tree.

Help very much appreciated.
13 years ago