java做的简单记事本 下载本文

内容发布更新时间 : 2024/12/22 16:24:03星期一 下面是文章的全部内容请认真阅读。

public void windowClosing(WindowEvent e) {

dispose(); } } );

d=new Dialog(this,\字体选择\ d.setBounds(150,150,320,200);

findD.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {

findD.setVisible(false); } }

);

d.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {

d.setVisible(false); } }

);

c1=new Choice();c2=new Choice();c3=new Choice(); GraphicsEnvironment

ge=GraphicsEnvironment.getLocalGraphicsEnvironment();

String fontName[]=ge.getAvailableFontFamilyNames(); for(int i=0;i

c1.add(fontName[i]); }

c2.add(\粗体\ c2.add(\斜体\

c2.add(\粗体与斜体\ c2.add(\普通\

for(int i=8;i<100;i++) {

c3.add(\ }

Panel p1=new Panel(); Panel p2=new Panel(); p1.add(c1); p1.add(c2);

6

p1.add(c3);

btn1=new Button(\确定\ btn2=new Button(\取消\

d.setLayout(new GridLayout(5,3)); d.add(p1); p2.add(btn1);

btn1.addActionListener(this); btn2.addActionListener(this); p2.add(btn2); d.add(p2);

About=new Dialog(this,\关于\

About.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {

About.setVisible(false); } }

);

About.setBounds(300,300,150,150);

About.add(new Label(\蒋俊涛的计事体1.0版本\ Menu mn=new Menu(\文件\ MenuItem miNewFile=new MenuItem(\新MenuShortcut(KeyEvent.VK_N)); MenuItem miOpenFile=new MenuItem(\打MenuShortcut(KeyEvent.VK_O)); MenuItem miSaveFile=new MenuItem(\保MenuShortcut(KeyEvent.VK_S)); MenuItem miExit=new MenuItem(\退MenuShortcut(KeyEvent.VK_E)); mn.add(miNewFile); mn.add(miOpenFile); mn.add(miSaveFile); mn.addSeparator(); mn.add(miExit);

miNewFile.addActionListener(this); miOpenFile.addActionListener(this); miSaveFile.addActionListener(this); miExit.addActionListener(this); Menu mn1=new Menu(\编辑\ MenuItem miSelectAll=new MenuItem(\全MenuShortcut(KeyEvent.VK_P)); MenuItem miClear=new MenuItem(\清MenuShortcut(KeyEvent.VK_S));

7

建\开\存\\

选\\

出空 MenuItem miCopy=new MenuItem(\MenuShortcut(KeyEvent.VK_C)); 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); 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));

8

复制粘贴剪切查找替换字体色选择入时间关于\\\\\

\\\

\

miAbout.addActionListener(this); mn3.add(miAbout);

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); p6.add(tReplace); p7.add(bReplace); 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(\粘贴\ 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);

9

Bar.add(mn3); setMenuBar(Bar); setSize(800,600); 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(\新建\ {

text.setFont(new Font(Str1,Font.PLAIN,15)); text.setForeground(Color.black); text.setText(\ } try {

if(strCmd.equals(\打开\ {

openFile(); }

if(strCmd.equals(\保存\ {

saveFile(); }

}catch(IOException e1){} if(strCmd.equals(\退出\ {

System.exit(0);

10