Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JOutlookBar

Reply
Thread Tools

JOutlookBar

 
 
Peter Cheung
Guest
Posts: n/a
 
      04-26-2012
http://www.youtube.com/watch?v=p6PzTWYgezM

how to make swing timer run faster? I use swing timer to draw the animation, but it runs slowly.
 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      04-26-2012
On Thursday, April 26, 2012 3:29:30 PM UTC-7, Peter Cheung wrote:
> http://www.youtube.com/watch?v=p6PzTWYgezM
> 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.

--
Lew
 
Reply With Quote
 
 
 
 
Peter Cheung
Guest
Posts: n/a
 
      04-27-2012
Lew於 2012年4月27日星期五UTC+8上午7時19分49秒 寫道:
> On Thursday, April 26, 2012 3:29:30 PM UTC-7, Peter Cheung wrote:
> > http://www.youtube.com/watch?v=p6PzTWYgezM
> > 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


The Swing timer is in here:
http://code.google.com/p/peter-swing...BarLayout.java

I already set it to 1ms, but it still runs slowly.

So the animation is not smooth.

thanks
 
Reply With Quote
 
Daniel Pitts
Guest
Posts: n/a
 
      04-27-2012
On 4/26/12 8:17 PM, Peter Cheung wrote:
> Lew於 2012年4月27日星期五UTC+8上午7時19分49秒 寫道:
>> On Thursday, April 26, 2012 3:29:30 PM UTC-7, Peter Cheung wrote:
>>> http://www.youtube.com/watch?v=p6PzTWYgezM
>>> 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.
>>
>> --
>> Lew

>
> The Swing timer is in here:
> http://code.google.com/p/peter-swing...BarLayout.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).
 
Reply With Quote
 
markspace
Guest
Posts: n/a
 
      04-27-2012
On 4/27/2012 10:11 AM, Daniel Pitts wrote:

> On 4/26/12 8:17 PM, Peter Cheung wrote:
>> I already set it to 1ms, but it still runs slowly.
>>
>> So the animation is not smooth.



> 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.



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.


> 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).



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.
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      04-27-2012
markspace wrote:
> Daniel Pitts wrote:
>> Peter Cheung wrote:
>>> I already set it to 1ms, but it still runs slowly.
>>>
>>> So the animation is not smooth.

>
>
>> 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.

>
>
> 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.
>
>
>> 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).

>
> 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
 
Reply With Quote
 
Peter Cheung
Guest
Posts: n/a
 
      04-28-2012
markspace於 2012年4月28日星期*UTC+8上午3時33分00秒 寫道:
> On 4/27/2012 10:11 AM, Daniel Pitts wrote:
>
> > On 4/26/12 8:17 PM, Peter Cheung wrote:
> >> I already set it to 1ms, but it still runs slowly.
> >>
> >> So the animation is not smooth.

>
>
> > 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.

>
>
> 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.
>
>
> > 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).

>
>
> 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 changed to use Runnable, animation become smooth now.
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
 
Reply With Quote
 
Peter Cheung
Guest
Posts: n/a
 
      04-28-2012
Lew於 2012年4月28日星期*UTC+8上午4時51分00秒 寫道:
> markspace wrote:
> > Daniel Pitts wrote:
> >> Peter Cheung wrote:
> >>> I already set it to 1ms, but it still runs slowly.
> >>>
> >>> So the animation is not smooth.

> >
> >
> >> 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.

> >
> >
> > 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.
> >
> >
> >> 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).

> >
> > 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


I don't have any javadoc, all the documents I wrote are in here http://code..google.com/p/peter-swing/w/list

I use Jigloo plugins to generate the UI code for pas few years, comfortablewith 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.

peter-swing's components and theme seems working, so i don't brother jigloo's code.
 
Reply With Quote
 
Arne Vajhøj
Guest
Posts: n/a
 
      04-28-2012
On 4/28/2012 6:10 AM, Peter Cheung wrote:
> Lew於 2012年4月28日星期*UTC+8上午4時51分00秒 寫道:
>> Have you gone over every line of this class and gained comprehension of what it does?


> 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.


But it did not work.

In which case you should actually read your code before
asking other people to read the code.

Arne


 
Reply With Quote
 
Daniel Pitts
Guest
Posts: n/a
 
      04-28-2012
On 4/28/12 3:06 AM, Peter Cheung wrote:
> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57