Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: String max out

  1. #1
    Member
    Join Date
    Feb 2012
    Location
    Azle/Arlington
    Posts
    31
    My Mood
    Torn
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default String max out

    Is it theoretically possible to max out the number of characters allowed in a string?? (I know you can in c++ but what about java?) if so can you please send me the link fo the api documentaion i would need to use?? and help will be gratiously accepted!!


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,447
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 544 Posts

    Default Re: String max out

    What exactly do you mean? What do you mean by "allowed"? What should happen if a String with a greater length is created? When are the Strings created?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member
    Join Date
    Feb 2012
    Location
    Azle/Arlington
    Posts
    31
    My Mood
    Torn
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: String max out

     import static java.lang.System.out;
    import javax.swing.*;
     
    public class test{
     
    	public static void main(String ad[]){
     
    		String playerNamePrompt = "Enter Your Full Name as the player. \n";
    		String player = JOptionPane.showInputDialog(playerNamePrompt);
    		out.print(player);
     
    	}
    }

    I want to make a max amount of characters that the String player can hold. so that when i use the code somewhere else if i draw the string player on the screen it is only 0 - 16 characters
    Last edited by lorider93p; February 23rd, 2012 at 12:15 PM. Reason: fix my highlights

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,447
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 544 Posts

    Default Re: String max out

    Why don't you just check the length of the String, and then re-prompt the user if it's not in a valid range?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Member
    Join Date
    Feb 2012
    Location
    Azle/Arlington
    Posts
    31
    My Mood
    Torn
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: String max out

    That makes since. but im trying to move away from reprompts (to many variables) but i guess there is a way to do it. TNX

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,447
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 544 Posts

    Default Re: String max out

    You could also come up with your own window using a JTextField if you really wanted to limit the number of characters. There are a number of ways to accomplish this. I suggest googling something like "java JTextField max characters" to see some options.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. The Following User Says Thank You to KevinWorkman For This Useful Post:

    lorider93p (March 2nd, 2012)

  8. #7
    Member
    Join Date
    Feb 2012
    Location
    Azle/Arlington
    Posts
    31
    My Mood
    Torn
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: String max out

    ok thanks Kevin. (Ive been offline for a few days)

  9. #8
    Member
    Join Date
    Feb 2012
    Location
    Azle/Arlington
    Posts
    31
    My Mood
    Torn
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: String max out

    I have been looking at code and found a error that helped me edit a few things. 1 being the use of a jPanel instead of jFrame. That was 1 of my logical errors. using the jPanel instead of direct contact to the jframe gives me more control of the background color. and With that i can fix most of my errors. and even fix a few things. Including the making of a new Win() setup. Thanks all for the help. On finish of this message i will mark all my forums solved (because im done witht the project i was working on and have my answer for all the questions

Similar Threads

  1. Replies: 7
    Last Post: December 11th, 2011, 10:58 PM
  2. How to change a String value into a number and then back into a String.
    By javapenguin in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 18th, 2011, 12:43 PM
  3. [SOLVED] difference between String Concatenation and String -Buffer/Builder .append(<value>)
    By chronoz13 in forum Java Theory & Questions
    Replies: 5
    Last Post: September 3rd, 2011, 08:16 AM
  4. Replies: 18
    Last Post: March 2nd, 2011, 09:52 AM
  5. [SOLVED] String Matcher finding only char not a whole string
    By Kakashi in forum What's Wrong With My Code?
    Replies: 11
    Last Post: February 18th, 2011, 08:58 AM