Stepping through an algorithm - can't do it in java?

I'm trying to solve a tiling problem displayed in a GUI. The problem is, I need the algorithm to solve the problem step by step. But whenever I click start, it just solves it. Here's my code.
if (e.getSource() == start) { //push the start button
     while (!isSolved(boxes)) { //until the puzzle is solved
          if (condition) {
               right.doClick(); //click on the rightButton
          else {
               left.doClick(); //click on the leftButton
          try { /sleep for 1000 seconds so i can see the move
               Thread.sleep(1000);
          } catch (InterruptedException e1) {
               // TODO Auto-generated catch block
               e1.printStackTrace();
}What's wrong? I make it sleep after every iteration of the while loop but instead it doesnt show the intermediate steps. It does wait the 1 second after every iteration, but none of the steps are shown on the gui - the buttons don't appear to get pushed every second. It should show the steps every second, right??
Please help
Thanks in advance.
jboolean23

I'm not sure how to do it on another thread. Could
you please explain?Swing runs a special Thread called the dispatcher thread, which does all the GUI management stuff, redraws and so on.
When it calls back to your actionPerformed method or whatever the callback is on that thread. The important thing is that nothing in the way of screen updates can happen untill that call returns. So your actionPerformed should return withing a fraction of a second (the only common exception is when it calls a model dialog).
In a case like this what it needs to to is to build and start a new thread to do the long-running process, and then return, leaving the child thread doing its stuff.
To start a thread create a class which implements Runnable. Usually an anonymous class will to the job. Then you pass an object of this class to the constructor of a new Thread. Call start() and the Thread is up and running.
However, when such a thread requires changes to be made in what's on display the updates need to be done back on the dispatcher thread. What it does is to create another Runnable class and put it on the dispatcher thread's TODO list.
Learn to use small, often anonymous classes for these purposes. And that goes for ActionListener classes too - don't make your JFrame or whatever the ActionListner.
In a case like this you should probably also disable the control that starts the model while the model is running.
Starting a thread using an anonymous class would look something like this:
modelThread = new Thread(new Runnable() {  // anonymous class syntax
     public void run() {  // this is the code that's run as the thread's body
              doThreadStuff(); // a private method of the outer class
        },   // end of anonymous class definition
      "Model Thread");  // give the thread a name - it helps with debugging
modelThread.start();To do screen updates from a background thread like this use EventQueue.invokeLater()

Similar Messages

  • Can you set a BREAKPOINT and step through it

    Hello all,
    How do set a breakpoint in the app so that one can step through it and no where it is failing and the value of the variables returned?
    Thanks

    If you are trying to debug server side PL/SQL program units, you could use DBMS_DEBUG.
    http://download-west.oracle.com/docs/cd/B14117_01/appdev.101/b10802/d_debug.htm#996728

  • Preview : Can't step through pdf slideshows

    I've noticed in Preview that if you open a PDF and go into slideshow mode, you can't step through the slides with the arrow keys (or even the spacebar) until you hit the play button, wait a bit, then pause. This is different from Tiger, and very strange in general.
    I was thinking of ways to emulate the way it's done in Tiger - are there any settings I can change in the ~/Library/Preferences folder, through editing a plist file or via the command - line?
    Thanks,
    - Craig

    In the meantime this workaround might help: http://discussions.apple.com/thread.jspa?messageID=5770205&#5770205

  • When my new MacBookPro/Lion awakes from sleep I get network Diagnostics telling me I'm not connected to the internet. After I step through ND it says connection is fine and I can connect. software bug? Corrupted file carried forward from my old Mac?

    When my brand new MacBookPro awakes from sleep it has lost its internet connection. It goes to Network Diagnostics and I need to step through all the pages to get to the end where it says connection is o.k. Is this a bug in Lion or could it be a corrupt file migrated over from my old MacBook Pro which would frequently lose its Airport connection and couldn't be reconnected until it cooled down. (This one always shows full bars on the Airport indicator).

    That's definitely just paranoia.  First, because in sleep mode, there's no internet connection.  The computer might as well be turned off as far as the network is concerned, and there's no activity in the computer other than a bare trickle of electricity to maintain the RAM.  The processor is doing nothing.
    Second, Macs are quite difficult to hack, and if you're on a wireless network, the wireless router protects you from incoming attacks from the outside world.
    Of course, you should be able to leave Safari open with no open windows and not affect your ability to get online when it wakes up.  If you can reproduce that reliably, and if I can as well (haven't had a chance to try it yet), then it should be reported to Apple.

  • Can I instruct the debugger to step through triggered events as well?

    I have the following statements in my code:
    Public Class Class1
    Public Shared Sub TestClass()
    Dim ExlApp As Excel.Application = CType(AddinModule.CurrentInstance, TimeTracker.AddinModule).ExcelApp
    ExlApp.Range("A1").Value = "Test"
    ExlApp.Range("A2").Value = "When I press F11 the debugger jumps to this row from test"
    End Sub
    End Class
    When I step through the debugger, it jumps directly from the first statement above to the second. But inbetween those rows some events are triggered. Is there any way to tell the debugger to not jump over these events but instead step into these events?

    Hi JP3O,
    Since it is related to the specific VB app, to really repro this issue, could you share me the sample?
    >>But inbetween those rows some events are triggered.
    Maybe you could add breakpoints in your events, and then debug your whole app with "Start debugging (F5)", and make sure that the code is really called (the breakpoints were hit)or it has been called before the code shared in your thread.
    Or it is related to the JIT:
    https://msdn.microsoft.com/en-US/library/7ad07721(v=vs.100).aspx 
    If the breakpoints in evens are not hit, please check whether you could get any message if you put the mouse on the breakpoints. Maybe it is related to the symbols loaded or others.
    If you get any latest information, please feel free to let me know.
    Best Regards,
    Jack
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Applescript no longer steps through iCal events in sequence

    Hi all,
    I have been using an Applescript that someone on this forum helped me write a few years ago to put unique combos of events into iCal and it has worked perfectly for me, although this year it has begun to jump around within iCal when it is adding events. In other words it used to step through the calendar and add events day by day, progressing chronologically. Now it still accomplishes the task but starts (currently) with May 1 of 2011 and moves to May 16th ... The fact that it still works is cool, but it has slowed the applescript down quite a lot.
    Here is a section of the script...thanks, dan
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px; height: 340px;
    color: #000000;
    background-color: #FFDDFF;
    overflow: auto;"
    title="this text can be pasted into a HTML editor">
    repeat with theEvent in (events of calendar "School Calendar 10-11")
    if isitacycleday contains (summary of theEvent) then
    --Gets the current day and the cycle day number
    set cycleday to summary of theEvent
    set cycleDate to (start date of theEvent) + 1 * hours
    set cycleNumber to last character of cycleday as integer
    --There are always 7 periods in every day
    repeat with periodNumber from 1 to 6
    --Gets the subject from periodCycle
    set theSummary2 to item periodNumber of item cycleNumber of periodcycle2
    set theSummary to item periodNumber of item cycleNumber of periodCycle
    --Checks to see if there's a subject for this period, if not skips to next one
    if theSummary2 is not "" then
    set theStart to date (startTime of item periodNumber of periodTimes) of cycleDate
    set theEnd to date (endTime of item periodNumber of periodTimes) of cycleDate
    --Makes the event in the calender whose name is defined at the top of the script
    make new event at end of calendar TargetCalendar with properties {summary:theSummary, start date:theStart, end date:theEnd}
    end if
    end repeat
    end if
    end repeat </pre>

    Hi Bernard,
    right, I believe you were the one that came up with this script! It still does the trick, although it does begin adding new events at different times depending on when the cache was last deleted (i think). I've used the Onyx program to do this and indeed it influences the start date for the creation of new events via your script, so I don't think it has anything to do with the master calendar. Since I repeatedly run this script to make new events and then export the calendar, delete it, make a new untitled calendar and then run the script again... I've found that iCal and the applescript sloooow down over time and it is best to quit both, maybe even restart and then start the process again. Guess I might never figure this one out.
    Thanks for the help,
    dan

  • Stepping through a poorly formatted xml file

    Hi, this forum worked a charm earlier so I'm hoping it will go 2 for 2.
    Through a httpservice I'm reading an XML file into a ArrayCollection. Because the XML is so poorly formatted I'm having to write some very sloppy code just to step through 20 results. I have no control over the XML.
    XML Example (can be anywhere from 0 to 20 results):
    <results>
        <game>
            <type>game</type>
            <id>321</id>
            <name>gamename</name>
            <image>i34d.png</image>
        </game>
        <character>
            <type>character</type>
            <id>1123</id>
            <name>john</name>
            <image>sds.png/image>
        </character>
        <game>
            <type>game</type>
            <id>432</id>
            <name>examplename</name>
            <image>g2dss.png</image>
        </game>
    </results>
    Each result can be one of 7 types (I've done only 2, game and character, in my example). The order of them I really want to preserve in my ArrayCollection as it's very relevant.
    Here is the (very) sloppy way I'm currently loading each result into my AC:
    //container array
    var ac2:ArrayCollection = new ArrayCollection;
    //I do a block like this for EVERY results type. Meaning 7 in total...
    if (service2.lastResult.response.results.character) {
         var characterAC:ArrayCollection = new ArrayCollection;
         if (service2.lastResult.response.results.character is ArrayCollection) {
         //there is more than 1 entry
         characterAC = service2.lastResult.response.results.character as ArrayCollection;
         } else {
              //There is only 1 entry. Need to MAKE it an ArrayColleciton
              characterAC = new ArrayCollection([service2.lastResult.response.results.character]);
            //Add all characters to AC
         ac2.addAll(characterAC);
    The two major problems with this code is: 1, it's stupidly bloated and 2, ac2 no longer maintains the order of the XML response. First it puts all <character> into my AC, then it puts all <game> into AC. So on and so forth.
    In my head I'm trying to do something like this:
    ac2 = service2.lastResult.response.results.* as ArrayCollection;
    That would then load all results (regardless of type) into an ArrayCollection. I'm guessing a solution is not that simple...
    In an Ideal world, whoever created the XML api would just call each result <result> instead of the stupid type tags it currently uses.
    I hope all that makes sense.
    Regards,
    Zaph.

    @Zaph31,
    Why not use an XMLListCollection instead of an ArrayCollection?
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" initialize="init();">
        <mx:XML id="iWouldntHaveCodedXMLLikeThat" xmlns="">
            <results>
                <game>
                    <type>game</type>
                    <id>321</id>
                    <name>gamename</name>
                    <image>i34d.png</image>
                </game>
                <character>
                    <type>character</type>
                    <id>1123</id>
                    <name>john</name>
                    <image>sds.png</image>
                </character>
                <game>
                    <type>game</type>
                    <id>432</id>
                    <name>examplename</name>
                    <image>g2dss.png</image>
                </game>
            </results>
        </mx:XML>
        <mx:XMLListCollection id="xmlListColl" />
        <mx:Script>
            <![CDATA[
                private function init():void {
                    xmlListColl.source = iWouldntHaveCodedXMLLikeThat.children();
            ]]>
        </mx:Script>
        <mx:DataGrid id="dg" dataProvider="{xmlListColl}">
            <mx:columns>
                <mx:DataGridColumn dataField="type" />
                <mx:DataGridColumn dataField="id" />
                <mx:DataGridColumn dataField="name" />
                <mx:DataGridColumn dataField="image" />
            </mx:columns>
        </mx:DataGrid>
    </mx:Application>
    Peter

  • How to Step through Scripts that are sent to other Adobe Apps?

    A newbie question. In the ExtendScript Toolkit, I'm examining a script that uses BridgeTalk to send a script to Photoshop. I understand how to step through and examine the variables and functions that execute within the Bridge application. But how can I step through and examine the variables that are sent to the Photoshop application? The script executes without breaking as soon as the BridgeTalk script is sent.
    Thanks
    Help Getting Started with Bridge Scripting 

    I not sure that you can… What you may be able to do in some cases… is comment out the sending of the bridgetalk message and write the script constructed string message body to the toolkit console… That you might be able to cut and paste to a new script window and run with #target photoshop your other option would be to add lines $.writeln( variable ); at the relevant places in the message body construction…

  • Step through code ....VB debugging

    Hi,
    What window can I use to watch the variables value as you step through the code?
    Fenix  

    Please move your post to VS forum for a better assistance on this, this forum is for VB code related issues only:
    https://social.msdn.microsoft.com/Forums/en-US/home?forum=visualstudiogeneral
    Fouad Roumieh

  • Step through folder heirarchy to make all thumbnails

    New to Bridge but not [Apple]scripting. I see Bridge CS3 has almost no Applescript commands but all Javascript.
    My question is: Is it possible to tell Bridge to step through a big folder heirarchy and create thumbnails for all images?
    Any quick examples or reference appreciated.

    You can use two approaches -- you can use the ExtendScript Folder and File classes or the Bridge API's Thumbnail class.
    Download the Bridge SDK from www.adobe.com/devnet/bridge
    You'll find API documentation for the Folder and File objects in the JavaScript tools guild and of the Thumnail object in the Bridge CS3 JavaScript Reference (both in the SDK's docs folder).
    Please not that if you iterate over the files in a folder using the Thumbail object be sure to use this approach:
    var parent = new Thumbnail( new Folder("~/SomeImages") );
    var children = parent.children;
    for( var c = 0; c < children.length; ++c )
    //etc...
    And not...
    for( var c = 0; c < parent.children.length; ++c )
    // etc..
    The latter approach will be very slow and unreliable--each access to the Thumbnail.children property returns a new array of Thumbnails.
    -David Franzen
    Adobe Bridge Quality Engineer
    Adobe Systems, Inc.

  • Stepping through table is very slow

    LV 7.0 on Win 2K
    I use a table to display records of information. The table is filled once at entry to a user interface subprogram and the user has the possiblity to select certain records by clicking or stepping through with the cursor buttons.
    I have also written subprograms to sort the table by the various columns. The active row is used to provide more information e.g. displaying it in an image.
    Usually you would click on a line with the mouse, but somtimes it is more convenient to step through subsequent lines with the cursor buttons.
    As it turned out the latter is sometimes very slow.
    I tried to trace that behaviour in my program, but it seems that the problem is within labview. I reduced the vi to a simple loop
    where nothing is done with the table except to display the value. If you click on a line the value will follow instantaniously. If you click on a line at the top of the table and then step down with the cursor buttons the value will also follow very quickly. But when you do the same while beeing at the bottom this will take several seconds.
    I read several entries in the forum that describe similar problems when updating the table. Please note that this is a very static table here. The only thing that is happening, is a user interacting with it with the keyboard.
    The answers I saw so far, suggesting to keep the table small, or switching to other indicators etc. seem to overlook the reason why to use the table; that is tp have a compact display of a lot of ordered information. If the reason is really within LV runtime. Than NI has a nice task to improve LV next time :-(
    Gabi
    7.1 -- 2013
    CLA
    Attachments:
    Tableaccess.zip ‏65 KB

    Unfortunately, I can confirm that LabVIEW 7.1 shows the same slow behavior. Actually pressing "down arrow" on my rig is so slow, it seems to lock up the PC. (W2k)
    Interestingly, if you capture the "up" and "down" arrows with a filter event, there is no slowdown! Maybe you can used the attached rough draft (LabVIEW 7.0) to improve the UI experience to the user until NI fixes the issue.
    Enjoy!
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    Tableaccess.vi ‏266 KB

  • Stepping through an array

    Dear Forum members,
    Can anyone provide some guidance about how to step through and process data in an array file.  My outline LabVIEW program is to carry out the following steps:
    (1)  Take the first 5 samples from the data file (which contains 1000 samples)
    (2)  Process calculation
    (3)  Take the next 5 samples and process calculation Step (2) until the last batch of samples is reached
    I understand that I will need a loop (200 x 5 samples = 1000 samples analysed), but what I cannot get is how to programmatically step through the array rows, 5 at a time.  If anyone can help it would be appreciated.
    Regards,
    Solved!
    Go to Solution.

    Hi bunnykins,
    Using the Array Subset vi, this becomes a fairly simple problem.
    Just specify a start point and a length of data you want then you can pull a small array of data out of a large one.
    I have attached an example for you to tweak to whatever you need.
    Enjoy!
    -Rob Afton
    Electrical Engineering Intern
    GHSP
    Attachments:
    Subarray Calculations.vi ‏12 KB

  • After download of Photoshop, it will login in and register. it says no connect available, however I can login through browser.  Can you help

    after download of Photoshop, it will login in and register. it says no connect available, however I can login through browser.  Can you help

    If deleting opm.db file and Signing in , did not work , please follow below steps:
    Open C:drive and navigate to C:\Program Files (x86)\Common Files\Adobe.
    Open Adobe folder and delete folders named Adobe Application Manager and OOBE.
    Disable Anti-Virus and Firewall temporarily.
    click on the below link an download Adobe Application manager and install the same .
    http://download.adobe.com/pub/adobe/creativesuite/cc/win/ApplicationManager8.0_all.exe
    Once the installation process is completed, locate Adobe Application manager shortcut on Desktop and double click on it .
    It will start update process.
    Once update process is completed.
    Try Signing in to Photoshop application and check.

  • JMF Player: Stepping through an .mov file

    I have an applet that plays an .mov file and I would like to step through the file one frame at a time on command. Does any body know how I could do so? I also need the ability to start at a certain frame and play from that location.
    Any Ideas????
    Thanks,
    Andrew

    I figured it out!! They actually have an example that I never noticed before that you can look at. If you are interested go to this address:
    http://java.sun.com/products/java-media/jmf/2.1.1/solutions/Seek.html
    Thanks

  • Step Through java.* Classes With JDB

    Here is a simple program:
    public final class HelloWorld {
      private HelloWorld() {
      public static void main(String[] args) {
        System.out.println("Hello, World!");
    }I compile it with the -g option, and run it in jdb:
    javac -g HelloWorld.java
    jdb HelloWorld
    I set a breakpoint in the main function...now I'm wondering why I can't step through the String constructor (or whatever magic happens behind the String literal syntax) and the println method calls. When I use step, it just skips over them! I find that I can set breakpoints in library methods, and use list to see the source, but as soon as I step it flies out of the library method and back to mine. Does anybody know what gives? Is it because the libraries aren't compiled with the -g option???

    Thanks for your quick input. It seems you're right about the libraries. I made a dummy class compiled with the -g:none option, added some more lines in the first class (compiled with -g), and ran it through jdb. It stepped over the methods from the class with no debug info...same way as before.
    This is annoying. Sun should really provide debug versions of their libraries.
    So how does JBuilder let you step through library methods? Did they take the Sun source and recompile it? Do they have a magic debugger?

Maybe you are looking for

  • Packages in the queue don't exist in the tp buffer

    Hello Please could you help us???. We have import packages SAPKINBC9A, but we have a problem, because we obtein error  Packages in the queue don't exist in the tp buffer, what do we make for this packages exists in the buffer?? Thanks

  • Oracle functions in universe

    Hi Experts , I have created a set of user defined functions in oracle .I included these functions in Oracleen.PRM file . I restarted all the servers . Still i did not see my function in the universe .  My functions has two parameters . I need to pass

  • Exception report based on dates

    dear all, we all know that in order for us to do an exeption report it has to be based on numbers, has anyone try doing this based on a date before? a key figure date that is. thanks in advance for your reply.

  • Business Graphics 3D display

    Hi, I have created a Webdynpro Application with Business Graphics. I am trying to create a 3D display of Bar charts which is working fine with developer user id. When the same application is executed by an End User it displays in 2D. Can some one sug

  • How to use time capsule as hardisk?

    I googled but didn't find any answer so do you know how to use it I have the 1tb I want to use it as external hardisk I got a tip from a friend if I create a raid that would split the hardisk to two one for back up & one for regular use. But his tip