利用JAVA创建简单的菜单界面
来源:互联网 发布:网络销售好不好招人 编辑:程序博客网 时间:2024/04/28 08:21
package com.Gui.test3;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JFrame;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.JOptionPane;public class make extends JFrame{//JFrame f = new JFrame("This is a test");private JMenuBar bar;private JMenu mainMenu[];private JMenuItem item[];private String stmainMenu[] = {"文件", "编辑", "退出"};private String stitemName[] = {"新建", "打开", "关闭"};public static void main(String[] args) {make te = new make();te.GUID();}public make(){super("This is a test");}public void GUID(){bar = new JMenuBar();//设定主菜单mainMenu = new JMenu[stmainMenu.length];for(int i = 0; i < stmainMenu.length; i++){mainMenu[i] = new JMenu(stmainMenu[i]);}//加载主菜单栏for(int i = 0; i < stmainMenu.length; i++){bar.add(mainMenu[i]);}this.setJMenuBar(bar);//加载第一项的子菜单item = new JMenuItem[stitemName.length];for(int i = 0; i < stitemName.length; i++){item[i] = new JMenuItem(stitemName[i]);}mainMenu[0].add(item[0]);mainMenu[0].add(item[1]);mainMenu[0].add(item[2]);//加载监听器item[0].addActionListener( new ActionListener(){public void actionPerformed(ActionEvent event){JOptionPane.showMessageDialog(null, "文件");}});item[2].addActionListener(new ActionListener(){public void actionPerformed(ActionEvent Event){System.exit(1);}});mainMenu[1].addActionListener(new ActionListener(){public void actionPerformed(ActionEvent Event){System.exit(1);}});//显示界面;this.setSize(300, 300);this.setVisible(true);}}
以下是实例图片:
<img src="http://img.blog.csdn.net/20160801224711369?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
</pre><pre name="code" class="java">
0 0
- 利用JAVA创建简单的菜单界面
- cocos2dx3.2 创建界面菜单的简单使用
- 用 Java 创建带图像的菜单来美化界面
- 利用Java制作一个简单的QQ登录界面
- 同一界面挂多个菜单,利用权限控制菜单的显示
- 创建简单的下拉菜单
- 四,主要菜单界面的创建
- 编写一个简单的菜单操作界面
- 利用Qt实现简单的界面
- 利用uinavigattion实现简单的登陆界面
- 简单的利用数据库实现登录界面
- 使用PopupWindow创建一个简单的菜单
- 使用easyUI创建简单的菜单
- 使用jQuery创建简单的手风琴菜单
- 使用jQuery创建简单的手风琴菜单
- 用Qt创建一个简单的菜单
- 利用div+css生成简单的导航菜单,简单实用
- java最简单的知识之创建一个简单的windows窗口,利用Frame类
- Swift基础(三十)UISearchBar
- android之View坐标系(view获取自身坐标的方法和点击事件中坐标的获取)
- 最小二乘法的实现
- git学习 二(系统学习)
- hdu 5735 Born Slippy 折半枚举
- 利用JAVA创建简单的菜单界面
- ubuntu 16.04安装PHPSTORM
- eclipse发布到tomcat提示java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderLis
- Java中的位运算
- Web Service
- 基于DevExpress的Winform程序安装包的制作
- SpringMVC+Mybatis+Oracle实现web分页
- jstl中fmt:formatDate的输出格式详解
- inux查看磁盘读写性能(iostat命令)的方法