Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Menu bar on Applet

Status
Not open for further replies.

mickjbud

Programmer
Jun 13, 2002
48
GB
Hi all

I am trying to write a web applet with a menu bar on but unfortunately I am having trouble understanding how you go about this. Can you only add a menu bar to a frame?

Any help is most welcome.

Mick
 
Thanks prosper for the link but I forgot to mention I need to do this without using swing. I have managed to write the menuBar into the frame but when I run the prog using AppletViewer I get two windows opened, one is the applet the other is the frame. Is there any way to add a menu bar without using frame or swing to an applet. The applet needs to be attached to the web page and not floating.

Thanks
Mick
 
I find right click popup menu in applet, here is the code
Code:
    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;

    public class PopupMenuTest extends Applet implements ActionListener {

	PopupMenu popup;

	public void init() {	    
            MenuItem mi;

	    popup = new PopupMenu("Edit");

            mi = new MenuItem("Cut");
            mi.addActionListener(this);
	    popup.add(mi);

            mi = new MenuItem("Copy");
            mi.addActionListener(this);
	    popup.add(mi);

	    popup.addSeparator();

            mi = new MenuItem("Paste");
            mi.addActionListener(this);
	    popup.add(mi);

	    add(popup); // add popup menu to applet
           
            enableEvents(AWTEvent.MOUSE_EVENT_MASK); 

	    resize(200, 200);
        }

	public void processMouseEvent(MouseEvent e) {

	    if (e.isPopupTrigger()) { 
	        popup.show(e.getComponent(), e.getX(), e.getY());
	    }
	    super.processMouseEvent(e);
        }

        public void actionPerformed(ActionEvent e) {
	    String command = e.getActionCommand();

            if (command.equals("Cut")) {
	        // perform cut operation
            } else if (command.equals("Copy")) {
                // perform copy operation
            } else if (command.equals("Paste")) {
                // perform paste operation
            }
        }
    }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top