java向窗口添加菜单_Java基础之创建窗口——向窗口中添加菜单(Sketcher)

控制台程序。

JMenuBar对象表示放在窗口顶部的菜单栏。可以为JMenuBar对象添加JMenu或JMenuItem对象,它们都显示在菜单栏上。JMenu对象是带有标签的菜单,单击就可以显示一列菜单项。JMenuItem对象表示菜单中带有标签的菜单项,单击就会执行某个程序动作。

// Main window for the Sketcher application

import javax.swing.*;

import static java.awt.event.InputEvent.*; // For modifier constants

@SuppressWarnings("serial")

public class SketcherFrame extends JFrame {

// Constructor

public SketcherFrame(String title) {

setTitle(title); // Set the window title

setDefaultCloseOperation(EXIT_ON_CLOSE);

setJMenuBar(menuBar); // Add the menu bar to the window

JMenu fileMenu = new JMenu("File"); // Create File menu

JMenu elementMenu = new JMenu("Elements"); // Create Elements menu

fileMenu.setMnemonic('F'); // Create shortcut

elementMenu.setMnemonic('E'); //

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值