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

Thread: Switch statement issues Help please!!

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

    Lightbulb Switch statement issues Help please!!

    Hi Programmers! This is my code, i have been having issues with it. It should change the ComboBox "MethodType" to have new items. I used to have it all in if statements however it was then running all of the code instead of just the needed part. A case statement will jump out once the code has been run. it better code.
    when i put a number in the text field "Bells"

    Help please!



    public void actionPerformed(ActionEvent e) {



    if(e.getSource() == Bells) {
    switch (Bells.getText()){
    case "4":
    MethodType.setModel(new DefaultComboBoxModel(new String[] {"Minimus","Other"}));//causes a problem 2
    MethodType.setSelectedItem(SelectedItem);
    BellsError.setVisible(false);
    break;


    case "6":
    System.out.println("done");
    MethodType.setModel(new DefaultComboBoxModel(new String[] {"Doubles","Minor","Other"}));//causes a problem 2
    MethodType.setSelectedItem(SelectedItem);
    BellsError.setVisible(false);
    System.out.println("end");
    break;


    case "8":
    MethodType.setModel(new DefaultComboBoxModel(new String[] {"Triples","Major","Other"}));//causes a problem 2
    MethodType.setSelectedItem(SelectedItem);
    BellsError.setVisible(false);
    break;

    case "10":
    MethodType.setModel(new DefaultComboBoxModel(new String[] {"Caters","Royal","Other"}));//causes a problem 2
    MethodType.setSelectedItem(SelectedItem);
    BellsError.setVisible(false);
    break;

    case "12":
    MethodType.setModel(new DefaultComboBoxModel(new String[] {"Sinques","Maximus","Other"}));//causes a problem 2
    MethodType.setSelectedItem(SelectedItem);
    BellsError.setVisible(false);
    break;

    default:
    BellsError.setVisible(true);
    MethodType.setModel(new DefaultComboBoxModel(new String[] {"Minimus","Doubles","Minor","Triples","Major","Ca ters","Royal","Sinques","Maximus","Other"}));
    break;
    }
    }


  2. #2
    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: Switch statement issues Help please!!

    Welcome to the Forum! Please read this topic to learn how to post code correctly and other useful tips for newcomers.

    Please post your code correctly per the above link and describe what issues you are having that you need help with.

Similar Threads

  1. How to turn my If statement into a case/switch statement?
    By blobby404 in forum What's Wrong With My Code?
    Replies: 23
    Last Post: June 19th, 2014, 03:11 PM
  2. [SOLVED] A Loop statement and a switch statement issue
    By sternfox in forum Loops & Control Statements
    Replies: 13
    Last Post: March 7th, 2013, 04:19 PM
  3. Replacing an If statement with a Switch statement
    By logi in forum Loops & Control Statements
    Replies: 9
    Last Post: February 4th, 2013, 12:21 AM
  4. Issues with my ordering program - if statement issues?
    By Shenaniganizer in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 31st, 2012, 10:17 PM
  5. switch and math problem issues
    By emartino in forum Java Theory & Questions
    Replies: 1
    Last Post: January 19th, 2010, 05:34 PM

Tags for this Thread