From: Joshua Cranmer on 15 Feb 2010 07:53 On 02/14/2010 11:38 PM, Amr wrote: > my problem is, how do i know whether to give<extends JPanel> or > <extends JFrame>? > both extenstions are used in the book. Traditionally, I make all of my custom panes extend JPanel; I can't really think of a good case where JFrame needs to be extended: if I need to make a powerful main window, I would likely just create a Main-ish class that extends nothing and constructs the elaborate JFrame. -- Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth
From: Arne Vajhøj on 15 Feb 2010 20:21 On 15-02-2010 07:53, Joshua Cranmer wrote: > On 02/14/2010 11:38 PM, Amr wrote: >> my problem is, how do i know whether to give<extends JPanel> or >> <extends JFrame>? >> both extenstions are used in the book. > > Traditionally, I make all of my custom panes extend JPanel; I can't > really think of a good case where JFrame needs to be extended: if I need > to make a powerful main window, I would likely just create a Main-ish > class that extends nothing and constructs the elaborate JFrame. Extending JFrame is often seen - including in examples from SUN. Arne
From: Arne Vajhøj on 15 Feb 2010 20:23 On 15-02-2010 02:26, markspace wrote: > Also, neither should extend ActionListener. Make that a separate class. > The behavior of being a JPanel (of JFrame) and the behavior of being an > ActionListener are fairly different. Don't make one object have both > behaviors, separate those two concepts so they're easier to deal with. > > You often see simple teaching examples where one single class does > everything: it extends ActionListener, extends JFrame, and assembles the > entire GUI too. This isn't really appropriate for larger programs, where > this "do it all" behavior would make maintenance more difficult. > Separate those concerns to different classes. Those do it all classes > are really only trying to save space so the demo can be as brief as > possible. Good advice. What is good for demo code is not necesarrily good for real world programs. Either a separate class or an anonymous class if the code is simple. Arne
From: Lew on 15 Feb 2010 20:37 Joshua Cranmer wrote: >> Traditionally, I make all of my custom panes extend JPanel; I can't >> really think of a good case where JFrame needs to be extended: if I need >> to make a powerful main window, I would likely just create a Main-ish >> class that extends nothing and constructs the elaborate JFrame. Arne Vajhøj wrote: > Extending JFrame is often seen - including in examples from SUN. Arne Vajhøj also wrote: >> What is good for demo code is not necesarrily good >> for real world programs. -- Lew
From: Arne Vajhøj on 15 Feb 2010 20:42 On 15-02-2010 20:37, Lew wrote: > Joshua Cranmer wrote: >>> Traditionally, I make all of my custom panes extend JPanel; I can't >>> really think of a good case where JFrame needs to be extended: if I need >>> to make a powerful main window, I would likely just create a Main-ish >>> class that extends nothing and constructs the elaborate JFrame. > > Arne Vajhøj wrote: >> Extending JFrame is often seen - including in examples from SUN. > > Arne Vajhøj also wrote: >>> What is good for demo code is not necesarrily good for real world >>> programs. :-) Yes. Arne
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: JFreeChart - Legend control with adding different series Next: Adding JPanel to JFrame |