P
Peter Cheung
how to make swing timer run faster? I use swing timer to draw the animation, but it runs slowly.
how to make swing [sic] timer run faster?
I use swing [sic] timer to draw the animation, but it runs slowly.
how to make swing [sic] timer run faster?
I use swing [sic] timer to draw the animation, but it runs slowly.
Please provide code.
Best is to prepare a Simple, Self-Contained Compilable Example.
http://sscce.org/
Unless you show us the code, here in the newsgroup, in an example that isolates the issue, it can be difficult to diagnose your problem.
I would need to see how you're using the timer now to see what might be wrong. It could be a concurrency issue, or you might be running other thingson the Event Dispatch Thread (EDT) that you shouldn't, there might be other demands on the system (e.g., from the video recording software), or you simply might not have enough computing power to run it faster.
The solutions for those issues, if any of them pertain, is to make your code thread-safe, take things off the EDT, shut down other software and services while you record your video, or use a faster computer, respectively.
Lewæ–¼ 2012å¹´4月27日星期五UTC+8上åˆ7時19分49秒寫é“:how to make swing [sic] timer run faster?
I use swing [sic] timer to draw the animation, but it runs slowly.
Please provide code.
Best is to prepare a Simple, Self-Contained Compilable Example.
http://sscce.org/
Unless you show us the code, here in the newsgroup, in an example that isolates the issue, it can be difficult to diagnose your problem.
I would need to see how you're using the timer now to see what might be wrong. It could be a concurrency issue, or you might be running other things on the Event Dispatch Thread (EDT) that you shouldn't, there might be other demands on the system (e.g., from the video recording software), or you simply might not have enough computing power to run it faster.
The solutions for those issues, if any of them pertain, is to make your code thread-safe, take things off the EDT, shut down other software and services while you record your video, or use a faster computer, respectively.
The Swing timer is in here:
http://code.google.com/p/peter-swin...dvancedswing/outlookbar/OutlookBarLayout.java
I already set it to 1ms, but it still runs slowly.
So the animation is not smooth.
thanks
You're timer simply calls draw. Also, 1ms is really too fast, and will
cause more harm than good. You should aim for closer to 30hz->60hz. Try
around 33ms timer.
Ideally, the "work" for your animation should be done in the timer
handler too (so that your state changes on the timer, not just a redraw).
markspace said:I happen to know a little about animation (graphics is a personal hobby
of mine). The gold standard in animation is 25 frames per second, or 40
ms in between frames.
However, as a practical matter, much lower frames rates are acceptable.
Some cheaper animation, like some of the early so-called
"japanimation," used as little as 4 or 6 frames per second in parts of
their work.
I'd start at 250 ms. 1 ms will clearly overwhelm any normal desktop
system with too much work. Get 250 ms working, then see if it can be
improved.
This.
Peter, what I've looked at in your code base is pretty bad. Most of it
is really ugly generated code. Nothing has comments. There's no test
harness that I saw. You need to slow down and write some code by hand,
try to understand what is really going on. One good class is better
than 100 cruddy classes, and it is certainly my impression that the
latter is what you have.
I happen to know a little about animation (graphics is a personal hobby
of mine). The gold standard in animation is 25 frames per second, or 40
ms in between frames.
However, as a practical matter, much lower frames rates are acceptable.
Some cheaper animation, like some of the early so-called
"japanimation," used as little as 4 or 6 frames per second in parts of
their work.
I'd start at 250 ms. 1 ms will clearly overwhelm any normal desktop
system with too much work. Get 250 ms working, then see if it can be
improved.
This.
Peter, what I've looked at in your code base is pretty bad. Most of it
is really ugly generated code. Nothing has comments. There's no test
harness that I saw. You need to slow down and write some code by hand,
try to understand what is really going on. One good class is better
than 100 cruddy classes, and it is certainly my impression that the
latter is what you have.
Looking at this part of your code, Peter:
public class OutlookBarLayout implements LayoutManager2, java.io.Serializable, ActionListener
// Why not import Serializable?
// Where is the 'serialVersionUID'?
{
public Hashtable<String, Component> components = new Hashtable<String, Component>();
// Don't use Hashtable
public int buttonHeight = 31;
private int separatorHeight = 8;
private int totalHeight;
private int noOfButtonLeft;
private int top;
private int left;
// bad scope, AFAICT, should be a local variable - how is this part of the instance state?
private int right;
private Timer timer = new Timer(1, this);
// Shouldn't this be 'final'?
private Container target;
private int currentY;
public OutlookBarLayout() {
}
...
You don't need to specify a no-argument, empty constructor.
Where are your Javadoc comments?
Have you gone over every line of this class and gained comprehension of what it does?
Please answer the questions in detail.
Lewæ–¼ 2012å¹´4月28日星期å…UTC+8上åˆ4時51分00秒寫é“:
I use Jigloo plugins to generate the UI code for pas few years, comfortable with it and I usually won't review the generated-code.
I was a traditional-java-programmer, I write all swing code by myself
and didn't use any plugins to generate code. But now I changed, I use
plugin to generate UI code. I don't care much about the
generated-code by Jigloo plugin, if it works, everything fine to me.
I use Jigloo plugins to generate UI code, I am happy with that plugin and its generated code, so I would like to stay with it. thanks
I read that as "I have no idea what I'm really doing, and I'm happy with that."
God help me if I ever become that willfully ignorant.
It seems unlikely in your case.
Peter, Daniel raises an important point that will help you if you take it.. The
art of programming requires learning, and not superstition. If you don't know
what Jigloo does, and others have pointed out that it isn't working, thenyou
are helpless and powerless.
You also completely avoid the issue of the lack of documentation, the
plagiarism which turns out not even to be necessary in the first place, and
the general lack of utility of the project. These are serious issues, and
resolving them will go a long way to making you a good programmer.
Refusing to resolve them, and taking the sort of negative attitude towards the
universal advice you're receiving, are bad habits and will destroy your
capabilities.
Just sayin' ...
Lewæ–¼ 2012å¹´4月29日星期日UTC+8下åˆ12時08分46秒寫é“:
Thanks, let me finish my project first.
Peter said:why people in the forum look like angering something on me?
There are several reasons, and it's a fair question.
In the first place, I doubt that anyone is actually angry with you. Thereis a
difference between harshness and anger, although few people pay attentionto
the difference. You have triggered some harsh reactions, but people really are
trying to impart information to help you. The thing you do right is to engage
with the conversation, to keep responding to people and trying to understand.
As long as you do that no one should actually be angry with you.
What people have been telling you is important information. There are high
standards to professional programming, and they are rigorous. Early on you
showed some resistance to the information people gave you. This is especially
important in the area of ethics, which you violated. Besides that, you did not
respond to the comments regarding engineering flaws in your code. Your
responses to other comments, namely the lack of Javadocs and a build script,
were dismissive and constituted little more than, "I'm not doing that." We
know you're not doing that, we pointed out that you're not doing that. More
importantly we pointed out that you should be doing that, advice that you
ignore at your own cost.
Basically you have not shown interest in the wisdom and expertise that the
several very smart and knowledgeable people like Patricia Shanahan, Daniel
Pitts, markspace and Arne Vajhøj, to name a few, have shared. You don't give
reasons or logic for your decisions. You seem unaware and uninterested in
respect for copyrights. Instead of taking coding advice, you say, "Let me
finish my project," indicating that you are going to follow bad code witheven
more bad code.
Peter said:There is only one developer to develop peter-swing, yes, its me.
The primary goal for peter-swing is to make a new theme for my other project ...
If it is working, i don't want to spend time on writing comment,
i would like to spend time on peter-bochs rather.
I really don't need a build script, because eclipse can build. Eclipse can build a executable jar, it is enough for me. I don't know how hurt is my sentence "I'm not doing that", but in chinese, that sentence is not a offensive sentence.
But the words "Wow, shame on you, Peter", it is very offensive in my point of view.
Peter Cheungæ–¼ 2012å¹´4月29日星期日UTC+8下åˆ3時13分55秒寫é“:
why people in the forum look like angering something on me?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.