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 6 of 6

Thread: How to create Choices in Java?

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How to create Choices in Java?

    Can you please tell me how to create multiple Choices in one Panel?
    I need to create a program that will choose a number in these choices then it will display the words at the bottom.

    E.g. "Two Thousand Fourteen"
    "Three Thousand"
    "Two Thousand"

    Please help me.

    Thanks1.JPG


  2. #2
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: How to create Choices in Java?

    Quote Originally Posted by patrickdan02 View Post
    Can you please tell me how to create multiple Choices in one Panel?
    Supposing in Swing, a "choice" can be created with the JComboBox component. In order to have more JComboBox components in a single JPanel, you need a specific layout manager in the JPanel or you can use "absolute" positioning.
    Andrea, www.andbin.netSCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginnersMy new project Java Examples on Google Code

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: How to create Choices in Java?

    Here's a link to the Swing tutorials. Your question is not specific enough to determine what help you need.

  4. #4
    Junior Member
    Join Date
    Jan 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to create Choices in Java?

    Quote Originally Posted by GregBrannon View Post
    Here's a link to the Swing tutorials. Your question is not specific enough to determine what help you need.
    I'm sorry. I just need to know how to create choices like these. 4 choices. The first one is from 0-3, the second up to the fourth one is 0-9. When you choose a number, it will display the corresponding words instead of numbers.

    I don't know how to create these choices using the For Loop. Please help me.

  5. #5
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: How to create Choices in Java?

    I'm not sure of the purpose of the for loop. Perhaps you could explain that part, but before then, read the Swing tutorial on using the JComboBox. There's not much more we can do for you until you understand Swing basics and make an attempt to code that part.

  6. #6
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: How to create Choices in Java?

    Quote Originally Posted by patrickdan02 View Post
    The first one is from 0-3, the second up to the fourth one is 0-9. I don't know how to create these choices using the For Loop. Please help me.
    If the number of choice components is known/fixed and if the values are also known/fixed, there's no really need to use "loops".

    Here is a simple example:

    Integer[] evenValues = { 2, 4, 6, 8 };     // note: autoboxing since Java 5
    JComboBox evenNumbersCombo = new JComboBox(evenValues);

    Quote Originally Posted by patrickdan02 View Post
    When you choose a number, it will display the corresponding words instead of numbers.
    If you use JComboBox as I have described above, you have an Integer object as the "selected" value (not a primitive int).
    How to generate a number in letters is another story. Every language, english, italian, etc... has its specific rules to form "literal numbers". And in general there are also many special/corner cases. You have to known these rules.
    Andrea, www.andbin.netSCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginnersMy new project Java Examples on Google Code

Similar Threads

  1. how can i make the choices 1 2 3 4 to A B C D in java
    By khianz08 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 14th, 2013, 11:33 AM
  2. can i create the project in java ?
    By naved in forum Java Theory & Questions
    Replies: 1
    Last Post: June 29th, 2011, 08:43 AM
  3. create file in java
    By pokuri in forum Object Oriented Programming
    Replies: 2
    Last Post: January 19th, 2011, 10:42 AM
  4. How I can create those shapes with Java?
    By Learner in forum AWT / Java Swing
    Replies: 3
    Last Post: November 18th, 2010, 02:10 AM