Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2010
    Posts
    3
    Rep Power
    0

    Default ActionEvent problem when combined with becker robots

    I have created a class (MapBuilder) whose object loads a map from a txt file that has been saved using a UI that is a class (MazeEditor) I also made. MapBuilder, therefore, creates a City object from the becker.robots class. It translates the visual information from MazeEditor into information on a txt file that can be used to create a city and robot from the becker.robots package.

    The MazeEditor UI has a button which calls a new MapBuilder object, purpose being so the user can actually run the maze they have just created from within the UI. Because the MapBuilder object creates this City object, the City object is all within what I believe to be a JFrame. This means that there is another JFrame open on top of the MazeEditor UI JFrame and they aren't modal. (I tell you this for more information in some bid to get to the bottom of this).

    I also believe that there is some sort of threading going on with the City object, since in any normal circumstance, when the City object is created, any robot commands from anywhere within a class referencing a robot within the City, to move it, are not executed until the user presses the 'Start' button which comes with the City object. Excuse my very loose and uneducated use of the threading element because I know very little about that side of things at the moment.

    My actual problem is this: If I ensure there are no commands to move the robot in any way, then the City object gets created successfully and everything is visible... Walls are where they should be and robot is where it should be. However, if I place any commands within the code to actually move the robot, then when the City object is created, I get an entirely blank JFrame window pop up... Completely grey, with nothing in it.

    I am not sure if it is something to do with the ActionListener function not finishing its code before the City object interrupts itself by somehow temporarily 'hanging' whilst waiting for the user to press the 'Start' button that is supposed to be there, for the robot to move.

    I tried to explain this as best I could, I hope anyone reading this was able to follow it. I haven't included any code as there is so much of it and I thought that maybe an explanation would suffice for this particular problem. If I am wrong then let me know and I will post up whatever code deemed necessary.

    What I will say, is that the function following the ActionEvent triggered when the user clicks the button, first ensures that there is a file to load by irrelevant means and then calls an object of MapBuilder by simply 'new MapBuilder(fileToBeLoaded). It is within MapBuilder that calls a new object of City.

    Any light on this would be hugely appreciated since I have spent literally days trying to figure this out, with all kinds of experiments and internet research, to no avail.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Yep you've got a threading or concurrency issue. It seems to me that you're trying to run a time or cpu-intensive process on the EDT (the Event Dispatch Thread) which is the main thread that runs Swing programs. To solve this, call the non-Swing code in a background thread such as a typical thread or a SwingWorker. For more information on this, please read this: Concurrency in Swing.

    Much luck!

  3. #3
    Join Date
    Apr 2010
    Posts
    3
    Rep Power
    0

    Default Will look into this

    OK, thank you for the clarification. This means I have a lot of research and reading to do as this area of Java I have little experience in, like I said in my first post. Thanks for the link, I will look into it and post back with either a solution or more problems... But hopefully the former!

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by J -+- Creation View Post
    OK, thank you for the clarification. This means I have a lot of research and reading to do as this area of Java I have little experience in, like I said in my first post. Thanks for the link, I will look into it and post back with either a solution or more problems... But hopefully the former!
    You're welcome. If you run into any problems trying to implement your solution, please come on back and let's see if we can help you. Best of luck and welcome to the forum!

  5. #5
    Join Date
    Apr 2010
    Posts
    3
    Rep Power
    0

    Default The answer may be a while yet

    Unfortunately, I am currently studying at university and at this time have about 2 weeks to hand in 3 different projects so I will have to dedicate my time to finishing them off.

    This Java maze editor thing is really a side project I created which at the risk of sounding like I am blowing my own trumpet, is way beyond what we are currently being taught, or what is required for the assignment. I enjoy programming so much (almost obsessively compulsive) that I kind of got carried away reading books and playing around with code and neglected 2 projects concerning other modules.

    Therefore, I am hoping that it is OK for me to keep this thread open for some time, just until I have handed in my projects and then I can crack back on with this. I say this because, upon embarking on reading this excellent new material you provided, I see that it is going to take some time that I don't have right now, for me to fully understand the whole thread concept which I can see is exceedingly valuable to the whole programming experience. So, providing it is OK for me to leave this thread open, I will check back in here in a couple of weeks or so with problems/solutions.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Rotation & translation combined
    By ScottVal in forum Java 2D
    Replies: 4
    Last Post: 02-27-2011, 07:57 PM
  2. Replies: 8
    Last Post: 02-28-2010, 09:36 AM
  3. [SOLVED] Actionevent problem
    By Cymro in forum New To Java
    Replies: 3
    Last Post: 04-04-2008, 08:11 AM
  4. becker.robots problem.
    By jesse in forum New To Java
    Replies: 1
    Last Post: 11-26-2007, 11:25 PM
  5. Need help with becker robots problem please.
    By L67Pontiac in forum New To Java
    Replies: 1
    Last Post: 07-06-2007, 08:50 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
  •