Results 1 to 5 of 5
  1. #1
    javan00b is offline Member
    Join Date
    Jan 2008
    Posts
    5
    Rep Power
    0

    Default Game of Life assignment

    I'm having trouble with getting user input for a game of life assignment. I am using a 2d array to calculate cell generations and calling a separate class with nested loops to generate graphics components, which are then added to a container with a grid layout. This all works fine. We are then supposed to be able to update the cells when the user clicks on them. I don't know how to do this. If I use a variable generated within the graphics component class, how do I pass this data to the main class? I'm thinking there is something simple that I'm missing.

  2. #2
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    If I use a variable generated within the graphics component class, how do I pass this data to the main class? I'm thinking there is something simple that I'm missing.
    you can implement a getData() method.
    or you can save it into file and read that file in main class

    or take a look at this example,

    Java Code:
    public class test{
    
    	static double x = 0.0;
    	
    	public static void main(String args[]){
    		System.out.println("Current value: "+x);
    		new SET().setData();
    		System.out.println("New value: "+x);
    		System.exit(0);
    	}
    }
    
    class SET{
    	public void setData(){
    		new test().x = 100;
    	}
    }
    correct me if im too far from your point.

    regards,
    sukatoa
    freedom exists in the world of ideas

  3. #3
    javan00b is offline Member
    Join Date
    Jan 2008
    Posts
    5
    Rep Power
    0

    Default

    Why might this not be working? (Sorry for the formatting). When I run it, it doesn't detect that the component was clicked.

    Java Code:
    GraphicsClass newg = new GraphicsClass(Array1[r][c]);
            
    boolean clicked = newg.returnClicked();
    boolean status1 = newg.returnStatus1();
    container1.add(newg);
    
            if (clicked==true){System.out.print("clicked");
              if (status1==false){
                Array1[r][c]="x";
                System.out.print("false");}
              else if (status1==true){
                Array1[r][c]="O"; 
                System.out.print("true");}              
              else
                System.out.print("error");
            }
    Last edited by javan00b; 04-28-2008 at 05:22 AM.

  4. #4
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    Can you show us your GraphicsClass?

    Many of your experts here are willing to test your code.
    freedom exists in the world of ideas

  5. #5
    javan00b is offline Member
    Join Date
    Jan 2008
    Posts
    5
    Rep Power
    0

    Default

    There is a mouseClicked event handler in the class. I have methods that return booleans for for when the mouse is clicked and what the status of the cell is. I think the problem is that these values are returned when the new component is created, and I need to get these values after cells have been added to the grid and the method in the main class (that creates the cells) has been called.

Similar Threads

  1. Replies: 2
    Last Post: 08-05-2010, 05:49 AM
  2. Servlet Life Cycle
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-28-2007, 10:57 AM
  3. for Assignment plz help
    By assamhammad in forum New To Java
    Replies: 1
    Last Post: 11-06-2007, 09:35 PM
  4. java assignment, need help bad.
    By carlos123 in forum New To Java
    Replies: 1
    Last Post: 11-06-2007, 05:53 PM

Posting Permissions

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