Results 1 to 4 of 4
  1. #1
    Justinweq is offline Member
    Join Date
    Dec 2013
    Posts
    1
    Rep Power
    0

    Default I need help with some strange errors with my icons.

    Hello i need some help with some strange glitches when setting my images i have to some labels icon.
    Here is my code for rolling the dice which plays a short animation of the dice rolling
    Java Code:
     private void rollTheDice()
        {
            Dice dice1 = new Dice();
            Dice dice2 = new Dice();
            short roll1 = 0,roll2 = 0;
            for(int i = 0;i <= 30;i++)
            {
            roll1 = dice1.roll();
            roll2 = dice2.roll();
            switch(roll1)
            {
                case 1:
                    die1jLabel.setIcon(side1);
               case 2:
                    die1jLabel.setIcon(side2);
               case 3:
                    die1jLabel.setIcon(side3);
               case 4:
                    die1jLabel.setIcon(side4);
               case 5:
                    die1jLabel.setIcon(side5);
               case 6:
                    die1jLabel.setIcon(side6);
            }
             switch(roll2)
            {
                case 1:
                    die2jLabel.setIcon(side1);
               case 2:
                    die2jLabel.setIcon(side2);
               case 3:
                    die2jLabel.setIcon(side3);
               case 4:
                    die2jLabel.setIcon(side4);
               case 5:
                    die2jLabel.setIcon(side5);
               case 6:
                    die2jLabel.setIcon(side6);
            }
                try {
                    Thread.sleep(33+i);
                } catch (InterruptedException ex) {
                    Logger.getLogger(Main_GUI.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    Here is my icons that i am loading.

    Java Code:
     Icon side1  = new  ImageIcon("src/Images/die1.png"),
                side2 = new ImageIcon("src/Images/die2.png"),
                side3 = new ImageIcon("src/Images/die3.png"),
                side4 = new ImageIcon("src/Images/die4.png"),
                side5 = new ImageIcon("src/Images/die5.png"),
                side6 = new ImageIcon("src/Images/die6.png");
    Here is some a screen shot of the project before the roll button is clicked.
    I need help with some strange errors with my icons.-capture1.png


    Here is a screenshot of the project after the roll button is clicked
    I need help with some strange errors with my icons.-capture2.png

    See what i mean.

    As far as I can tell this code should be working,but for whatever reason its not.
    If anyone knows what is going wrong and how I can fix it please say so.

    Thanks, JustinWeq

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,646
    Rep Power
    5

    Default Re: I need help with some strange errors with my icons.

    Are you doing a repaint() after you change the dice? And it would be helpful if you would provide a short compilable, program that demonstrates the problem.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,036
    Rep Power
    20

    Default Re: I need help with some strange errors with my icons.

    Along with the repaint() (is that necessary with a change of icon? I can never remember), look at your case statements again. You have ne "break;"'s in there, so they'll both fall through, eventually setting the icon to a 6.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,646
    Rep Power
    5

    Default Re: I need help with some strange errors with my icons.

    Quote Originally Posted by Tolls View Post
    Along with the repaint() (is that necessary with a change of icon? I can never remember).
    I don't really know either (And I didn't bother to look at the code). It may indeed fire off a propertyChangeEvent or similar event which may result in a repaint.

    And I keep missing those dog gone break statements. Geez.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. Strange errors in simple code.
    By ninjakreborn in forum New To Java
    Replies: 4
    Last Post: 11-21-2012, 02:33 PM
  2. applet loading errors strange?!
    By newbie_jar in forum Java Applets
    Replies: 1
    Last Post: 11-08-2011, 05:35 PM
  3. help with jtree icons
    By ankit_k in forum AWT / Swing
    Replies: 4
    Last Post: 06-16-2011, 08:18 PM
  4. Replies: 4
    Last Post: 01-04-2011, 12:36 AM
  5. Replies: 3
    Last Post: 03-08-2009, 01:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •