First off this is school help but i'm not looking for help with writing the program only wth why it works at my house but not at my school. Heres my code and when im at my house it will run fine but when im at school i can move my mouse once before the whole game freezes up. And then at my house it flasshes a lot is that because i need to either back buffer ordouble buffer it?
CODE
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.applet.*;
public class ConnectFour extends Applet implements Runnable, MouseListener, MouseMotionListener
{
Random generator = new Random();
Thread mythread;
public boolean game = true;
public int thecounter, startx, starty, mx, my, thex, they, finalx, finaly, entermouseX, entermouseY, exitmouseX, exitmouseY, drawX = -100, turn = 0, speed = 10, timecounter = 0;
public int[][] board = new int[7][7];
boolean redWins = false, blackWins = false;
public void init()
{
setBackground (Color.white);
setSize(1000, 900);
addMouseListener(this);
addMouseMotionListener(this);
}
public void start()
{
mythread = new Thread(this);
mythread.start();
}
public void run()
{
while(game == true)
{
showStatus("" + thex + they);
repaint();
try
{
Thread.sleep(speed);
}
catch (InterruptedException e) {; }
}
}
public void mouseClicked (MouseEvent e){ }
public void mouseReleased (MouseEvent e)
{
timecounter = 0;
finalx = e.getX();
finaly = e.getY();
if ((finalx>=85)&&(finalx<=187))
{
int counter = 6;
while ((board[0][counter] > 0) && (counter >= 1))
counter--;
if (counter >= 1)
{
board[0][counter] = turn%2+1;
turn++;
}
}
if ((finalx>=187)&&(finalx<287))
{
int counter = 6;
while ((board[1][counter] > 0) && (counter >=1))
counter--;
if (counter >= 1)
{
board[1][counter] = turn%2+1;
turn++;
}
}
if ((finalx>=287)&&(finalx<387))
{
int counter = 6;
while ((board[2][counter] > 0) && (counter >=1))
counter--;
if (counter >= 1)
{
board[2][counter] = turn%2+1;
turn++;
}
}
if ((finalx>=387)&&(finalx<487))
{
int counter = 6;
while ((board[3][counter] > 0) && (counter >=1))
counter--;
if (counter >=1)
{
board[3][counter] = turn%2+1;
turn++;
}
}
if ((finalx>=487)&&(finalx<587))
{
int counter = 6;
while ((board[4][counter] > 0) && (counter >=1))
counter--;
if (counter >=1)
{
board[4][counter] = turn%2+1;
turn++;
}
}
if ((finalx>=587)&&(finalx<687))
{
int counter = 6;
while ((board[5][counter] > 0) && (counter >=1))
counter--;
if (counter >=1)
{
board[5][counter] = turn%2+1;
turn++;
}
}
if ((finalx>=687)&&(finalx<787))
{
int counter = 6;
while ((board[6][counter] > 0) && (counter >=1))
counter--;
if (counter >=1)
{
board[6][counter] = turn%2+1;
turn++;
}
}
int counterRed = 0, counterBlack = 0;
for (int x = 0; x < 7; x++)
{
counterRed = 0;
counterBlack = 0;
for (int y = 0; y < 6; y++)
{
if (board[x][y] == 1)
{
counterBlack++;
counterRed = 0;
if (counterBlack == 4)
blackWins = true;
}
if (board[x][y] == 2)
{
counterRed++;
counterBlack = 0;
if (counterRed == 4)
redWins = true;
}
if (board[x][y] == 0)
{
counterRed = 0;
counterBlack = 0;
}
}
}
for (int y = 0; y < 6; y++)
{
counterRed = 0;
counterBlack = 0;
for (int x = 0; x < 7; x++)
{
if (board[x][y] == 1)
{
counterBlack++;
counterRed = 0;
if (counterBlack == 4)
blackWins = true;
}
if (board[x][y] == 2)
{
counterRed++;
counterBlack = 0;
if (counterRed == 4)
redWins = true;
}
if (board[x][y] == 0)
{
counterRed = 0;
counterBlack = 0;
}
}
}
for (int x = 0; x < 4; x++)
{
counterRed = 0;
counterBlack = 0;
for (int y = 0; y < 3; y++)
{
counterRed = 0;
counterBlack = 0;
for (int z = 0; z < 4; z++)
{
if (board[x+z][y+z] == 1)
{
counterBlack++;
counterRed = 0;
if (counterBlack == 4)
blackWins = true;
}
if (board[x+z][y+z] == 2)
{
counterRed++;
counterBlack = 0;
if (counterRed == 4)
redWins = true;
}
if (board[x+z][y+z] == 0)
{
counterRed = 0;
counterBlack = 0;
}
}
}
}
for (int x = 0; x < 4; x++)
{
counterRed = 0;
counterBlack = 0;
for (int y = 3; y < 6; y++)
{
counterRed = 0;
counterBlack = 0;
for (int z = 0; z < 4; z++)
{
if (board[x+z][y-z] == 1)
{
counterBlack++;
counterRed = 0;
if (counterBlack == 4)
blackWins = true;
}
if (board[x+z][y-z] == 2)
{
counterRed++;
counterBlack = 0;
if (counterRed == 4)
redWins = true;
}
if (board[x+z][y-z] == 0)
{
counterRed = 0;
counterBlack = 0;
}
}
}
}
}
public void mouseEntered (MouseEvent e)
{
entermouseX = e.getX();
entermouseY = e.getY();
}
public void mouseExited (MouseEvent e)
{
exitmouseX = e.getX();
exitmouseY = e.getY();
}
public void mousePressed (MouseEvent e)
{
startx = e.getX();
starty = e.getY();
if ((startx>=87)&&(startx<=187))
drawX=100;
if ((startx>=187)&&(startx<287))
drawX=200;
if ((startx>=287)&&(startx<387))
drawX=300;
if ((startx>=387)&&(startx<487))
drawX=400;
if ((startx>=487)&&(startx<587))
drawX=500;
if ((startx>=587)&&(startx<687))
drawX=600;
if ((startx>=687)&&(startx<787))
drawX=700;
}
public void mouseDragged (MouseEvent e)
{
mx = e.getX();
my = e.getY();
if ((mx>=87)&&(mx<=187))
drawX=100;
if ((mx>=187)&&(mx<287))
drawX=200;
if ((mx>=287)&&(mx<387))
drawX=300;
if ((mx>=387)&&(mx<487))
drawX=400;
if ((mx>=487)&&(mx<587))
drawX=500;
if ((mx>=587)&&(mx<687))
drawX=600;
if ((mx>=687)&&(mx<787))
drawX=700;
}
public void mouseMoved (MouseEvent e)
{
thex = e.getX();
they = e.getY();
if ((thex>=85)&&(thex<=187))
drawX=100;
if ((thex>=187)&&(thex<287))
drawX=200;
if ((thex>=287)&&(thex<387))
drawX=300;
if ((thex>=387)&&(thex<487))
drawX=400;
if ((thex>=487)&&(thex<587))
drawX=500;
if ((thex>=587)&&(thex<687))
drawX=600;
if ((thex>=687)&&(thex<787))
drawX=700;
}
public void paint (Graphics page)
{
super.paint(page);
Graphics2D page2 = (Graphics2D)page;
setBackground(Color.yellow);
for (int x = 1; x < 8; x++)
{
for (int y = 0; y < 6; y++)
{
page.setColor(Color.white);
page.fillOval(x*100, 100*y + 100, 75, 75);
page.setColor(Color.black);
page.drawOval(x*100, 100*y + 100, 75, 75);
}
}
for (int x = 1; x <= 6; x++)
{
page.setColor(new Color (112, 128, 144));
page.drawLine(x*100+87, 92, x*100+87, 700);
}
page.setColor(new Color (112, 128, 144));
for (int y = 1; y <= 5; y++)
page.drawLine(75, 100*y+87, 920,100*y+87);
page.setColor(Color.white);
page.fillRect(85, 0, 705, 90);
page.fillRect(0, 0, 85, 900);
page.fillRect(787, 0, 1000, 900);
page.fillRect(75,690,1000,900);
page.setColor(Color.black);
page.drawRect(85, 90, 702, 600);
if (turn%2 == 0)
page.setColor(Color.black);
if (turn%2 == 1)
page.setColor(Color.red);
if ((redWins == false) && (blackWins == false))
page.fillOval(drawX, 10, 75, 75);
for (int x = 1; x <= 7; x++)
{
for (int y = 6; y >= 1; y--)
{
if (board[x][y] == 1)
page.setColor(Color.black);
if (board[x][y] == 2)
page.setColor(Color.red);
if (board[x][y] > 0)
page.fillOval(100*x,100*y, 75, 75);
}
}
if (redWins == true)
page.drawString("RED WINS", 400, 30);
if (blackWins == true)
page.drawString("BLACK WINS", 400, 30);
thecounter = 0;
for (int x = 0; x < 7; x++)
for (int y = 0; y < 6; y++)
if (board[x][y] == 0)
thecounter++;
if (thecounter == 0)
page.drawString("It's a tie", 400, 30);
}
}