📄 j_menu.java.bak
字号:
// ////////////////////////////////////////////////////////
//
// J_Menu.java
//
// Created by Jun-Hai Yong, on XX xx, xxxx (Date)
// ////////////////////////////////////////////////////////
// Readme:
// Menu Example.
// ////////////////////////////////////////////////////////
// Using this example, please explicitly refer to the book:
// Jun-Hai Yong. Programming in Java.
// Beijing: Tsinghua University Press, 2004.
// 使用本例子,请注明引用:
// 雍俊海. Java 程序设计. 北京: 清华大学出版社, 2004.
// Please note that the author and publisher make no
// warranty of any kind on the examples provided.
// ////////////////////////////////////////////////////////
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class J_Menu extends JFrame
{
JMenuBar m_menuBar= new JMenuBar( );
public J_Menu( )
{
super("Menu Example");
JMenu [] m = { new JMenu("File"), new JMenu("Edit") };
char [] mC = { 'F', 'E' };
JMenuItem [] [] mI =
{
{new JMenuItem("Save"), new JMenuItem("Print")},
{new JMenuItem("Copy"), new JMenuItem("Read")}
};
char [] [] mIC = { {'S', 'P'}, {'C', 'R'}};
int i, j;
setJMenuBar(m_menuBar);
for (i= 0; i< m.length; i++)
{
m_menuBar.add(m[i]);
m[i].setMnemonic(mC[i]);
for (j= 0; j< mI[i].length; j++)
{
m[i].add(mI[i][j]);
mI[i][j].setMnemonic(mIC[i][j]);
mI[i][j].addActionListener( new ActionListener( )
{
public void actionPerformed(ActionEvent e)
{
JMenuItem mItem= (JMenuItem)e.getSource( );
System.out.println("Run Menu Item: " + mItem.getText( ));
} // End of method: actionPerformed
} // End of the anonymous inner class, which implements ActionListener
); // End of invoking addActionListener
} // End of inner loop: inner for
} // End of inner loop: outer for
setSize(250, 120);
setVisible(true);
} // End of constructor: J_Menu
public static void main( String args[] )
{
JFrame app = new J_Menu( );
Container cp = app.getContentPane( );
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
} // End of method: main
} // End of class: J_Menu
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -