Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

to do composite panels that implements interfaces

mrsAngeloJul 16 2012 — edited Jul 27 2012
Hi,

I am not able to use panels that implement interfaces to realize a composition with other panels.

I would like to do this composition to decide at run time (using a method factory pattern) how the panels have to be arranged.

The the code is this...:
public ClassDialog extends JFrame {
Interface_one panel1 ;   
Interface_two panel2 ;  


public ClassDialog() {
    panel1 = new Panel1();
    panel2 = new Panel2();
    
    add(panel1);
    add(panel2)

}


public class Panel1 extends JPanel implements Interface_one{
..
}

public class Panel2 extends JPanel implements Interface_two{
..
}
When this code is wrote, the error: "no suitable method found for add" is showed in the IDE of NetBean..

I cannot understand what can be the reason because is not allowed to add component that implements interface..

So I would ask an explanation for the problem that I am having.

I should also get an advice how realize composition of panels using factory method pattern

thank you

regards

Angelo Moreschini
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 24 2012
Added on Jul 16 2012
10 comments
301 views