菜单不显示
import javax.swing.JFrame;import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JTextArea;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
class Break1 extends JFrame{
JPopupMenu mnuShortcut = new JPopupMenu();
JTextArea txa = new JTextArea();
public Break1(){
setDefaultCloseOperation( EXIT_ON_CLOSE );
jbInit();
}
private void jbInit(){
setTitle( "无标题 - 笔事本" );
JFrameSize fs = new JFrameSize( this, 50, true );
JMenuBar mnuBar = new JMenuBar();
JMenu mnuFile = new JMenu( "文件(F)" );
JMenu mnuEdit = new JMenu( "编辑(E)" );
JMenu mnuFormat = new JMenu( "格式(O)" );
JMenu mnuLookVoer = new JMenu( "查看(V)" );
JMenu mnuHelp = new JMenu( "帮助(H)" );
JMenuItem mnuNew = new JMenuItem( "新建(N)", 'N' );
JMenuItem mnuOpen = new JMenuItem( "打开(O)...", 'O' );
JMenuItem mnuSave = new JMenuItem( "保存(S)", 'S' );
JMenuItem mnuSaveAs = new JMenuItem( "另存为(A)...", 'A' );
JMenuItem mnuSetPage = new JMenuItem( "页面设置(U)...", 'U' );
JMenuItem mnuPrint = new JMenuItem( "打印(P)", 'P' );
JMenuItem mnuExit = new JMenuItem( "退出(X)", 'X' );
JMenuItem mnuUndo = new JMenuItem( "撤销(U)", 'U' );
JMenuItem mnuCut = new JMenuItem( "剪贴(T)", 'T' );
JMenuItem mnuCopy = new JMenuItem( "复制(C)", 'C' );
JMenuItem mnuPaste = new JMenuItem( "粘贴(P)", 'P' );
JMenuItem mnuDelete = new JMenuItem( "删除(L)", 'L' );
JMenuItem mnuSearch = new JMenuItem( "查找(F)...", 'F' );
JMenuItem mnuSearchNext = new JMenuItem( "查找下一个(N)", 'N' );
JMenuItem mnuTemp = new JMenuItem( "替换(R)...", 'R' );
JMenuItem mnuGo = new JMenuItem( "转到(G)...", 'G' );
JMenuItem mnuAllSelect = new JMenuItem( "全选(A)", 'A' );
JMenuItem mnuDate = new JMenuItem( "时间/日期(D)", 'D' );
JCheckBoxMenuItem mnuEnter = new JCheckBoxMenuItem( "自动换行(W)", false );
JMenuItem mnuFont = new JMenuItem( "字体(F)...", 'F' );
JCheckBoxMenuItem mnuState = new JCheckBoxMenuItem( "状态栏(S)", false );
JMenuItem mnuHelpTitle = new JMenuItem( "帮助主题(H)", 'H' );
JMenuItem mnuAboutAs = new JMenuItem( "关于笔记本(A)", 'A' );
JCheckBoxMenuItem mnuRightLift = new JCheckBoxMenuItem( "从右到左的阅读顺序(R)" );
JCheckBoxMenuItem mnuShowUnicode = new JCheckBoxMenuItem( "显示Unicode控制字符(S)" );
JMenu mnuInsertUnicode = new JMenu( "插入Unicode控制字符(I)" );
txa.setBounds( 0, 0, getWidth(), getHeight() );
getContentPane().add( txa );
mnuUndo.setEnabled( false );
mnuCut.setEnabled( false );
mnuCopy.setEnabled( false );
mnuPaste.setEnabled( false );
mnuDelete.setEnabled( false );
mnuSearch.setEnabled( false );
mnuSearchNext.setEnabled( false );
mnuGo.setEnabled( false );
mnuState.setEnabled( false );
mnuFile.add( mnuNew );
mnuFile.add( mnuOpen );
mnuFile.add( mnuSave );
mnuFile.add( mnuSaveAs );
mnuFile.addSeparator();
mnuFile.add( mnuSetPage );
mnuFile.add( mnuPrint );
mnuFile.addSeparator();
mnuFile.add( mnuExit );
mnuBar.add( mnuFile );
mnuEdit.add( mnuUndo );
mnuEdit.addSeparator();
mnuEdit.add( mnuCut );
mnuEdit.add( mnuCopy );
mnuEdit.add( mnuPaste );
mnuEdit.add( mnuDelete );
mnuEdit.addSeparator();
mnuEdit.add( mnuSearch );
mnuEdit.add( mnuSearchNext );
mnuEdit.add( mnuTemp );
mnuEdit.add( mnuGo );
mnuEdit.addSeparator();
mnuEdit.add( mnuAllSelect );
mnuEdit.add( mnuDate );
mnuBar.add( mnuEdit );
mnuFormat.add( mnuEnter );
mnuFormat.add( mnuFont );
mnuBar.add( mnuFormat );
mnuLookVoer.add( mnuState );
mnuBar.add( mnuLookVoer );
mnuHelp.add( mnuHelpTitle );
mnuHelp.addSeparator();
mnuHelp.add( mnuAboutAs );
mnuBar.add( mnuHelp );
this.setJMenuBar( mnuBar );
mnuShortcut.add( mnuUndo );
mnuShortcut.addSeparator();
mnuShortcut.add( mnuCut );
mnuShortcut.add( mnuCopy );
mnuShortcut.add( mnuPaste );
mnuShortcut.add( mnuDelete );
mnuShortcut.addSeparator();
mnuShortcut.add( mnuRightLift );
mnuShortcut.add( mnuShowUnicode );
mnuShortcut.add( mnuInsertUnicode );
txa.addMouseListener( new Mouse_mnuShortcut( this ) );
setVisible( true );
}
public void show_mnuShortcut( MouseEvent e ){
if( e.isMetaDown() ){
mnuShortcut.show( this.txa , e.getX(), e.getY() );
}
}
public static void main( String[] args ){
Break1 break1 = new Break1();
}
}
class Mouse_mnuShortcut implements MouseListener{
Break1 frame;
public Mouse_mnuShortcut( Break1 f ){
frame = f;
}
public void mouseClicked(MouseEvent e){
}
public void mousePressed(MouseEvent e){
}
public void mouseReleased(MouseEvent e){
frame.show_mnuShortcut( e );
}
public void mouseEntered(MouseEvent e){
}
public void mouseExited(MouseEvent e){
}
}
菜单栏第二个子菜单前几个菜单项无法显示