I just spent an hour actraully trying to figure this out maybe I am
doing it wrong but it works.

importPackage(java.awt);

function JMColor(r,g,b) {
    // the same as calling super()
    var color = JavaAdapter(Color(r,g,b));
    // Do your contstructor stuff here

    // return the object
    return color;
}
var col = new JMColor(0.75,0.5,0.5);
print(col);
//java.awt.Color[r=191,g=128,b=128]


On Mar 3, 11:32 pm, Joseph Montanez <[email protected]> wrote:
> If your using the adapter with an empty javascript object then thats a
> no no.
>
> Just use:
> new JavaAdapter(javax.swing.OverlayLayout);
>
> On Mar 3, 9:53 pm, Cameron McCormack <[email protected]> wrote:
>
>
>
> > [Reposted from m.d.t.js-engine where I mistakenly posted it first.]
>
> > Hi.
>
> > I want to, from script, extend a Java class that has no default
> > constructor.  Specifically, I want to extend javax.swing.OverlayLayout
> > so that I can override some of its methods.  I tried:
>
> >   Rhino 1.7 release 3 PRERELEASE 2009 03 04
> >   js> new JavaAdapter(javax.swing.OverlayLayout, { })
> >   Exception in thread "main" java.lang.NoSuchMethodError:
> >   javax.swing.OverlayLayout: method <init>()V not found
> >           at adapter1.<init>(<adapter>)
> >           ...
>
> > so obviously I need a way to provide a constructor in my class so that I
> > can call super and provide an argument.  Is there a way I can do this,
> > or will I have to extend OverlayLayout from Java?
>
> > Also, having the NoSuchMethodError quit the shell doesn't look good.
> > Maybe there can be a 'catch (NoSuchMethodError e)' at
> > src/org/mozilla/javascript/JavaAdapter.java:216 that throws some kind of
> > Exception.
>
> > Thanks,
>
> > Cameron
>
> > [PS: Actually, after I misposted this originally in m.d.t.js-engine, I
> > realised that I don't actually want to extend OverlayLayout; I need to
> > call setAlignmentX() on the components in the container.  But extending
> > a class with no default constructor is something I've wanted to do
> > before, so the question still remains.]
>
> > --
> > Cameron McCormack ≝http://mcc.id.au/

_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to