import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JLabel;
import javax.swing.JFrame;
import java.awt.FlowLayout;
import java.awt.Color;
public class DiceThrower extends Applet
{
Die die1;
Die die2;
public void paint (Graphics g)
{
die1.draw(g);
die2.draw(g);
g.drawString ("Click mouse anywhere", 55, 140);
g.drawString ("to throw dice again", 65, 160);
}
public void init()
{
die1 = new Die();
die2 = new Die();
die1.setTopLeftPosition(20, 20);
die2.setTopLeftPosition(150, 20);
throwBothDice();
// Erick's Program Insert below
public class WinnerGui extends JFrame;
{
public WinnerGui();
{
super ("You Are The Winner with GUI");
Container c = getContentPane();
c.setBackground(Color.lightGray);
c.setLayout(new FlowLayout());
c.add(new JLabel("You're a Winner! You Got Doubles!"));
}
}
//End Erick's Program insert
DiceThrowerMouseListener diceThrowerMouseListener =
new DiceThrowerMouseListener();
diceThrowerMouseListener.setDiceThrower(this);
addMouseListener(diceThrowerMouseListener);
}
public void throwBothDice();
{
die1.throwDie();
die2.throwDie();
repaint();
}
}
class Die
{
int topLeftX;
int topLeftY;
int numberShowing = 6;
final int spotPositionsX[] = {0, 60, 0, 30, 60, 0, 60};
final int spotPositionsY[] = {0, 0, 30, 30, 30, 60, 60};
public void setTopLeftPosition(final int _topLeftX, final int _topLeftY)
{
topLeftX = _topLeftX;
topLeftY = _topLeftY;
}
public void throwDie()
{
numberShowing = (int)(Math.random() * 6 + 1);
}
public void draw(Graphics g)
{
switch(numberShowing)
{
case 1:
drawSpot(g, 3);
break;
case 2:
drawSpot(g, 0);
drawSpot(g, 6);
break;
case 3:
drawSpot(g, 0);
drawSpot(g, 3);
drawSpot(g, 6);
break;
case 4:
drawSpot(g, 0);
drawSpot(g, 1);
drawSpot(g, 5);
drawSpot(g, 6);
break;
case 5:
drawSpot(g, 0);
drawSpot(g, 1);
drawSpot(g, 3);
drawSpot(g, 5);
drawSpot(g, 6);
break;
case 6:
drawSpot(g, 0);
drawSpot(g, 1);
drawSpot(g, 2);
drawSpot(g, 4);
drawSpot(g, 5);
drawSpot(g, 6);
break;
}
}
void drawSpot(Graphics g, final int spotNumber)
{
g.fillOval(topLeftX + spotPositionsX[spotNumber],
topLeftY + spotPositionsY[spotNumber], 20, 20);
}
}
class DiceThrowerMouseListener extends MouseAdapter
{
DiceThrower diceThrower;
public void mouseClicked (MouseEvent e)
{
diceThrower.throwBothDice();
}
public void setDiceThrower(DiceThrower _diceThrower)
{
diceThrower = _diceThrower;
}
}
}
That was what I have dwindled it down to, using my knowledge, as well as others' expertise...however I am listening to what you say, and get these messages when I try to compile in the CMD:
line 63 - illegal start of expression (carrot at p in public)
line 63 - ; expected (carrot at c in class)
line 63 - { expected (carrot at ; at end of line)
line 65 - illegal start of expression (carrot at p in public)
line 83 - <identifier> expected (carrot as: (this) ) -- I don't even know what that means
^
line 84 - invalid method declaration; return type required (carrot at a in add)
line 84 - <identifier> expected (carrot like this: [see below])
addMouseListener(diceThrowerMouseListener);
^
line 84 - ) expected (carrot is one place over from previous spot [see above]
line 93 - illegal start of expression (carrot at p in public)
I know this seems like a lot of errors, but believe it or not, I actually had it up in the high teens and was able to fix some of them myself from going by previous examples, as well as looking things up in my text book. If anyone has any suggestions concerning the syntax errors of the code, please please let me know and I will work my hardest to fix them...thank you all so much for helping.
Erick