I added the latest code to the proper place...
ultimately i just checked the personal message i received to see if i put it in the right place, and I did, so I just copied and pasted the code you had in the personal message. However, something is still not right...it isn't working! I checked to see if the code needed to be recompiled, so I compiled it in the command prompt, and tried to open the applet with the .htm file you had me make a little bit ago. The window is still not popping up however...
Here's the code that I now have in the DiceThrower.java text file:
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;
WinnerGui window = new WinnerGui();
public void displayGUI() {
window.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
window.dispose();
}
});
window.setSize(300, 100);
window.show();
}
public void closeGUI() {
window.dispose();
}
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();
DiceThrowerMouseListener diceThrowerMouseListener =
new DiceThrowerMouseListener();
diceThrowerMouseListener.setDiceThrower(this);
addMouseListener(diceThrowerMouseListener);
}
public void throwBothDice()
{
int n1 = 0;
int n2 = 0;
n1 = die1.throwDie();
n2 = die2.throwDie();
if (n1 == n2) {
displayGUI();
}
else {
closeGUI();
}
repaint();
}
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!"));
}
}
}
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 int throwDie()
{
numberShowing = (int)(Math.random() * 6 + 1);
return numberShowing;
}
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 should be what you have been asking for. Is there anything else I need to do to get this to work?
And also, it's probably not going to be a problem, however I did finally receive my deadline for my presentation when I need to share to the committee what I have been doing this trimester...it's next wednesday, February the 8th. Do you think we can get the program to work by then?
Thanks John,
Erick
Edited by Eroved-Kcire, 03 February 2006 - 10:13 AM.