I'm still pretty much a newbie.
I'm working with jdk 1.1.4.
I've written a java application which has a menu bar.
It works fine.
Now I'd like to turn it into an applet. I can't see
a way to add the menu bar. In my application version,
my main 'window' inherits from Frame, which has
the setMenuBar() function. Frame implements the
MenuContainer interface.
When I rewrote it as an applet, I derived from Applet which
does not implemente the MenuContainer interface, and has
no setMenuBar() function.
Do I need to implement the MenuContainer interface myself?
If so, how would I go about writing the functions it implements?
Font getFont() - I can figure this one out
boolean postEvent( Event evt ) - ???
void remove( MenuComponent comp ) - ???
Please reply to
mdavis at multipath dot com
as well as to this newsgroup, if you would be so kind, because
my news service loses half the postings before I can read them.
Many thanks,
Michael
--
// Michael Davis, Programmer/Analyst I don't speak for Multipath. //
// mda...@DELmultipath.com Nor do I speak against them. //
// Toronto The 'DEL' in my address is an anti-spam device. //
Good luck,
Michael Stenzler
public class myApplet extends Applet
{
private Frame myFrame;
public void init()
{
myFrame = new Frame("Title for myFrame");
this.add(myFrame);
// Add components of the applet to your frame
myFrame.add(new Button("Button1"));
..
}
}
Michael Davis wrote in message <6cuttg$ev5$1...@mpsrv3.multipath.com>...
Use Applet.setJMenuBar(JMenuBar)
Andreas
>
> You can't use the MenuBar class in the main panel of an Applet
> because it can only exist for a frame and Applets are extended from
> Panel. You might try creating a Frame to fill up the whole window
> and work with that. I havn't tried it, so don't know if it would
> work.
>
> Good luck,
>
> Michael Stenzler
>
> Michael Davis wrote:
> >
Thanks so much for your suggestion. Unfortunately I couldn't get it to work.
I tried the above code ( and I tried a similar thing with my app ) and both
times I got the same error. ( Here, I used the name 'tst' instead of 'myApplet' ):
java.lang.IllegalArgumentException: adding a window to a container
at java.awt.Container.addImpl(Container.java:285)
at java.awt.Container.add(Container.java:179)
at tst.init(tst.java:12)
at sun.applet.AppletPanel.run(AppletPanel.java:287)
at java.lang.Thread.run(Thread.java)
tst.java line 12 is: 'this.add(myFrame);'.
Now, interestingly enough, when I tried it with my app the first time, I left out
that line and instead had my frame class call showPanel(); which pops up my app
in a new window. This isn't what I want, I want it to be in the applet main window.
Is there something else I might try?
Cheers, MD
>Michael Davis wrote in message <6cuttg$ev5$1...@mpsrv3.multipath.com>...
>
>
> Thanks so much for your suggestion. Unfortunately I couldn't get it to work.
> I tried the above code ( and I tried a similar thing with my app ) and both
> times I got the same error. ( Here, I used the name 'tst' instead of 'myApplet' ):
>
> java.lang.IllegalArgumentException: adding a window to a container
> at java.awt.Container.addImpl(Container.java:285)
> at java.awt.Container.add(Container.java:179)
> at tst.init(tst.java:12)
> at sun.applet.AppletPanel.run(AppletPanel.java:287)
> at java.lang.Thread.run(Thread.java)
>
> tst.java line 12 is: 'this.add(myFrame);'.
>
Did you run the appletviewer for testing your applet? I had the same problem. But
running the applet in the Netscape Navigator should work. (For JDK1.1 you need
netscape4.04j2 from http://developer.netscape.com.)
Thomas