Controlling A Loop With Buttons

Basically I need start and stop buttons for my loop which is in the main method. I figured I would use a boolean variable whose value is changed by the click of the buttons in a while statement. The problem is the loop is never started. So I must be following the wrong procedure. I would appreciate any help.

This is part of the code
public class MyClass extends JFrame implements ActionListener{
private JButton start, stop;
private boolean test;
.....//other variables
public MyClass() {
...initialize other variables
        test = false;
           setTitle("My Class");
           setLayout(new BorderLayout());
           grd = new MyGrid(W,H);
           add(grd);
     JPanel p = new JPanel();
     p.add(start = new JButton("Start"));
           p.add(quit = new JButton("Quit"));
           p.add(stop = new JButton("Stop"));
           add("South",p);
//My actionPerformed Looks like this
public void actionPerformed (ActionEvent e) {
        String s = e.getActionCommand();
        if ("Start".equals(s)) {
            flag= true;
        } else if ("Stop".equals(s)) {
            flag = false;
//...other methods
public  static void main(String []args){
          MyClass frame = new MyClass();
          JFrame.setDefaultLookAndFeelDecorated(true);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                 frame.setSize(FRAME_WIDTH,FRAME_HEIGHT);
                 frame.setVisible(true);
       while(frame.test == true){
         ///do the loop stuff
}//end main
}//end MyClass

Similar Messages

  • Control Drop Zone with Button State

    Does anyone know if you can control the display of a drop zone with the state of a button. I am working on an exercise video and would like change an image based on the selected state of three different buttons.

    Use auto actions on your buttons to jump to new (almost identical) menus with different drop zone video. Auto action can be set in the Button Property Inspector/Advanced Tab. Auto-action will automatically goto the jump target (another menu) upon selection of the button. Don't set an auto-action on the button the jumps to your desired target track.
    eg. - Create 3 menus A, B and C.
    "Menu A" should have: 1) "Button A" as the default selected button and a jump target to whatever track you want, 2) "Button B" should have auto-action that jumps to "Menu B" and 3) "Button C" should have auto-action that jumps to "Menu C".
    "Menu B" should have: 1) "Button B" as the default selected button, and a jump target to whatever track you want, 2) "Button A" should have auto-action that jumps to "Menu A" and 3) "Button C" should have auto-action that jumps to "Menu C".
    "Menu C" should have: 1) "Button C" as the default selected button, and a jump target to whatever track you want, 2) "Button A" should have auto-action that jumps to "Menu A" and 3) "Button B" should have auto-action that jumps to "Menu B".
    -k
    G5   Mac OS X (10.4.3)  
    G5   Mac OS X (10.4.3)  

  • Interrupt repeat loops with buttons

    Hi,
    How do I make buttons available to the user while I run a repeat loop?
    I'm doing a shell script in the background and I'm using a repeat loop to read out the log of the results. Meanwhile, I want to have a Cancel button available to the user.
    The button however doesn't respond while the repeat loop runs, while the rest of my UI is in fact updating (based on the incoming log). I'm even using a one second delay at the beginning of the loop.
    I'm using AppleScript Studio in Xcode/Interface Builder.
    Thanks,
    JW

    1. Create a control in the window which has some sort of boolean property (if you are using a progress bar, then you already have one, since a progress bar can be indeterminate, and you can check this).
    2. Set the handler which shows the window (or alters the window when the process begins) to set this boolean property to a particular value
    3. Have the "Cancel" button handler invert the property
    4. Have the repeat loop check the property as part of its boolean condition (as in "repeat while x is true")
    Note that if the window is going to go away anyway when the process is complete, then you can use the window's title to indicate the status: set the title to "Cancelling..." and have the repeat loop check whether the title of the window is "Cancelling...".
    You could also just create a global within the script file, and have the repeat loop check the status of the global, but that tends to lead, sooner or later, to overlapping reuse of a single global value, which is a bug.

  • Control FLV playback with button on different timeline

    I have an FLVPlayback instance on my stage within a movie
    clip within a movie clip eg.
    _root.showreel_mc.showreelHolder.showreel (where showreel is
    the instance name given to the FLV component itself)
    I already have a button that fades out showreel_mc in order
    to fade other content in but I also need it to pause the FLV so it
    doesn't keep playing in the background. I've tried this...
    _root.showreel_mc.showreelHolder.showreel.pause()
    But it doesn't work - anyone got any ideas? I'm using
    Actionscript 2.0.
    Cheers!

    I found the option to sync with rest of project under the options tab and this solved my problem.

  • In Search for Automatic Sliding Content with Buttons tutorial

    I would like to implement a cross screen sliding content. I would like this content to have buttons which allow to move from one section to another. I would like this buttons to be in the ON position when the corresponding section is on the screen.
    I would like it to start and sycle once automatically, yet to have user a control over it with buttons.
    Does any one know a good tutorial site where I can find something like that?

    check http://www.greensock.com/tag/tutorials/

  • Using timer/counter with PCI-6221/USB-6210 to control timed-loop VI

    Dear all,
    I need to ask about two devices and one of their functionalities, PCI-6221 and USB-6210. For our NI-based system, we need to control some timings in a Timed-Loop vi, for that currently we are using PCI-6221 and we give external TTL signal (at 1 kHz) to it,
    recenntly we need to make some changes and for that we found USB 6210 DAQ to be more suitable, but we need to clear ourselves on some specific things.
    Can the counter/timers functions available in the either PCI 6221 or USB 6210 can be used to control the Timed-loop VI by giving external clock or by using their own internal clock source?
    Although we are using external clock with the PCI 6221 but we want to know about the usage of their internal clock, also are controlling timed-loop also possible for USB-6210
    Also... What if we use the RTOS, are they still able to control the timed-loop VI  without giving any 'EXTERNAL CLOCK' and using the internal clock sources of the DAQs
    Waiting for reply,
    Bests,
    RaJaf
    Solved!
    Go to Solution.

    Ben,
    I having read previous email which I send earlier with general overview, we discussed in more detail within our team and I am giviing the specific answers.
    Please check in RED the most recent answers. Blue are the questions/suggestions by your side.
    1.    Using Internal hardware clock of PCI-6221 would enable us get rid of external clock, but how to divert the internal hardware clock to the current settings. Any idea  (can you provide us with some reference manul for otherwise). I mean is there some flag-bit etc. or VI
    2.       Is it also meant that with the installation of RTOS the timed-loop can directly get the timing source from the internal hardware clock PCI-6221? --- How???
    3.       In order to make desktop to work as RT system, what is the hardware (motherboard, processor, etc..) requirement? What are the LabVIEW modules (specific name) that needed to be installed? Our platform is LabVIEW 8.6. (Currently we have windows-7 with i7 core processor)
    What kind of application are you intending for this system? ---- high-speed laser scanning system.
    Are you most concerned about accuracy, speed, or responsiveness? To control the laser mirror scanner to move at 1 kHz or 2 kHz speed. On the other hands, using PCI-5105 (128 MB memory) as a DAQ for real-time/on-the-fly data processing.
    Bests,
    RAJAF

  • Control 32-bit register with buttons

    I am quite new with Labwindows.
    I need to control a lot of 32-bit registers by using buttons to set or reset each bits.
    (It would be so complicated to manage each button by  CALLBACK function).
    Is there a simple way to controll array of buttons in Labwindows ? Or is there even a concept for "array of buttons" ?
    Like in Labview with array and buttons as boolean variables.

    If you are using CVI 2010 or later you can use arrays of controls which can help you in this issue: here a tip on using them
    EDIT Wolfgang preceded me often! 
    Going a little bit further on his idea of a single callback for several controls, you can add to the controls appropriate callbackData with which can taylor the behaviour of the callback. Suppose you install a single callback on 32 buttons and add the bit index as callbackData on each of then with SetCtrlAttribute (..., ..., ATTR_CALLBACK_DATA, (void *)index); with index from 1 to 32: when you enter the callback you can simply read the callbackData you receive to immediately have the index of the bit to manipulate. The callbackData can only be assigned programmatically, you cannot set it in the UIR editor.
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • How can i control a slider with a button.

    Is it possible to control a slider with a button? It works like a automatic sliding gate. Is it possible? Where when you open the gate, it will slide slowly.. And can anyone help me with this..

    I was bored...
    The way this usually works is that I think of a simpler implementation once I click the Submit button... 
    Jim
    You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
    Attachments:
    gate.vi ‏15 KB

  • To Disble the Field in Table Control after clicking Save button

    Hi,
    I have a requirement as follows. i need to disable one field in the table control after clicking save button. i tried with SCREEN elements but it disabling whole the table control but i need to disable that particular one record only in the table control. i found Structure CXTAB_COLUMN in documentaion. it has the properties like invisible. can any body tell how can we disble that particular field in table control only for the one record. and how can we use CXTAB_COLUMN.
    Thanks in advance.

    hi,
    do like this...
    in USER_COMMAND_1000 module of PAI,
    MODULE user_command_1000 INPUT.
      CASE ok_code.
        WHEN 'BACK' OR 'UP' OR 'CANC'.
          LEAVE PROGRAM.
        WHEN 'SAVE'.
          fl = 1.
          GET CURSOR LINE lin.
      ENDCASE.
    ENDMODULE.                 " user_command_1000  INPUT
    and make on module disable in Loop Endloop in PBO.
    and write like this...
    MODULE disable OUTPUT.
      LOOP AT SCREEN.
        IF tab1-current_line = lin AND fl = 1.
          screen-input = 0.
        ELSEIF tab1-current_line < lin.
          screen-input = 0.
        ELSE.
          screen-input = 1.
        ENDIF.
        MODIFY SCREEN.
      ENDLOOP.
    ENDMODULE.                 " disable  OUTPUT
    here fl and lin both are type i.....
    and there will b one module in PBO
    MODULE tab1_change_tc_attr.
    in that put if condition....
    MODULE tab1_change_tc_attr OUTPUT.
      IF sy-ucomm <> '' AND sy-ucomm <> 'SAVE'.
        DESCRIBE TABLE itab LINES tab1-lines.
      ENDIF.
    ENDMODULE.                    "TAB1_CHANGE_TC_ATTR OUTPUT
    ur problem will solve...
    reward if usefull....
    Edited by: Dhwani shah on Jan 2, 2008 1:17 PM

  • I have defined a finite state machine: pb with button : they need to be click twice

    I have defined a finite state machine and also defined a call to a C dll enabling to kill processus  since in my state machine I have to sequence several exe and being able to interupt them (This is the goal of mu manageProc dll)
    for the moment I make my integration test with the notepad.exe process
    the create and kill seems to work
    but I have problem wth my finite state machine I need to click twice on the differnts button for a given state to be really effective
    I have also used glabal variable and an event controller ( without that I was unable to get ffedback oo buuton click
    So my question are
    Is my problem due to the use of a shift register
    Please tell me if you need other file to understand my problem
    Regards
    Thibaut
    Attachments:
    Spectro State MAchine .vi ‏77 KB

    Thibaut,
    You should put the event structure into its own parallel while loop rather than sharing the loop with the state machine. Typically the terminals of the controls will be placed inside the event case where they are read. At least inside the loop.
    Run your VI with execution highlighting on (the light bulb on the diagram toolbar). This will show you how dataflow works.
    You probably do not need most of your global variables. Appropriate use of shift registers and wires would eliminate them.
    Lynn

  • I can not control my cursor with the trackpad.  It moves randomly. It began after an Angry Birds update.  Anyone else have this problem?

    I have a late 2011 OS X Lion 10.7.4 that is only 6 months old.  For the first 4 months I had no problems, but then about 6 weeks ago I downloaded an Angry Birds update from the Apple App Store, and my problems began.  When playing Angry Birds the the new Angry Birds update for the first time the cursor began to jump around, moving on it's own as if someone else was controlling it.  After a few moments I became obvious I could not control the cursor with the trackpad. When I placed the tip of my finger gently in the center of the trackpad to try to hold the cursor still it becan switching from the game (desktop) to launchpad and mission control.  I then put the computer down so I was not even touching it, walked several feet away and the cursor still moved on it's own.
    I've done a lot of research over the last few weeks on related articles and realized this is a common problem with numerous different causes: PRAM settings,
    screen sharing, remote settings, having fingers accidently touch edges of trackpad, writst resting too close to trackpad, swollen battery, etc. and I don't think it's due to any of those issues.
    The problem came out of nowhere.  My computer stays at home, and is not used by anyone else.  At first it was just Angry Birds, but now it can happen at any time.  Sometimes hours or days go by when this does not happen, sometimes it happens so much I can't use the computer at all.  It can get so bad that I won't be able to click out of whatever I'm doing on my desktop, and I'll have to shut it down by holding the power button. 
    Has anyone else had this issue after updating Angry Birds?

    try a new/fresh apple brand cable and make sure it is the only usb cable in use. this worked for me, i noticed i had no problem with a lighting cable. i did a restore from scratch and from backup and it did not help me...and if you cant sync than you wont be able to get anything but apps back after the restore

  • Adobe Extension Manager loops with the following message: "The Extension Manager will now launch and

    Hi, whenever I open Dreamweaver CS5 I get this message:
    Adobe Extension Manager loops with the following message:
    “The Extension Manager will now launch and finish updating Dreamweaver”.
    Then the manager starts and I have to wait and click a few buttons until I can close it.
    How can I stop the Extension Manager popping up?
    Thanks for advice.

    Seems to be a lot of this going on. Wondering if we're wasting our time with this??!!

  • Having trouble with buttons in motion menus

    I'm having some problems with buttons in motion menus:
    - I've created a motion menu where some text (button names) fade in.
    - I set a loop point after the text has faded in completely.
    - I set the end condition to "loop"
    (there is some animation after the text fades in that I would like to loop)
    - I draw out 5 buttons and assign different overlay colors to each of the button states.
    The problem is that each time the motion menu jumps back to its loop point.. the menu seems to stutter - the overlay color on the currently selected button turns off for a second and the button is momentarily disabled (can't be selected). This problem only shows up on the actual dvd build. The buttons work smoothly when tested in the simulator.
    I can avoid this problem by losing the animation and just setting the end condition to "still".. but I was wondering if anyone knows if there is something I might have missed or could try as a workaround.
    17" powerbook g4   Mac OS X (10.4.5)  

    This problem only shows up on the actual dvd build. The buttons work smoothly when tested in the simulator.
    It could be how the DVD is reading the DVD (sort of the nature of DVD, everything is not exactly the same), because buttons will not show until the loop point and there may be a slight pause from end of animation in the menu to the loop point. And the overlay will turn off briefly when it hits the end.
    Visually what you can do is make the animation in a manner so that at the loop point the buttons are part of the background itself and make sure your loop point is at that point (or slightly after) so it looks like the button is there.
    For the most part the setting of still may work okay (really a creative call), sometimes listening to the same music/seeing samee animation may be too much (of course it depends on project) and you can jump to the loop point on the menu on subsequent calls

  • Display a message in a For Loop  with field value

    Hello All,
    pls,i wanna display a message in a For Loop with field value the code is:
    FOR Q1 IN GET_SUM_EXP_QUANTITY LOOP               .
    INSERT INTO PLN_PLAN_DISTRIBUTION_WAY
    (FIN_YEAR_CODE , MONTH_CODE , MATERIAL_CODE , DISTRIBUTION_WAY , EXPECTED_QUANTITY , GROUP_CODE)
    VALUES (:PLN_PLAN.FIN_YEAR_CODE , TO_CHAR(V_FROM_DATE,'MM') , Q1.MATERIAL_CODE , 1 , V_MONTHLY_QTY , Q1.GROUP_CODE);
    MESSAGE(':PLN_PLAN.FIN_YEAR_CODE'||:PLN_PLAN.FIN_YEAR_CODE ||' '||'V_FROM_DATE = '||TO_CHAR(V_FROM_DATE,'MM'), 'Q1.MATERIAL_CODE'||' '|| Q1.MATERIAL_CODE||' '||'DISTRIBUTION_WAY'||' = 1'||'EXPECTED_QUANTITY'||' = '|| V_MONTHLY_QTY||'GROUP_CODE'|| ' '|| Q1.GROUP_CODE);
    FORMS_DDL('COMMIT');
    How 2 display a message with the value:
    Q1.MATERIAL_CODE
    Q1.GROUP_CODE
    message(Q1.MATERIAL_CODE)     
    gave me numeric or value error on run time when pressed on button
    Regards,
    Abdetu..

    Thanks 4 reply..
    again they r in a For Loop as mentioned above...
         INSERT INTO PLN_PLAN_DISTRIBUTION_WAY
                                                           (FIN_YEAR_CODE , MONTH_CODE , MATERIAL_CODE , DISTRIBUTION_WAY , EXPECTED_QUANTITY , GROUP_CODE)
                                            VALUES (:PLN_PLAN.FIN_YEAR_CODE , V_REPAIR_MONTH , Q1.MATERIAL_CODE , 1 , V_REPAIR_Qty , Q1.GROUP_CODE);
    FORMS_DDL('COMMIT');
    The fields in bold r required to be displayed for testing puposes..
    this gives me numeric or value error in runtime..
    Best regards,
    Abdetu..

  • How do you start a loop with an event and end the loop when u release ....

    How do you start a loop with lets say an event of some sort, whether it be holding down a key or pressing the mouse click and then stopping the loop when you release that key or mouse button.?
    double c = 1.8, i = 1, max = 90, exp = 0;
    final double inc = 0.002; //speed at while it increases
    boolean f = false, g = false;
    while (true)
        while (f == false && stopMeter == false) //increasing speed going up to 90
            exp = Math.pow (c, i);
            i += inc;
            pAngle.setText (Math.round (exp) + "");
            if (exp > max)
                f = true;
                g = false;
            } //end if
        } //end while
        while (g == false && stopMeter == false)  //decreasing speed going down from 90
            exp = Math.pow (c, i);
            i -= inc;
            pAngle.setText (Math.round (exp) + "");
            if (exp < 1)
                g = true;
                f = false;
            } //end if
        } //end while
    } //end whilethis is a snippet of my increasing increments. Its for an angle meter. I can't get it to stop, when the user clicks or does something... the program just gets stuck in an infinite loop. I am still new to java and i do not know how to fix this.

    You are in the wrong forum. Try this one instead: http://forum.java.sun.com/forum.jspa?forumID=31
    /M

Maybe you are looking for

  • Open the WebI report from Xcelsius dashboard

    Hi All, I would like to know how to open the WebI report from the xcelsius dashboard. Looking at the previous posts I followed the following steps to implement the same but that is not working. Inserted the component URL button and used the folowing

  • Duplicate entries in Table T5UGJ - Garnishment notice letters printed twice

    Hi Experts, We have a scenario where duplicate entries have been created for an employee in the table T5UGJ. Hence when the notice letters were printed, they printed twice. Would there be any specific reason or any master data change in IT 0194 / IT1

  • XSAN No Controller

    Hi, My xsan shows no controller. Even I am unable to connect to Xsan. Even I the permission to Remove a computer is Grey But when I open from terminal using cvadmin it shows the controller. Can I add the previous controller again as its not showing i

  • [Oracle][ODBC][Ora]ORA-24801: illegal parameter value in OCI lob function

    Hi, I am trying to insert an xml doc into a column of Oracle table which has a datatype CLOB in JSP. PFB my code that I am using -- int id = 100; String st1 = "NEW"; String st2 = "WLR3_IN_1"; Date dt = new SimpleDateFormat("mm/dd/yyyy").parse("04/02/

  • SAP t-code F-05 to post Foreign currency valuation

    I have used SAP t-code F-05 to post Foreign currency valuation. After posting the entry H have reversed document in FB08 because of error. Unfortunately I want it to bring back to the original posting. I had reversed the reversal document in FB08. It