Works on house computer but not school computer

problems with my connect four program working at my house but not at s

Page 1 of 1

9 Replies - 825 Views - Last Post: 16 June 2008 - 03:43 PM Rate Topic: -----

#1 marathdamane91  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 01-April 08

Works on house computer but not school computer

Post icon  Posted 16 June 2008 - 09:40 AM

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?
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);
	}
}



Is This A Good Question/Topic? 0
  • +

Replies To: Works on house computer but not school computer

#2 jjsaw5  Icon User is offline

  • I must break you
  • member icon

Reputation: 90
  • View blog
  • Posts: 3,059
  • Joined: 04-January 08

Re: Works on house computer but not school computer

Posted 16 June 2008 - 10:02 AM

if its a game, maybe your school has stuff like this blocked and thats why it's freezing
Was This Post Helpful? 0
  • +
  • -

#3 marathdamane91  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 01-April 08

Re: Works on house computer but not school computer

Posted 16 June 2008 - 10:07 AM

View Postjjsaw5, on 16 Jun, 2008 - 10:02 AM, said:

if its a game, maybe your school has stuff like this blocked and thats why it's freezing


its a game that im writing for my final and the other people in the class arent having problems with it and i transfered it on a flash drive so its not like im going through a blocke website or anything
Was This Post Helpful? 0
  • +
  • -

#4 prajayshetty  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 31
  • View blog
  • Posts: 920
  • Joined: 27-April 07

Re: Works on house computer but not school computer

Posted 16 June 2008 - 10:24 AM

View Postmarathdamane91, on 16 Jun, 2008 - 10:07 AM, said:

View Postjjsaw5, on 16 Jun, 2008 - 10:02 AM, said:

if its a game, maybe your school has stuff like this blocked and thats why it's freezing


its a game that im writing for my final and the other people in the class arent having problems with it and i transfered it on a flash drive so its not like im going through a blocke website or anything


it doesnt work on mine pc also do u checked it has some runtime error i guess eclipse is printing something in red at runtime
it gives following error dude i cant correct coz i dont have kng of appelet though but me sure other guys will help
guys the error is at runtime

Exception in thread "AWT-EventQueue-1" java.lang.ArrayIndexOutOfBoundsException: 7
at ConnectFour.paint(ConnectFour.java:367)
at java.awt.Container.update(Unknown Source)
at sun.awt.RepaintArea.updateComponent(Unknown Source)
at sun.awt.RepaintArea.paint(Unknown Source)
at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
the same error is repeated again and again continuously

This post has been edited by prajayshetty: 16 June 2008 - 10:27 AM

Was This Post Helpful? 0
  • +
  • -

#5 marathdamane91  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 01-April 08

Re: Works on house computer but not school computer

Posted 16 June 2008 - 10:28 AM

View Postprajayshetty, on 16 Jun, 2008 - 10:24 AM, said:

View Postmarathdamane91, on 16 Jun, 2008 - 10:07 AM, said:

View Postjjsaw5, on 16 Jun, 2008 - 10:02 AM, said:

if its a game, maybe your school has stuff like this blocked and thats why it's freezing


its a game that im writing for my final and the other people in the class arent having problems with it and i transfered it on a flash drive so its not like im going through a blocke website or anything


it doesnt work on mine pc also do u checked it has some runtime error i guess eclipse is printing something in red at runtime
it gives following error dude i cant correct coz i dont have kng of appelet though but i thinkso other guys can help
guys the error is at runtime

Exception in thread "AWT-EventQueue-1" java.lang.ArrayIndexOutOfBoundsException: 7
at ConnectFour.paint(ConnectFour.java:367)
at java.awt.Container.update(Unknown Source)
at sun.awt.RepaintArea.updateComponent(Unknown Source)
at sun.awt.RepaintArea.paint(Unknown Source)
at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
the same error is repeated again and again continuously

hmm its not even showing up with an error for me at all. and i dont see why it would work at my house but not at my school if its a problem with the program
Was This Post Helpful? 0
  • +
  • -

#6 prajayshetty  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 31
  • View blog
  • Posts: 920
  • Joined: 27-April 07

Re: Works on house computer but not school computer

Posted 16 June 2008 - 10:31 AM

View Postmarathdamane91, on 16 Jun, 2008 - 10:28 AM, said:

View Postprajayshetty, on 16 Jun, 2008 - 10:24 AM, said:

View Postmarathdamane91, on 16 Jun, 2008 - 10:07 AM, said:

View Postjjsaw5, on 16 Jun, 2008 - 10:02 AM, said:

if its a game, maybe your school has stuff like this blocked and thats why it's freezing


its a game that im writing for my final and the other people in the class arent having problems with it and i transfered it on a flash drive so its not like im going through a blocke website or anything


it doesnt work on mine pc also do u checked it has some runtime error i guess eclipse is printing something in red at runtime
it gives following error dude i cant correct coz i dont have kng of appelet though but i thinkso other guys can help
guys the error is at runtime

Exception in thread "AWT-EventQueue-1" java.lang.ArrayIndexOutOfBoundsException: 7
at ConnectFour.paint(ConnectFour.java:367)
at java.awt.Container.update(Unknown Source)
at sun.awt.RepaintArea.updateComponent(Unknown Source)
at sun.awt.RepaintArea.paint(Unknown Source)
at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
the same error is repeated again and again continuously

hmm its not even showing up with an error for me at all. and i dont see why it would work at my house but not at my school if its a problem with the program

be patient there are some pro here they will help u when they see ur post
coz me too a learner like u so cant help sorry u executing program directly from command line or using an ide

This post has been edited by prajayshetty: 16 June 2008 - 10:32 AM

Was This Post Helpful? 0
  • +
  • -

#7 marathdamane91  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 01-April 08

Re: Works on house computer but not school computer

Posted 16 June 2008 - 10:39 AM

so i increased the array and now it works fine. im still just very confused about why it wasn't working at school but was at my house and now i cant get the circles in the right column
Was This Post Helpful? 0
  • +
  • -

#8 prajayshetty  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 31
  • View blog
  • Posts: 920
  • Joined: 27-April 07

Re: Works on house computer but not school computer

Posted 16 June 2008 - 10:51 AM

View Postmarathdamane91, on 16 Jun, 2008 - 10:39 AM, said:

so i increased the array and now it works fine. im still just very confused about why it wasn't working at school but was at my house and now i cant get the circles in the right column

ya it that error also stated something like that just check for errors at runtime and compile time both everytime coz they give someidea of the error

This post has been edited by prajayshetty: 16 June 2008 - 10:52 AM

Was This Post Helpful? 0
  • +
  • -

#9 1lacca  Icon User is offline

  • code.rascal
  • member icon

Reputation: 44
  • View blog
  • Posts: 3,822
  • Joined: 11-August 05

Re: Works on house computer but not school computer

Posted 16 June 2008 - 11:53 AM

I guess your problem originated at the line:
for (int x = 1; x <= 7; x++)
because your board array is declared only as public int[][] board = new int[7][7]; so it will fail for x==7.
Maybe you weren't running the same version of your program, or it simply didn't get to that line for some reason (I didn't try to understand the logic of your code, only looked at apparent errors).
Was This Post Helpful? 0
  • +
  • -

#10 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: Works on house computer but not school computer

Posted 16 June 2008 - 03:43 PM

Seriously doubt it works at home :D :D :D


	   public int[][] board = new int[7][7];
...
...
		for (int x = 1; x <= 7; x++)



as soon as x will equal 7 you'll have an array out of bound exception

probably wanted to say: for(int x = i; x < 7; x++)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1