Hi you all!


I hope someone here will help me, i have workt with my java-program for 14 hours and i cant get it right. Im sure im on the right way but i cant get i all right.
ok.. first i have to create a dice-class that generates random number, 1-to 6.
Then, in a Jpanel the dices 30 times should be thrown 30 times. Then i will create a staticstic how many numbers of each.

well the program work.
But it works whithout the dice-klass. how do i implant the class in a corret way??

sorry, dont laught of my code, im a really beginner on this,=)
the first code is the dice-class. now i have done some changes and im sure it contains lot of rubbish. thanks for any help!!

[

public class Dice
{
         public int dice; 
         public Random random; 
         public int store;

	public Dice()
	{
		random = new Random();
	}

	public double getGame()
	{
                dice = (random.nextInt(6)+1);

                     store=1+ random.nextInt(6);
             return dice	;
	}
public void changeGame()
   {
          dice = (random.nextInt(6)+1);
              store=1+ random.nextInt(6);

   }
	
	public Dice getGameObject()
	{ 
            dice = (random.nextInt(6)+1);
         


		return this;
	}

}
Random random=new Random();
   
    Dice myDice = new Dice(); 


           
            Graphics g = jPanel1.getGraphics();
            jPanel1.paintAll(g);
         
            g.setColor(Color.red);

          
            Graphics gg = jPanel2.getGraphics();
            jPanel2.paintAll(gg);
          
            gg.setColor(Color.blue);

         
            Graphics ggg = jPanel3.getGraphics();
            jPanel3.paintAll(ggg);
      
           ggg.setColor(Color.pink);

       
             Graphics gggg = jPanel4.getGraphics();
            jPanel4.paintAll(gggg);
      
            gggg.setColor(Color.green);


            Graphics ggggg = jPanel5.getGraphics();
            jPanel5.paintAll(ggggg);
         
            ggggg.setColor(Color.yellow);

             Graphics gggggg = jPanel6.getGraphics();
             jPanel6.paintAll(ggggg);
            
             gggggg.setColor(Color.orange);


                int f1=0;
                int f2=0;
                int f3=0;
                int f4=0;
                int f5=0;
                int f6=0;

                int store;

             for ( int counter = 1; counter <= 30; counter++ )
            { 

           store=1+ random.nextInt(6);
         
           
           switch (store)
             {
            case 1:
            ++f1;
            g.drawRect(f1,10,10,10);
            break;

            case 2:
            ++f2;
            gg.drawRect(f2,10,10,10);
            break;

            case 3:
            ++f3;
            ggg.drawRect(f3,10,10,10);
            break;

            case 4:
            ++f4;
            gggg.drawRect(f4,10,10,10);
            break;

            case 5:
            ++f5;
            ggggg.drawRect(f5,10,10,10);
            break;

            case 6:
            ++f6;
            gggggg.drawRect(f6,10,10,10);
            break;

     }
   }

well ... you're not showing all your code, so I can just guess as to what you mean.
you are instantiating a new Dice object (myDice) but you never use it.
just call the methods defined in the Dice class by using the myDice instance.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.