Using Buttons?

I'm trying to make a reset button to reset my game. It's not doing anything though...here's what I'm workin with. Basically, reset, makes the arraylist containg all of the pieces empty so there shudn't be any thing drawn to the board when i hit reset

import java.applet.*;

import java.awt.event.*;

import java.awt.*;

publicclass GameDisplayextends Appletimplements MouseListener, ActionListener

{

GamePlay game;

Image[] images;

String [] fonts;

Button reset;

Font font;

int font_size;

publicvoid init()

{

images = loadImages();

reset =new Button("Reset");

game =new GamePlay(images);

addMouseListener(this);

reset.addActionListener(this);

add(reset);

font_size = 50;

font =new Font("Sanserif", Font.BOLD, font_size);

}

publicvoid actionPerformed (ActionEvent ae)

{

if(ae.getSource()==reset)

{

game.reset(images);

repaint();

}

}

//more stuff

This code is in the GamePlay class:

publicvoid reset(Image[] i)

{

board =new Board(i[0]);

images = i;

turn = 1;

color ="red";

message ="";

gameOver =false;

}

And this is the board class:

public Board(Image i)

{

fileName ="C:\\Users\\JP\\Projects\\Connect Four\\src\\ConnectFourgrid.gif";

pic = i;

pieces =new ArrayList();

winner ="nobody";

over =false;

ct=1;

myLength = 7;

myWidth = 6;

}

[2867 byte] By [JFactor2004a] at [2007-11-27 9:02:55]
# 1
Looks alright to me, other than assigning images to itself in the reset method. What's wrong with it?
hunter9000a at 2007-7-12 21:34:15 > top of Java-index,Java Essentials,New To Java...
# 2
Have you tried putting a print statement in the actionPerformed Method to see if it is firing?
_helloWorld_a at 2007-7-12 21:34:16 > top of Java-index,Java Essentials,New To Java...
# 3
Ok, so, when I hit reset, it doesn't clear any of the images until I resize the window. If I resize the window at all, it works. Anyway to auto refresh? I thought thats what repaint did
JFactor2004a at 2007-7-12 21:34:16 > top of Java-index,Java Essentials,New To Java...
# 4

try this

public void repaint(Graphics g){

update(g);

refreshUI(); //this is the function to redraw the GUI

}

add that into your class which extends Applet

refreshUI() is a function which should do whatever steps you need to repaint. you may try to ommit it if you dont know what to put there

mkoryaka at 2007-7-12 21:34:16 > top of Java-index,Java Essentials,New To Java...
# 5
shouldn't it not have an input graphics g b/c then I can't do repaint()
JFactor2004a at 2007-7-12 21:34:16 > top of Java-index,Java Essentials,New To Java...
# 6
you can still do repaint() if you have a method that takes a different list of arguemnts, its called overriding. repaint(Graphics g) is a swing component method call, i am not 100% sure if it will work for you, since you are using Awt but you can give it a try.
mkoryaka at 2007-7-12 21:34:16 > top of Java-index,Java Essentials,New To Java...
# 7
does calling repaint() only do update() or the refresh too? What does the default method do?
JFactor2004a at 2007-7-12 21:34:16 > top of Java-index,Java Essentials,New To Java...
# 8
why dont you read the API, it will usually tell you exactly what a method does.
mkoryaka at 2007-7-12 21:34:16 > top of Java-index,Java Essentials,New To Java...