FrameDemo6
package cn.itcast;
/*
* 一级菜单
*/
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
/*
* 一级菜单
*/
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class FrameDemo6 {
public static void main(String[] args) {
// 创建窗体对象并设置属性
Frame f = new Frame("一级菜单");
f.setBounds(400, 200, 400, 300);
f.setLayout(new FlowLayout());
// 创建菜单栏
MenuBar mb = new MenuBar();
// 创建菜单
Menu m = new Menu("File");
// 创建菜单项
MenuItem mi = new MenuItem("退出系统");
//添加菜单组件
m.add(mi);
mb.add(m);
//设置菜单栏
f.setMenuBar(mb);
// 设置窗体关闭
f.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// TODO Auto-generated method stub
super.windowClosing(e);
System.exit(0);
}
});
public static void main(String[] args) {
// 创建窗体对象并设置属性
Frame f = new Frame("一级菜单");
f.setBounds(400, 200, 400, 300);
f.setLayout(new FlowLayout());
// 创建菜单栏
MenuBar mb = new MenuBar();
// 创建菜单
Menu m = new Menu("File");
// 创建菜单项
MenuItem mi = new MenuItem("退出系统");
//添加菜单组件
m.add(mi);
mb.add(m);
//设置菜单栏
f.setMenuBar(mb);
// 设置窗体关闭
f.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// TODO Auto-generated method stub
super.windowClosing(e);
System.exit(0);
}
});
mi.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
System.exit(0);
}
});
// 设置窗体可见
f.setVisible(true);
}
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
System.exit(0);
}
});
// 设置窗体可见
f.setVisible(true);
}
}