aspose file tools*
The moose likes Java in General and the fly likes Printing Treemap, value and key in pop-up window Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Printing Treemap, value and key in pop-up window" Watch "Printing Treemap, value and key in pop-up window" New topic
Author

Printing Treemap, value and key in pop-up window

Lucian Botezatul
Greenhorn

Joined: Jan 08, 2011
Posts: 20

I have a Treemap and want to print the Values: and Keys to my window:



When i run the code, the values and keys from the Treemap are shown like this:




I tried with the Iterator (suggested here on forum)




The result looks better, but still have 2 Problems:

1. the text in my pop-up window looks the same, no changes.

QUESTION 1: HOW i get the changes inside my window ?

2. the changes from the iterator are show only on the console, and the squared bracket still there:


10 [Fragen: Ben 10 ]
9 [Fragen: Ben 9 ]
8 [Fragen: Ben 8.1 ]
7 [Fragen: Ben 7.1 ]
6 [Fragen: Ben 6.1 ]
5 [Fragen: Ben 5.1 ]
4 [Fragen: Ben 4.1 ]
3 [Fragen: --> Me Myself <-- ]
2 [Fragen: Ben 2.1 ]
1 [Fragen: Ben 1 ]

QUESTION 2: How i get the squared bracket away


i try to get something like this in my window:

10 Fragen: Ben 10
9 Fragen: Ben 9
8 Fragen: Ben 8.1
7 Fragen: Ben 7.1
6 Fragen: Ben 6.1
5 Fragen: Ben 5.1
4 Fragen: Ben 4.1
3 Fragen: --> Me Myself <--
2 Fragen: Ben 2.1
1 Fragen: Ben 1

Thanks
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36598
    
  16
Why are you using a new List every time? You are adding lots of single-member Lists. Why don't you create a Question class, which can encapsulate the question and answer? Then you can override its toString method to print what you want.
Also the numbers n1 n2 n3 look like awkward coding; that sort of thing can be very error-prone.

To find why you are getting [], you should look at the toString() method used by ArrayList.
Lucian Botezatul
Greenhorn

Joined: Jan 08, 2011
Posts: 20

Long story:
http://www.coderanch.com/t/522928/java/java/More-than-sorting-dupplicate-elimination

Short version:

have a quiz, where a lot of dummy users inside.

I dont know if i can encapsulate the question / answer because i try them to change randomly:

the n numbers are for the start values of the user, means n1 - user with one right answer .... n7, n71, users with 7 correct answers ...
this numbers are after each ten answers randomly increased, so if you run the quis you get after each 10 questions a list with the scores of the "other users".

thanks for the advice, i will change the names of the n - variables, for better code readability

in my Experiment_RF_Rnk1 class




in my actual class:



i think that a concept change would have as result the rewrite of my whole programm ?
maybe other ideas who dont need a big code change thanks
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36598
    
  16
Why don't you have User objects with a count of how many questions they have answered?
Lucian Botezatul
Greenhorn

Joined: Jan 08, 2011
Posts: 20

i have only ONE user, his answers are counted and shown in the list
the ohter users in the list are dummy users, where the answers increase randomly,
The ONE user who run the quiz should think that they are more active users at the same time and that he get each 10 questions the actual standings

Campbell i am not shure if i got that what you meaning right ?

Why don't you have User objects with a count of how many questions they have answered?



Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36598
    
  16
That can still be implemented with User objects, but I hadn't realised you only have one user.
Lucian Botezatul
Greenhorn

Joined: Jan 08, 2011
Posts: 20

If someone interested, i solved my problem, put the final code here in Forum:

http://www.coderanch.com/t/526309/java/java/Problems-printing-Treemap-nd-run
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Printing Treemap, value and key in pop-up window
 
Similar Threads
HELP - Stuck on a TreeMap key problem
Sort and create new Objects before using TreeMap
Marcus Green Exam #1 question
Problems printing a Treemap 2nd run
Parsing a hashtable