• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Printing Treemap, value and key in pop-up window

 
Lucian Botezatul
Greenhorn
Posts: 20
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49830
69
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49830
69
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you have User objects with a count of how many questions they have answered?
 
Lucian Botezatul
Greenhorn
Posts: 20
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49830
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That can still be implemented with User objects, but I hadn't realised you only have one user.
 
Lucian Botezatul
Greenhorn
Posts: 20
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic