Results 1 to 6 of 6
  1. #1
    Grid_iso is offline Member
    Join Date
    May 2011
    Posts
    12
    Rep Power
    0

    Default How do you check a constantly changing int from another class.

    So I have this class called Claw and the object in it is always moving along the x axis of the jframe.
    I need to know how to check the consistently changing x axis to see if it goes past a certain number like 450 for example, and if this happens I need a boolean called something (e.g private boolean pastpoint;) to become true but this all needs to happen in the Jpanel to be of any use to what I want to do but I cant seem to figure out how to do this. So I guess... how would I do this, any code examples or hints would be much appreciated.

    Here is where I think my pos.x can be taken from, but if it isint .

    Java Code:
    	public Claw(int x, int y) {
    		pos = new Point(x, y);
    		direction = STOP;
    	}
    I got something in the jpanel which sets where the objects starting point is, maybe it can be checked for change as well, really not sure how to do this.

    Java Code:
    		yourClaw = new Claw(250, 0);
    Oh and if anyone could tell me how to lock the option to re size the game window that would be cool too :)

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    To lock the size, there should be a method like JFrame.setResizable(boolean), check the JFrame API for more info.

    Perhaps you could have the method which moves the object do the checking for you? How is the object moved exactly? Is there a loop? If so, have you tried checking in the loop? Showing more code may be helpful as well.

  3. #3
    Grid_iso is offline Member
    Join Date
    May 2011
    Posts
    12
    Rep Power
    0

    Default

    I have a jpanel that checks the movements I do, at a certain x point I need an object from another class follow the same key presses as the Claw class. No loops just an action event which keeps updating the objects movements. I would show more of the code but I don't want to run the risk of my code just happening to be the same as someone elses in my course. Basically I need a piece of code that consistently checks pos.x against its own int. Thanks for the help :)

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    So the JPanel has a point which it maintains? Do you have someway to access that point? If so, they other class should be able to just access the point and test where it is. It's hard to say without some more code. Could you perhaps try to portray the problem in a small program that runs? Short, Self Contained, Correct Example

  5. #5
    Grid_iso is offline Member
    Join Date
    May 2011
    Posts
    12
    Rep Power
    0

    Default

    thanks will look into that. Thanks for the help, mat give more detail later but g2g.

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default

    You could make use of the classes PropertyChangeListener, PropertyChangeEvent, SwingPropertyChangeSupport.

    Or you could go with the Observer / Observable pattern.

    mat give more detail later but g2g.
    What?

    db

Similar Threads

  1. Replies: 1
    Last Post: 05-16-2011, 01:19 PM
  2. Changing GUI labels from another class
    By porchrat in forum New To Java
    Replies: 15
    Last Post: 02-08-2011, 09:54 AM
  3. NetBeans GUI Builder + constantly updating information
    By Inventor22 in forum New To Java
    Replies: 5
    Last Post: 07-07-2010, 11:27 PM
  4. check me my class please
    By javanew in forum New To Java
    Replies: 2
    Last Post: 05-05-2010, 02:58 AM
  5. JDBC class check
    By DavidBainbridge in forum New To Java
    Replies: 4
    Last Post: 08-17-2009, 12:52 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
  •