如何设置我的applet的标题?

时间:2015-10-01 18:56:26

标签: java menu applet initialization

我如何安排此appletform? 我试图在我的小程序中添加menuitems但没有运气! 如果单击关闭menuitem,如何关闭窗口? 我试过dispose();但它也没有用!

public class AppletForm extends Applet implements
    DragGestureListener, // For recognizing the start of drags
    DragSourceListener, // For processing drag source events
    DropTargetListener, // For processing drop target events
    MouseListener, // For processing mouse clicks
    MouseMotionListener // For processing mouse drags
{
    private MenuBar menuBar = new MenuBar(); // first, create a MenuBar item
    private Menu file = new Menu(); // our File menu
    // what's going in File? let's see...
    private MenuItem openFile = new MenuItem();  // an open option
    private MenuItem saveFile = new MenuItem(); // a save option
    private MenuItem close = new MenuItem(); // and a close option!

    StringBuffer strBuffer;

    public void init() {
        setSize(500, 300);
    addMouseListener(this);
    strBuffer = new StringBuffer();
        addItem("initializing the apple ");

    }
}

1 个答案:

答案 0 :(得分:0)

  

如何设置applet的标题?

类似的东西:

<head> <title>The Applet Title</title> </head>

  

我正在尝试在我的applet中添加menuitems而没有运气!

试一试:

MenuBar mbar = new MenuBar();
Menu m = new Menu("File");
m.add(new MenuItem("New"));
m.add(new MenuItem("Open"));
m.addSeparator();
m.add(new MenuItem("Save"));
m.add(new MenuItem("Save As"));
m.addSeparator();
m.add(new MenuItem("Print"));
m.addSeparator();
m.add(new MenuItem("Quit"));
mbar.add(m);

Menu m = new Menu("Edit");
m.add(new MenuItem("Undo"));
m.add(new MenuItem("Redo"));
m.addSeparator();
m.add(new MenuItem("Cut"));
m.add(new MenuItem("Copy"));
m.add(new MenuItem("Delete"));
m.add(new MenuItem("Paste"));
m.addSeparator();

Menu f = new Menu("Options");
f.add(new CheckboxMenuItem("Insert"));
f.add(new CheckboxMenuItem("Auto indent"));
m.add(f);
mbar.add(m);

Menu m = new Menu("Help");
m.add(new MenuItem("Index"));
m.add(new MenuItem("About"));
mbar.add(m);

setMenuBar(mbar);
  

如果单击关闭menuitem,如何关闭窗口?

试一试:

public void exit() {     
    setVisible(false);
    dispose();
    System.exit(0);
}