import java.awt.Font;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
import java.util.Random;
public class Aufgabe extends JPanel
{
private double x; //
private double xValue1 = 10;
private double xValue2 = 15;
private double xValue3 = 20;
private double xValue4 = 25;
private double xValue5 = 30;
private double xValue6 = 35;
private double y = 10;
private double h = 10;
private double b = 0;
private int dice1 = 0;
private int dice2 = 0;
private int dice3 = 0;
private int dice4 = 0;
private int dice5 = 0;
private int dice6 = 0;
public void paintComponent( Graphics g )
{
super.paintComponent( g );
this.setBackground( Color.GRAY );
g.setFont( new Font( "SansSerif", Font.PLAIN, 12 ) );
g.drawString("Distribution", 0, 5 );
g.setFont( new Font( "SansSerif", Font.PLAIN, 12 ) );
g.drawString("1: ", 0, 10 );
g.setFont( new Font( "SansSerif", Font.PLAIN, 12 ) );
g.drawString("2: ", 0, 15 );
g.setFont( new Font( "SansSerif", Font.PLAIN, 12 ) );
g.drawString("3: ", 0, 20 );
g.setFont( new Font( "SansSerif", Font.PLAIN, 12 ) );
g.drawString("4: ", 0, 25 );
g.setFont( new Font( "SansSerif", Font.PLAIN, 12 ) );
g.drawString("5: ", 0, 30 );
g.setFont( new Font( "SansSerif", Font.PLAIN, 12 ) );
g.drawString("6: ", 0, 35 );
Random randomNumbers = new Random();
for( int counter = 1; counter <= 100; counter++ ) //
{
int rollTheDice = 1 + randomNumbers.nextInt(6);
switch( rollTheDice )
{
case 1:
++dice1;
g.setColor( Color.BLACK );
g.fillRect( (int) xValue1, (int) y, (int) b++, (int) h );
break;
case 2:
++dice2;
g.setColor( Color.BLACK );
g.fillRect( (int) xValue2, (int) y, (int) b++, (int) h );
break;
case 3:
++dice3;
g.setColor( Color.BLACK );
g.fillRect( (int) xValue3, (int) y, (int) b++, (int) h );
break;
case 4:
++dice4;
g.setColor( Color.BLACK );
g.fillRect( (int) xValue4, (int) y, (int) b++, (int) h);
break;
case 5:
++dice5;
g.setColor( Color.BLACK );
g.fillRect( (int) xValue5, (int) y, (int) b++, (int) h );
break;
case 6:
++dice6;
g.setColor( Color.BLACK );
g.fillRect( (int) xValue6, (int) y, (int) b++, (int) h );
break;
}
}
}
}