Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-14-2008, 11:24 PM
Member
 
Join Date: Dec 2007
Posts: 34
saytri is on a distinguished road
Problem in java
I've got a problem with a score list. I am diplaying the scores of all the users who enter the game. The problem is that the score are not listed in an alligned form. The player names are displayed in a good way, but the scores are either displayed as only one word (i.e the score joined with the word example John90 or else when i tried to include a space between the name and the score, the scores are not displayed in an alligned form (they depend on the length of the name) eg:
John 90
Raymond 80
Jake 10
Charmaine 90


This is the piece of code used to display this (this is being displayed on a dialog box, and the text is called from a textfile to a TextArea):

Code:
try { JOptionPane.showMessageDialog(null, "You answered " + count + " out of " + questions.length + " questions correctly."); BufferedWriter out; String text = JOptionPane.showInputDialog(null, "Enter your name"); out = new BufferedWriter(new FileWriter("players.txt",true)); out.write(text);//Write out a string to the text file out.write(" "); // i tried to use this to make a space, but its making a space depending on the length of the player name out.write(String.valueOf(count)); out.newLine(); out.close(); }catch(IOException e){ System.out.println("There was a problem:" + e); }


Thanks for the help.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-15-2008, 03:10 AM
roots's Avatar
Moderator
 
Join Date: Jan 2008
Location: Dallas
Posts: 263
roots is on a distinguished road
Code:
// Instead of :: out.write(" "); // i .. out.write(getSpace(20- text.length())); // Here 20 is max length possible change accordingly ... public static String getSpace(int length){ String str = ""; for(int i = 0 ; i < length ; i++ ){ str = str + " " ; } return str ; }
Should align the score ..
__________________
dont worry newbie, we got you covered.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-15-2008, 04:48 PM
Member
 
Join Date: Dec 2007
Posts: 34
saytri is on a distinguished road
Hi thanks a lot for your response. I have understood what you have written, but it seems that its doing the same thing (i.e not alligning the score).

Thanks.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-15-2008, 10:04 PM
roots's Avatar
Moderator
 
Join Date: Jan 2008
Location: Dallas
Posts: 263
roots is on a distinguished road
you can apply trim() to player's name .. and above code should work provided that the you use maximum possible length of name instead of 20.

Delete the existing data file as well.
__________________
dont worry newbie, we got you covered.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-16-2008, 11:09 PM
Member
 
Join Date: Jan 2008
Posts: 39
mcal is on a distinguished road
Ok thanks a lot.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem to ToolTip in Java 3d roshithmca AWT / Swing 1 02-05-2008 04:46 AM
Problem in java saytri New To Java 6 01-09-2008 05:13 PM
Problem with timer in java paul Advanced Java 3 07-26-2007 11:18 AM
JAVA if problem toby New To Java 2 07-25-2007 08:58 PM
java SE 6 problem techlance Java Applets 1 06-28-2007 11:10 AM


All times are GMT +3. The time now is 10:17 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org