Re: Converting from AWT to Swing - Compile Error

From: A. Bolmarcich (aggedor_at_earl-grey.cloud9.net)
Date: 03/21/04


Date: Sun, 21 Mar 2004 04:38:21 -0000

In article <YD77c.12735$TV6.10356@lakeread02>, Jason Dumler wrote:
> Hello All,
>
> I am converting an application from using AWT to swing. I have the
> following function inside a class:
> public void setParent(JComponent comp)
> {
> // What is our parent frame? Thanks to Paul Wheaton for posting the
> // example
> synchronized(comp.getTreeLock())
> {
> while((comp != null) && !(comp instanceof JFrame))
> comp = comp.getParent();
> }
> parentWindow = (JFrame) comp;
> }
>
> In converting, all I did was change Component to JComponent and Frame to
> JFrame, etc. However, this doesn't compile. Does anyone know why?
[snip]

Because an object of type JComonent can never be an instance of JFrame.
JFrame extends Frame which extents Window which extends Container which
extends Component which extends Object.

On the other hand, Frame is a subclass of Component. It is possible
for an object of type Component to be an instace of Frame.



Relevant Pages

  • Re: calling action function of the inner class in main function
    ... > I have created the two classes one extends from Applet, ... > extends from Frame. ... If you are converting an applet into a stand alone application, ...
    (microsoft.public.dotnet.vjsharp)
  • RE: how to instantiate the inner class.
    ... Instant VB: C# to VB.NET Converter ... > extends from Frame. ... The class which I inherited from the Frame class becomes ... > the inner class of the class extended from the Applet. ...
    (microsoft.public.dotnet.vjsharp)
  • Re: calling action function of the inner class in main function
    ... I have created the two classes one extends from Applet, ... The class which I inherited from the Frame class becomes ... call the functions of the class extended from Frame class - MenuBarFrame ...
    (microsoft.public.dotnet.vjsharp)
  • calling functions of the inner class- parameters of action functio
    ... I have created the two classes one extends from Applet, ... The class which I inherited from the Frame class becomes ... call the functions of the class extended from Frame class - MenuBarFrame ...
    (microsoft.public.dotnet.vjsharp)
  • how to instantiate the inner class.
    ... I have created the two classes one extends from Applet, ... The class which I inherited from the Frame class becomes ... public class MenuBarFrame extends Frame ...
    (microsoft.public.dotnet.vjsharp)