// Decompiled by DJ v3.2.2.71 Copyright 2003 Atanas Neshkov Date: 1/28/2003 3:31:06 AM // Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version! // Decompiler options: packimports(3) // Source File Name: Dice.java import java.awt.*; import javax.swing.JComponent; import javax.swing.JPanel; public class Dice extends JPanel { public Dice(int size) { mySize = size; dotSize = mySize / 5; left = (mySize - 3 * dotSize) / 4; right = mySize - left - dotSize; middle = (mySize - dotSize) / 2; setBackground(Color.white); myBackground = new Color(255, 255, 255); myColor = new Color(0, 0, 0); myColor = Color.black; setSize(size + 1, size + 1); setPreferredSize(new Dimension(size + 1, size + 1)); myValue = (int)(Math.random() * 6D) + 1; } public Dice() { this(100); } public void setPosition(int row, int col, LayoutManager layout) { GridBagConstraints con = new GridBagConstraints(); con.gridx = col - 1; con.gridy = row - 1; ((GridBagLayout)layout).setConstraints(this, con); } public void setDotColor(Color c) { myColor = c; } public int roll() { for(int i = 1; i < 50; i++) { myValue = (int)(Math.random() * 6D) + 1; repaint(); } return myValue; } public int getValue() { return myValue; } public void paint(Graphics g) { g.setColor(getBackground()); g.fillRect(0, 0, mySize, mySize); g.setColor(Color.black); g.draw3DRect(0, 0, mySize, mySize, true); g.setColor(myColor); switch(myValue) { case 1: // '\001' g.fillOval(middle, middle, dotSize, dotSize); break; case 2: // '\002' g.fillOval(left, left, dotSize, dotSize); g.fillOval(right, right, dotSize, dotSize); break; case 3: // '\003' g.fillOval(middle, left, dotSize, dotSize); g.fillOval(middle, middle, dotSize, dotSize); g.fillOval(middle, right, dotSize, dotSize); break; case 5: // '\005' g.fillOval(middle, middle, dotSize, dotSize); // fall through case 4: // '\004' g.fillOval(left, left, dotSize, dotSize); g.fillOval(left, right, dotSize, dotSize); g.fillOval(right, left, dotSize, dotSize); g.fillOval(right, right, dotSize, dotSize); break; case 6: // '\006' g.fillOval(left, left, dotSize, dotSize); g.fillOval(left, middle, dotSize, dotSize); g.fillOval(left, right, dotSize, dotSize); g.fillOval(right, left, dotSize, dotSize); g.fillOval(right, middle, dotSize, dotSize); g.fillOval(right, right, dotSize, dotSize); break; } } private int myValue; private int mySize; private int dotSize; private int left; private int right; private int middle; private Color myColor; private Color myBackground; }