Reputation: 121
I'm learning the different ways to position objects in GUI and I don't really understand why its necessary to cast to LayoutManager
in order to use the setLayout
method.
would it be necessary to implement the LayoutManager
interface for this to work correctly ?
public class FlowL extends JApplet{
public void init(){
// why is the cast necessary ?
// an error occurs when its setLayout(new FlowLayout());
setLayout((LayoutManager) new FlowLayout());
}
}
Upvotes: 0
Views: 431
Reputation: 209052
"and even though the error disapears i get an error..
java.lang.ClassCastException
:flowLayout.FlowLayout
cannot be cast tojava.awt.LayoutManager
"
There is no standard Java class flowLayout.FlowLayout
. That's your class (or possibly some third party class that doesn't extends LayoutManager, which I highly doubt).
You need to import
import java.awt.FlowLayout;
And get rid of your
import flowLayout.FlowLayout; // if you have that.
Upvotes: 2