Page 1 of 2 12 LastLast
Results 1 to 20 of 23

Thread: Toggle Trobble

  1. #1
    pottsmgg is offline Member
    Join Date
    Sep 2010
    Location
    OSAGE BEACH MO
    Posts
    10
    Rep Power
    0

    Default Toggle Trobble

    Why does the second not work?

    MC_Run() event from button.


    This works starts red not visible.. red not visible ..red not visible

    [code]
    @Action
    public void MC_Run()
    {
    int iii;
    int test_delay = 2000000000;
    System.out.println("start toggle");
    Toggle();
    System.out.println("end toggle");
    }

    Does not work starts red then not visible after end statement


    [code]
    @Action
    public void MC_Run()
    {
    int iii;
    int test_delay = 2000000000;
    System.out.println("start toggle");
    Toggle();
    for(int ii=0;ii<=test_delay;ii++){ iii = 0 ; iii++; }
    for(int ii=0;ii<=test_delay;ii++){ iii = 0 ; iii++; }
    for(int ii=0;ii<=test_delay;ii++){ iii = 0 ; iii++; }
    Toggle();
    System.out.println("end toggle")
    }

    Called by both


    [code]
    @Action
    public void Toggle()
    {
    if(jPanel2.isVisible())
    jPanel2. setVisible(false);
    else
    jPanel2.setVisible(true);
    }

  2. #2
    pottsmgg is offline Member
    Join Date
    Sep 2010
    Location
    OSAGE BEACH MO
    Posts
    10
    Rep Power
    0

    Default test code

    sorry i missed the code tag the first time.

    Why does the second not work?

    MC_Run() event from button.


    This works starts red not visible.. red not visible ..red not visible

    Java Code:
    @Action
    public void MC_Run()
    {
    int iii;
    int test_delay = 2000000000;
    System.out.println("start toggle");
    Toggle();
    System.out.println("end toggle");
    }
    Does not work starts red then not visible after end statement


    Java Code:
    @Action
    public void MC_Run()
    {
    int iii;
    int test_delay = 2000000000;
    System.out.println("start toggle");
    Toggle();
    for(int ii=0;ii<=test_delay;ii++){ iii = 0 ; iii++; }
    for(int ii=0;ii<=test_delay;ii++){ iii = 0 ; iii++; }
    for(int ii=0;ii<=test_delay;ii++){ iii = 0 ; iii++; }
    Toggle();
    System.out.println("end toggle")
    }

    [/code]

    Called by both


    Java Code:
    @Action
    public void Toggle()
    {
    if(jPanel2.isVisible())
    jPanel2. setVisible(false);
    else
    jPanel2.setVisible(true);
    }

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,585
    Rep Power
    23

    Default

    What is the posted code supposed to do/test? Please explain.
    Can you explain: "Does not work"

  4. #4
    pottsmgg is offline Member
    Join Date
    Sep 2010
    Location
    OSAGE BEACH MO
    Posts
    10
    Rep Power
    0

    Default Why can I not time the panel to be red and not red?

    MC_Run() is an event from button.

    Objective is to simulate an LED screen warning with a message
    that can be seen from a distance much like morse code in an LED.

    The code below works.

    1)Push the button
    2)print start message
    3)panel changes to not visible
    4)print end message
    5)push button
    6)print start message
    7)panel changes to red
    8)print end message

    this cycle repeats as long as you push the button

    Java Code:
    @Action
    public void MC_Run()
    {
    int iii;
    int test_delay = 2000000000;
    System.out.println("start toggle");
    Toggle();
    System.out.println("end toggle");
    }
    This does not work.
    Expected
    1)push the button
    2)print start message
    3)the panel changes to not visible
    4)then wait 4-6 seconds
    5)panel changes to red
    6)print end message

    Actual action
    1)push the button
    2)print start message
    4)then wait 4-6 seconds
    6)print end message
    5)panel changes to not visible

    Java Code:
     
    @Action
    public void MC_Run()
    {
    int iii;
    int test_delay = 2000000000;
    System.out.println("start toggle");
    Toggle();
    for(int ii=0;ii<=test_delay;ii++){ iii = 0 ; iii++; }
    for(int ii=0;ii<=test_delay;ii++){ iii = 0 ; iii++; }
    for(int ii=0;ii<=test_delay;ii++){ iii = 0 ; iii++; }
    Toggle();
    System.out.println("end toggle")
    }
    Called by both

    Java Code:
     
    @Action
    public void Toggle()
    {
    if(jPanel2.isVisible())
    jPanel2. setVisible(false);
    else
    jPanel2.setVisible(true);
    }

  5. #5
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    You can be more "accurate" halting a threads execution with:

    Java Code:
    Thread.sleep(6000);
    Thread (Java Platform SE 6)

    useful instead of those for loops

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,585
    Rep Power
    23

    Default

    Please create a small program that compiles and executes and demonstrates the problem.
    If there are two competing code sections put them in an if(true){version 1}else{version 2} block
    so each can be tested by a simple code change or even by passing an arg to the main

  7. #7
    pottsmgg is offline Member
    Join Date
    Sep 2010
    Location
    OSAGE BEACH MO
    Posts
    10
    Rep Power
    0

    Default That is the test program

    This is the code.

    The code missing is the java for the Java application, for the frame, for the panel and for the button.

    The difference is that I comment out part of the code.

    as follows

    Java Code:
    @Action
    public void MC_Run()
    {
    int iii;
    int test_delay = 2000000000;
    System.out.println("start toggle");
    
    Toggle();
    
    /*
    
    for(int ii=0;ii<=test_delay;ii++){ iii = 0 ; iii++; }
    for(int ii=0;ii<=test_delay;ii++){ iii = 0 ; iii++; }
    for(int ii=0;ii<=test_delay;ii++){ iii = 0 ; iii++; }
    Toggle();
    
    */
    
    System.out.println("end toggle")
    }

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,585
    Rep Power
    23

    Default

    Please create a small COMPLETE program that compiles and executes and demonstrates the problem.

    Someone has to do those steps, I suggest it should be the person looking for help.

  9. #9
    pottsmgg is offline Member
    Join Date
    Sep 2010
    Location
    OSAGE BEACH MO
    Posts
    10
    Rep Power
    0

    Default Toggle netBeans 6.9.1

    This is a Java and NetBeans IDE 6.9.1 Project.
    How do I send you the Project file?
    The button ,on the panel, on the frame, has an event "on click" which runs
    MC_Run.

    Sorry but I do not understand what you are asking for.

  10. #10
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,585
    Rep Power
    23

    Default

    I do not understand what you are asking for.
    A program that I can download, compile, execute that demonstrates your problem.
    Please create a small COMPLETE program that compiles and executes and demonstrates the problem.

  11. #11
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    potts just post a small program source that demonstrates you problem if you are not sure. In particular showing how jpanel2 is constructed and implemented. cheers

  12. #12
    pottsmgg is offline Member
    Join Date
    Sep 2010
    Location
    OSAGE BEACH MO
    Posts
    10
    Rep Power
    0

    Default

    Lets call it quits. The code generated by Netbeans is protected and cannot be changed. The code has some .h files, some property files and is long. it also has lib files and could only be compiled via the Java Netbeans IDE. I have had this same problem on MS Visual C++, MS Visual C# and MS Visual Basic. In MCU embedded code the problem was in returning from a ISR the stack was reset so you had to keep track of the led on of off after the ISR. I am assuming I am experiencing the same type of problem. I was hoping to emulate a toggled LED on a screen on a laptop.

    Thanks for your effort.
    Martin

  13. #13
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,585
    Rep Power
    23

    Default

    Seems a lot of students don't know how to write a program. They are tied to using an IDE

  14. #14
    pottsmgg is offline Member
    Join Date
    Sep 2010
    Location
    OSAGE BEACH MO
    Posts
    10
    Rep Power
    0

    Default

    I wrote my first program in 1957. I challange you to write a program, other than in assembly, which emulates a blinking LED where the pulse time for on off is variable( 10% on 90% off or 75% on 25% off). This is to run on desktop or laptop and use the monitor screen to emulate the LED. Most MPU use the blinking led program instead of hello world.

  15. #15
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,585
    Rep Power
    23

    Default

    Looks like an app for a Timer and Random number generator and a loop.
    Show a color, wait some time, turn color off, wait some time, show color, wait some time, turn off color, etc.

  16. #16
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by pottsmgg View Post
    I wrote my first program in 1957. I challange you to write a program, other than in assembly, which emulates a blinking LED where the pulse time for on off is variable( 10% on 90% off or 75% on 25% off). This is to run on desktop or laptop and use the monitor screen to emulate the LED. Most MPU use the blinking led program instead of hello world.
    If you have this much experience, then creating a small Swing application without NetBeans-generated code that at least attempts a solution should be trivial for you to create. If you do this and post it, we can help you. Or we can throw insults back and forth. Your choice.

  17. #17
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,585
    Rep Power
    23

    Default

    here's an hour's worth of work: http://normsstuff.zxq.net/Testing/ToggleApplet.html

    That excludes the graphics which I borrowed from a program named: DoubleBufferWithBufferedImage.
    Last edited by Norm; 09-10-2010 at 11:25 PM.

  18. #18
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Ah Norm I would not have, an hour could never be 60 years

  19. #19
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,585
    Rep Power
    23

    Default

    Oh well, I did it for a fellow ShowMe state res.

  20. #20
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Quote Originally Posted by Norm View Post
    Oh well, I did it for a fellow ShowMe state res.
    ...suppose you are right :o

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 4
    Last Post: 01-04-2010, 01:23 PM
  2. [SOLVED] Toggle Mouse Left-Right Handed
    By sirwiggles in forum New To Java
    Replies: 4
    Last Post: 04-10-2009, 10:27 PM
  3. Checking toggle state of a menu item
    By xsive in forum SWT / JFace
    Replies: 1
    Last Post: 09-22-2008, 02:42 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
  •