Java开发网 |
注册 |
登录 |
帮助 |
搜索 |
排行榜 |
发帖统计
|
您没有登录 |
» Java开发网 » Java GUI 设计
打印话题 寄给朋友 订阅主题 |
作者 | Re:[求助]菜单快键不能正确设置 [Re:Donnyzhao] |
Donnyzhao
发贴: 9 积分: 0 |
于 2004-10-07 23:24
import java.awt.*; import java.awt.event.*; public class MyApplet { public static void main(String args[]) { MyFrame frm=new MyFrame(); frm.setVisible(true); } } class MyFrame extends Frame implements ActionListener { //-------------Menu------------- MenuBar MyBar=new MenuBar(); Menu mn_File,mn_Edit,mn_Option,mn_View,mn_Help; //File MenuItem mn_File_New,mn_File_Open,mn_File_Save,mn_File_SaveAs; MenuItem mn_File_PageOption,mn_File_Print; MenuItem mn_File_Exit; //Edit MenuItem mn_Edit_Undo; MenuItem mn_Edit_Cut,mn_Edit_Copy,mn_Edit_Paste,mn_Edit_Delete; MenuItem mn_Edit_Find,mn_Edit_FindNext,mn_Edit_Change,mn_Edit_Goto; MenuItem mn_Edit_SelectAll,mn_Edit_DateTime; //Option CheckboxMenuItem mn_Option_Warp; MenuItem mn_Option_Font; //View MenuItem mn_View_StatusBar; //Help MenuItem mn_Help_Help,mn_Help_About; //-----------Popup--------------- PopupMenu MyPop=new PopupMenu(); MenuItem pp_Undo; MenuItem pp_Cut,pp_Copy,pp_Paste,pp_Delete; MenuItem pp_SelectAll; //-----------Face---------------- TextArea content=new TextArea(); MyFrame() { super("记事本"); mn_File=new Menu("文件"); mn_File_New=new MenuItem("新建",new MenuShortcut('n')); mn_File_Open=new MenuItem("打开...",new MenuShortcut('o')); mn_File_Save=new MenuItem("保存",new MenuShortcut('s')); mn_File_SaveAs=new MenuItem("另存为..."); mn_File_PageOption=new MenuItem("页面设置..."); mn_File_Print=new MenuItem("打印...",new MenuShortcut('p')); mn_File_Exit=new MenuItem("退出"); mn_Edit=new Menu("编辑"); mn_Edit_Undo=new MenuItem("取消",new MenuShortcut('z')); mn_Edit_Cut=new MenuItem("剪切",new MenuShortcut('x')); mn_Edit_Copy=new MenuItem("复制",new MenuShortcut('c')); mn_Edit_Paste=new MenuItem("粘贴",new MenuShortcut('v')); mn_Edit_Delete=new MenuItem("删除"); mn_Edit_Find=new MenuItem("查找...",new MenuShortcut('f')); mn_Edit_FindNext=new MenuItem("查找下一个"); mn_Edit_Change=new MenuItem("替换...",new MenuShortcut('h')); mn_Edit_Goto=new MenuItem("转到",new MenuShortcut('g')); mn_Edit_SelectAll=new MenuItem("全选",new MenuShortcut('a')); mn_Edit_DateTime=new MenuItem("日期/时间"); mn_Option=new Menu("格式"); mn_Option_Warp=new CheckboxMenuItem("自动换行"); mn_Option_Font=new MenuItem("字体..."); mn_View=new Menu("查看"); mn_View_StatusBar=new MenuItem("状态栏"); mn_Help=new Menu("帮助"); mn_Help_Help=new MenuItem("帮助主题"); mn_Help_About=new MenuItem("关于记事本"); mn_File_New.addActionListener(this); mn_File_Open.addActionListener(this); mn_File_Save.addActionListener(this); mn_File_SaveAs.addActionListener(this); mn_File_PageOption.addActionListener(this); mn_File_Print.addActionListener(this); mn_File_Exit.addActionListener(this); mn_Edit_Undo.addActionListener(this); mn_Edit_Cut.addActionListener(this); mn_Edit_Copy.addActionListener(this); mn_Edit_Paste.addActionListener(this); mn_Edit_Delete.addActionListener(this); mn_Edit_Find.addActionListener(this); mn_Edit_FindNext.addActionListener(this); mn_Edit_Change.addActionListener(this); mn_Edit_Goto.addActionListener(this); mn_Edit_SelectAll.addActionListener(this); mn_Edit_DateTime.addActionListener(this); mn_Option_Warp.addActionListener(this); mn_Option_Font.addActionListener(this); mn_View_StatusBar.addActionListener(this); mn_Help_Help.addActionListener(this); mn_Help_About.addActionListener(this); MyBar.add(mn_File); MyBar.add(mn_Edit); MyBar.add(mn_Option); MyBar.add(mn_View); MyBar.add(mn_Help); mn_File.add(mn_File_New); mn_File.add(mn_File_Open); mn_File.add(mn_File_Save); mn_File.add(mn_File_SaveAs); mn_File.addSeparator(); mn_File.add(mn_File_PageOption); mn_File.add(mn_File_Print); mn_File.addSeparator(); mn_File.add(mn_File_Exit); mn_Edit.add(mn_Edit_Undo); mn_Edit.addSeparator(); mn_Edit.add(mn_Edit_Cut); mn_Edit.add(mn_Edit_Copy); mn_Edit.add(mn_Edit_Paste); mn_Edit.add(mn_Edit_Delete); mn_Edit.addSeparator(); mn_Edit.add(mn_Edit_Find); mn_Edit.add(mn_Edit_FindNext); mn_Edit.add(mn_Edit_Change); mn_Edit.add(mn_Edit_Goto); mn_Edit.addSeparator(); mn_Edit.add(mn_Edit_SelectAll); mn_Edit.add(mn_Edit_DateTime); mn_Option.add(mn_Option_Warp); mn_Option.add(mn_Option_Font); mn_View.add(mn_View_StatusBar); mn_Help.add(mn_Help_Help); mn_Help.addSeparator(); mn_Help.add(mn_Help_About); //----------Popup------------ pp_Undo=new MenuItem("取消"); pp_Cut=new MenuItem("剪切"); pp_Copy=new MenuItem("复制"); pp_Paste=new MenuItem("粘贴"); pp_Delete=new MenuItem("删除"); pp_SelectAll=new MenuItem("全选"); MyPop.add(pp_Undo); MyPop.addSeparator(); MyPop.add(pp_Cut); MyPop.add(pp_Copy); MyPop.add(pp_Paste); MyPop.add(pp_Delete); MyPop.addSeparator(); MyPop.add(pp_SelectAll); pp_Undo.addActionListener(this); pp_Cut.addActionListener(this); pp_Copy.addActionListener(this); pp_Paste.addActionListener(this); pp_Delete.addActionListener(this); pp_SelectAll.addActionListener(this); //==========Popup============ //----------Face------------- content.addMouseListener(new MouseCatch(this)); content.add(MyPop); setLayout(new BorderLayout()); add("Center",content); //==========Face============= setMenuBar(MyBar); setSize(500,200); addWindowListener(new WindowAdpt()); } public void actionPerformed(ActionEvent e) { if(e.getActionCommand()=="退出") { dispose(); System.exit(0); } } } class WindowAdpt extends WindowAdapter { public void windowClosing(WindowEvent e) { Frame frm=(Frame)(e.getSource()); frm.dispose(); System.exit(0); } } class MouseCatch extends MouseAdapter { MyFrame MyParent; MouseCatch(MyFrame t) { MyParent=t; } public void mouseReleased(MouseEvent e) { if(e.isPopupTrigger()) MyParent.MyPop.show(e.getComponent(),e.getX(),e.getY()); } } 有了Swing为什么还要SWT? |
话题树型展开 |
人气 | 标题 | 作者 | 字数 | 发贴时间 |
3080 | [求助]菜单快键不能正确设置 | Donnyzhao | 116 | 2004-10-07 12:32 |
2632 | Re:[求助]菜单快键不能正确设置 | Donnyzhao | 6019 | 2004-10-07 23:24 |
已读帖子 新的帖子 被删除的帖子 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |