Re: Could this be done better
On 11/24/2014 15:11, Cecil Westerhof wrote:
Op Monday 24 Nov 2014 18:19 CET schreef Knute Johnson:
From the docs, JFrame:
"As a convenience, the add, remove, and setLayout methods of this
class are overridden, so that they delegate calls to the
corresponding methods of the ContentPane. For example, you can add a
child component to a frame as follows:
frame.add(child);"
so you can skip the call to getContentPane().
That was my mistake, I was looking at the wrong line.
Another way around that is to extend JComponent rather than JFrame and
add the component to the frame. For a while people were fairly adamant
about not extending JFrame but that's worn off a little lately. I often
extend JFrame for simple programs. It used to be that we thought we
might run some of them in applets but not so much any more.
Very small nit: The frame title is a parameter of the constructor.
You could have used:
super(description) as the first line.
When I try that I get:
ColourCycling.java:10: error: cannot reference description before supertype constructor has been called
super(description);
The error on the super call is because description is local rather than
a class field.
Have you looked at findbugs? It's a really cool tool to find poorly
designed code, orphans and other things. Its free.
http://findbugs.sourceforge.net/
--
Knute Johnson