当前位置:编程学习 > JAVA >>

Java JMenu_2

package com.han; 
 
import java.awt.Dimension; 
import java.awt.Rectangle; 
import java.awt.event.ActionEvent; 
import java.awt.event.ActionListener; 
import java.awt.event.InputEvent; 
import java.awt.event.KeyEvent; 
import java.awt.image.BufferedImage; 
import java.io.IOException; 
import java.net.URL; 
 
import javax.imageio.ImageIO; 
import javax.swing.ButtonGroup; 
import javax.swing.ImageIcon; 
import javax.swing.JCheckBoxMenuItem; 
import javax.swing.JFrame; 
import javax.swing.JMenu; 
import javax.swing.JMenuBar; 
import javax.swing.JMenuItem; 
import javax.swing.JRadioButtonMenuItem; 
import javax.swing.KeyStroke; 
 
public class JMenu_2 extends JFrame { 
 
    /**
     * 
     */ 
    private static final long serialVersionUID = 1395124747782445698L; 
 
    static Dimension dimension; 
 
    public JMenu_2() { 
        super(); 
        // TODO Auto-generated constructor stub  
        JMenuBar menuBar = new JMenuBar(); 
        setJMenuBar(menuBar); 
 
        JMenu fileMenu = new JMenu("文件(F)"); 
        fileMenu.setMnemonic('F'); 
        menuBar.add(fileMenu); 
 
        JMenuItem newItem = new JMenuItem("新建(N)"); 
        newItem.setMnemonic('N'); 
        newItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, 
                InputEvent.CTRL_MASK)); 
        fileMenu.add(newItem); 
        newItem.addActionListener(new newItemListener()); 
 
        JMenu openMenu = new JMenu("打开(O)"); 
        JMenuItem openMenuItem = new JMenuItem("未打开过的(N)"); 
        JMenuItem openMenuItem2 = new JMenuItem("刚打开过的(C)"); 
        fileMenu.add(openMenu); 
        openMenu.add(openMenuItem); 
        openMenu.add(openMenuItem2); 
        openMenu.setMnemonic('O'); 
        openMenuItem.setMnemonic('N'); 
        openMenuItem2.setMnemonic('C'); 
        openMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, 
                InputEvent.CTRL_MASK | InputEvent.ALT_MASK)); 
        openMenuItem2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, 
                InputEvent.CTRL_MASK | InputEvent.ALT_MASK)); 
        openMenuItem.addActionListener(new openMenuItemListener()); 
        openMenuItem2.addActionListener(new openMenuItem2Listener()); 
        fileMenu.addSeparator(); 
        openMenuItem2.setEnabled(false); 
 
        JMenuItem saveMenuItem = new JMenuItem("保存(S)"); 
        saveMenuItem.setMnemonic('S'); 
        saveMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, 
                InputEvent.CTRL_MASK)); 
        fileMenu.add(saveMenuItem); 
        saveMenuItem.addActionListener(new saveMenuItemListener()); 
        fileMenu.addSeparator(); 
 
        JMenuItem exitMenuItem = new JMenuItem("退出(E)"); 
        exitMenuItem.setMnemonic('E'); 
        exitMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, 
                InputEvent.CTRL_MASK)); 
        fileMenu.add(exitMenuItem); 
        exitMenuItem.addActionListener(new exitMenuItemListener()); 
 
        JMenu editMenu = new JMenu("编辑(E)"); 
        editMenu.setMnemonic('E'); 
        menuBar.add(editMenu); 
 
        JMenuItem cutMenuItem = new JMenuItem("剪切(T)"); 
        cutMenuItem.setMnemonic('T'); 
        cutMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, 
                InputEvent.CTRL_MASK)); 
        editMenu.add(cutMenuItem); 
        cutMenuItem.addActionListener(new cutMenuItemListener()); 
 
        JMenuItem copyMenuItem = new JMenuItem("复制(C)"); 
        copyMenuItem.setMnemonic('C'); 
        copyMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, 
                InputEvent.CTRL_MASK)); 
        editMenu.add(copyMenuItem); 
        copyMenuItem.addActionListener(new copyMenuItemListener()); 
        URL resource = this.getClass().getResource("/images/Luxun.jpg"); 
        BufferedImage imageScaled = null; 
        BufferedImage in; 
        try { 
            in = ImageIO.read(resource); 
            imageScaled = ImageScale.scale(in,

补充:软件开发 , Java ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,