Results 1 to 4 of 4
  1. #1
    panini is offline Member
    Join Date
    Dec 2009
    Posts
    3
    Rep Power
    0

    Default Works in Eclipse but not in browser

    Hi,

    I wrote this short code (about 70 lines) which implements a graphical game board for the connect four game. I could compile and use it without any errors in eclipse, but I i can not run it in a browser.

    I didn' use the filesystem and I dont think that I used functions violating the sandbox.

    I am a newbie and I would highly appreciate any advice.


    //package applets;
    Java Code:
    import java.applet.*; 
    import java.awt.*; 
    import java.awt.event.*;
    
    
    public class spielfeld extends Applet implements MouseListener
    {
    	//private static final long serialVersionUID = 3852206971008502788L;
    	//enum feld{leer,spieler1,spieler2};
    	public int groesseFeld=60;
    	public int seitenabstand=50;
    	public int zeileGeklickt = 0;
    	public int[][] felder; 
    	public boolean spieler1AmZug;
    		
      
      public void init(){
    	   felder = new int[7][6]; 
    	   addMouseListener(this);
    	   for(int i=0;i<7;i++)
    		   for (int j=0;j<6;j++)
    			   felder[i][j]=0;
      }
    	
      public void paint( Graphics g ) {
    	g.setColor(Color.gray);
        g.fillRect(seitenabstand, seitenabstand, groesseFeld*7,groesseFeld*6);
        g.setColor(Color.black);
        for (int i = 0; i < 8; i++)
          g.drawLine(seitenabstand+i*groesseFeld,seitenabstand ,seitenabstand+ i*groesseFeld,groesseFeld*6+seitenabstand);
        for (int i = 0; i < 7; i++)
          g.drawLine(seitenabstand,seitenabstand+i*groesseFeld, groesseFeld*7+seitenabstand, seitenabstand+i*groesseFeld);
      
    
        if (zeileGeklickt>0) g.drawString(Integer.toString(zeileGeklickt), 0, 15);
        g.setColor(Color.blue);
        for(int i=0;i<7;i++){
          for(int j=0;j<6;j++){
        	  if(felder[i][j]!=0)
        		  if(felder[i][j]==1)
        			  g.setColor(Color.yellow);
        		  else g.setColor(Color.green);
        	  else g.setColor(Color.black);
              int xpos=seitenabstand+(i)*groesseFeld+(groesseFeld)/6;
        	  int ypos=seitenabstand+groesseFeld*6-(j+1)*groesseFeld+(groesseFeld/6);
        	  g.fillOval(xpos, ypos, groesseFeld/3*2, groesseFeld/3*2);  		  
          }   
        }
      }
      
      public void mouseClicked (MouseEvent me)  {}
      public void mouseEntered (MouseEvent me)  {}
      public void mouseExited (MouseEvent me)   {}
      public void mousePressed (MouseEvent me)  {}
      public void mouseReleased (MouseEvent me) {
    	  int x=me.getX();
    	  zeileGeklickt=0;
    	  if ((x>seitenabstand) && (x<seitenabstand+7*groesseFeld))
    		  zeileGeklickt = (x-seitenabstand)/groesseFeld+1;
    	  for(int i=0;i<6;i++)
     	    if(felder[zeileGeklickt-1][i]==0){
     	    	if (spieler1AmZug) felder[zeileGeklickt-1][i]=1;
     	    	else felder[zeileGeklickt-1][i]=2;
     	    	spieler1AmZug=!spieler1AmZug;
     	    	break;
     	    }
    	  repaint();	
      } 
    }
    Last edited by panini; 12-11-2009 at 08:15 AM. Reason: Typo

  2. #2
    cowboy is offline Member
    Join Date
    Oct 2009
    Posts
    48
    Rep Power
    0

    Default

    it is intresting

  3. #3
    panini is offline Member
    Join Date
    Dec 2009
    Posts
    3
    Rep Power
    0

    Default ...

    did you try it?

  4. #4
    panini is offline Member
    Join Date
    Dec 2009
    Posts
    3
    Rep Power
    0

    Default forget it

    For some reason it works know allthough i didnt change anything.

    I dont know where the misstake was.

Similar Threads

  1. Anyone know how GroupLayout works?
    By ProgrammingPup in forum Advanced Java
    Replies: 5
    Last Post: 12-02-2009, 12:12 AM
  2. Replies: 10
    Last Post: 10-11-2009, 08:07 PM
  3. Javascript works in firefox not IE
    By bghwebmaster in forum Advanced Java
    Replies: 5
    Last Post: 09-29-2009, 02:15 PM
  4. sound works then stops!
    By smileii in forum CLDC and MIDP
    Replies: 0
    Last Post: 09-26-2009, 01:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •