Results 1 to 20 of 23
Thread: Toggle Trobble
- 09-02-2010, 03:55 AM #1
Member
- Join Date
- Sep 2010
- Location
- OSAGE BEACH MO
- Posts
- 10
- Rep Power
- 0
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);
}
- 09-02-2010, 04:05 PM #2
Member
- Join Date
- Sep 2010
- Location
- OSAGE BEACH MO
- Posts
- 10
- Rep Power
- 0
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"); }
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); }
- 09-02-2010, 04:17 PM #3
What is the posted code supposed to do/test? Please explain.
Can you explain: "Does not work"
- 09-02-2010, 05:47 PM #4
Member
- Join Date
- Sep 2010
- Location
- OSAGE BEACH MO
- Posts
- 10
- Rep Power
- 0
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"); }
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") }
Java Code:@Action public void Toggle() { if(jPanel2.isVisible()) jPanel2. setVisible(false); else jPanel2.setVisible(true); }
- 09-02-2010, 05:52 PM #5
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 12
You can be more "accurate" halting a threads execution with:
Java Code:Thread.sleep(6000);
useful instead of those for loops
- 09-02-2010, 06:15 PM #6
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
- 09-02-2010, 11:57 PM #7
Member
- Join Date
- Sep 2010
- Location
- OSAGE BEACH MO
- Posts
- 10
- Rep Power
- 0
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") }
- 09-03-2010, 12:01 AM #8
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.
- 09-03-2010, 05:46 AM #9
Member
- Join Date
- Sep 2010
- Location
- OSAGE BEACH MO
- Posts
- 10
- Rep Power
- 0
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.
- 09-03-2010, 01:20 PM #10I do not understand what you are asking for.
Please create a small COMPLETE program that compiles and executes and demonstrates the problem.
- 09-04-2010, 02:35 AM #11
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 12
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
- 09-10-2010, 06:02 AM #12
Member
- Join Date
- Sep 2010
- Location
- OSAGE BEACH MO
- Posts
- 10
- Rep Power
- 0
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
- 09-10-2010, 01:13 PM #13
Seems a lot of students don't know how to write a program. They are tied to using an IDE
- 09-10-2010, 01:53 PM #14
Member
- Join Date
- Sep 2010
- Location
- OSAGE BEACH MO
- Posts
- 10
- Rep Power
- 0
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.
- 09-10-2010, 02:00 PM #15
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.
-
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.
- 09-10-2010, 08:05 PM #17
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.
- 09-11-2010, 12:01 AM #18
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 12
Ah Norm I would not have, an hour could never be 60 years
- 09-11-2010, 12:03 AM #19
Oh well, I did it for a fellow ShowMe state res.
- 09-11-2010, 12:09 AM #20
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 12
Similar Threads
-
Can you toggle between look and feel, want to make different "themes"
By ryuzog in forum New To JavaReplies: 4Last Post: 01-04-2010, 01:23 PM -
[SOLVED] Toggle Mouse Left-Right Handed
By sirwiggles in forum New To JavaReplies: 4Last Post: 04-10-2009, 10:27 PM -
Checking toggle state of a menu item
By xsive in forum SWT / JFaceReplies: 1Last Post: 09-22-2008, 02:42 PM
Bookmarks