Roll two sets of dice when window is resized.

Hello,

I'm a kook.  

The dice on the window are supposed to change pips once the panel is resized.  Top row is complete.  Bottom row is supposed to change pips every 100 or so times. I can't figure out how to do this.  Thank you for your patience.

This has taken me more than twelve hours.  I'm not trying to get anyone to do my homework.  I simply need help.

Please..


package dicesample;

import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;

public class Face extends JPanel{
   
    private int faceValue;
    private int faceValue1;
    private int faceValue2=5;
    private int faceValue3=1;
   
    public Face() {
        setBackground(Color.BLACK);
    }
   
    public void paintComponent(Graphics g){
        faceValue = (int) (6*Math.random()+1);
        faceValue1=(int) (6*Math.random()+1);
//         faceValue2 =(int) (6*Math.random()+1);
////        faceValue3=(int) (6*Math.random()+1);
       
        super.paintComponent(g);
       
        rollDie(g, 40,40,faceValue);
        rollDie(g, 150,40,faceValue1);
        rollDie(g, 40,160, faceValue2);
        rollDie(g, 150,160,faceValue3 );
       
    }
    public void rollDie( Graphics g, int x, int y, int faceValue) {
       
        g.setColor(Color.WHITE);
        g.fillRect(x,y,105,105);
        g.setColor(Color.RED);
        g.drawRect(x,y,105,105);
       
       
        switch( faceValue){
            case 1:
                g.setColor(Color.BLACK);
                g.fillOval(x+45,y+45,15,15);
                break;
               
            case 2:
                g.setColor(Color.BLACK);
                g.fillOval(x+15,y+15,15,15);
                g.fillOval(x+75,y+75,15,15);
                break;
            case 3:
                g.setColor(Color.BLACK);
                g.fillOval(x+15,y+15,15,15);
                g.fillOval(x+45,y+45,15,15);
                g.fillOval(x+75,y+75,15,15);
                break;
               
            case 4:
               
                g.setColor(Color.BLACK);
                g.fillOval(x+15,y+15,15,15);
                g.fillOval(x+75,y+15,15,15);
                g.fillOval(x+45,y+45,15,15);
                g.fillOval(x+15,y+75,15,15);
                g.fillOval(x+75,y+75,15,15);
                break;
               
            case 5:
               
                g.setColor(Color.BLACK);
                g.fillOval(x+15,y+15,15,15);
                g.fillOval(x+75,y+15,15,15);
                g.fillOval(x+45,y+45,15,15);
                g.fillOval(x+15,y+75,15,15);
                g.fillOval(x+75,y+75,15,15);
                break;
               
            case 6:
               
                g.setColor(Color.BLACK);
                g.fillOval(x+15,y+15,15,15);
                g.fillOval(x+45,y+15,15,15);
                g.fillOval(x+75,y+15,15,15);
                g.fillOval(x+15,y+75,15,15);
                g.fillOval(x+45,y+75,15,15);
                g.fillOval(x+75,y+75,15,15);
                break;
        }
    }
   
    public void setFaceValue2(int _faceValue2) {
        int value=_faceValue2;
        int result = getFaceValue2();
        result +=faceValue2;
        if(result%100==0)faceValue2=(int) (6*Math.random()+1);
    }
   
    public int getFaceValue2() {
        return faceValue2;
    }
}

package dicesample;

import java.awt.Color;
import javax.swing.JFrame;

/**
 *
 * @author admin
 */
public class Main {
   
    /** Creates a new instance of Main */
    public Main() {
    }
   
   
    public static void main(String[] args) {
 
   
        Face panel = new Face();
       
        JFrame application = new JFrame();
       
        application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        application.add(panel);
     
        application.setSize(300,335);
        application.setVisible(true);
       
    }
   
}

mheningAsked:
Who is Participating?
 
mr_egyptianCommented:
Since this is hw, here's a clue (assuming I understand what you're looking for). All you need in setFaceValue2() is to randomly set values for face2 and face3, then count how many times the window is resized, if it's a multiple of 100, run the function, if not,  leave it alone.

Hope that's enough to get you there.  I tested it and it only takes ~2 minutes to implement.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.