内容发布更新时间 : 2024/12/23 17:10:43星期一 下面是文章的全部内容请认真阅读。
MenuItem miPaste=new MenuItem(\MenuShortcut(KeyEvent.VK_V)); MenuItem
miCut=new
MenuItem(\
MenuShortcut(KeyEvent.VK_T)); MenuItem
miFind=new
MenuItem(\
MenuShortcut(KeyEvent.VK_D)); MenuItem
miReplace=new
MenuItem(\
MenuShortcut(KeyEvent.VK_R));
MenuItem miAuto=new MenuItem(\自动换行\ miAuto.addActionListener(this); mn1.add(miSelectAll); mn1.add(miClear); mn1.add(miCopy); mn1.add(miPaste); mn1.add(miCut); mn1.addSeparator(); mn1.add(miFind); mn1.add(miReplace); mn1.add(miAuto);
miSelectAll.addActionListener(this); miClear.addActionListener(this); miCopy.addActionListener(this);
11
粘贴剪
切
查
找
替
换
\
\
\
\
miPaste.addActionListener(this); miCut.addActionListener(this); miFind.addActionListener(this); miReplace.addActionListener(this); Menu mn2=new Menu(\格式\ MenuItem
miFont=new
MenuItem(\
MenuShortcut(KeyEvent.VK_F)); MenuItem
miColor=new
MenuItem(\
颜
MenuShortcut(KeyEvent.VK_K)); MenuItem
miTime=new
MenuItem(\
插
MenuShortcut(KeyEvent.VK_T)); miFont.addActionListener(this); miColor.addActionListener(this); miTime.addActionListener(this); mn2.add(miFont); mn2.add(miColor); mn2.add(miTime);
Menu mn3=new Menu(\帮助\ MenuItem
miAbout=new
MenuItem(\
MenuShortcut(KeyEvent.VK_A)); miAbout.addActionListener(this); mn3.add(miAbout);
12
字
体
色
选
择
时
间
关
于
\
\
\
\
入
FileDialog findDlg = new FileDialog(this); Panel p5=new Panel(); Panel p6=new Panel();
Panel p7=new Panel(); p7.setLayout(new GridLayout(1,2,30,30)); p5.add(lFind);
p5.add(tFind);
p5.add(bFind);
tFind.addActionListener(this); bFind.addActionListener(this); p6.add(lReplace); p7.add(bReplaceAll); p6.add(p7);
tReplace.addActionListener(this);
bReplace.addActionListener(this);bReplaceAll.addActionListener(this); findD.setLayout(new GridLayout(2,1,10,10)); findD.setResizable(false); findD.add(p5); findD.add(p6);
findD.setBounds(100,100,260,190); //弹出PopupMenu popm=new PopupMenu();
MenuItem OpenFile=new MenuItem(\打开\ MenuItem SaveFile=new MenuItem(\保存\ MenuItem SelectAll=new MenuItem(\全选\ MenuItem Copy=new MenuItem(\复制\ MenuItem Paste=new MenuItem(\粘贴\
p6.add(tReplace);
p7.add(bReplace);
13
MenuItem Cut=new MenuItem(\剪切\ OpenFile.addActionListener(this); SaveFile.addActionListener(this); SelectAll.addActionListener(this); Copy.addActionListener(this); Paste.addActionListener(this); Cut.addActionListener(this); popm.add(OpenFile); popm.add(SaveFile); popm.add(SelectAll); popm.add(Copy); popm.add(Paste); popm.add(Cut); text.add(popm);
text.addMouseListener(new MyMouseEvent(this)); MenuBar Bar=new MenuBar(); Bar.add(mn); Bar.add(mn1); Bar.add(mn2); Bar.add(mn3); setMenuBar(Bar); setSize(800,600);
14
setVisible(true); }
class MyMouseEvent extends MouseAdapter {
MyTextPad myParentFrame; MyMouseEvent(MyTextPad myf) {
myParentFrame=myf;
}
public void mouseReleased(MouseEvent e) {
if(e.isPopupTrigger())
myParentFrame.popm.show((Component)e.getSource(),e.getX(),e.getY()); }
}
public void actionPerformed(ActionEvent e) {
String strCmd=e.getActionCommand(); if(strCmd.equals(\新建\
15