1、Inter Celeron 1G;JDK版本:1.5;五、进度计划及执行情况日期任务安排执行情况2008-1-7了解计事本的基本功能,并实现基本的框架基本框架搭建好了功能实现方法进行了整个窗口的布局调试结果最后程序能正常运行错误原因分析遇到的问题是:在开始时,文本域控件JText没有滚动条改正情况经过查API函数。在JScrollPane中添加文本域控件。在将JScollPane解决了问题。2007-1-8实现文件的打开和保存功能对文件进行正确的读写文件的打开和保存功能对文件可以进行正确的读写。刚开始进行文件读写操作时,用的是字节流,读出来的都是乱码。数据的流使用错了。使用了字符流解决了问题2
2、008-1-9实现字体风格和小的设置可以对字体进行正确设置字体名是调用系统的,字号用的是8-99号字,颜色调用java的颜色面板可以对字体的字体,字号,还有字体颜色进行相关设置,新建文件后,原来的字体颜色还保留着在新建时没有进行颜色的设置在新建后可以解决该问题2008-1-10实现查找和替换功能可以正确进行查找和替换应用的是String常用的几个方法可以进行查找和替换还有点功能上的欠缺查找到到最后一个时。不能返回重新查找有待改进2008-1-11实现字体风格的保存,保证打开后,能保持原来的风格。功能已经实现将字体风格保存到另一个文件中,打开文本时,也同时读取该文件,重新进行字体的设置。遇到过的
3、一次错误是,颜色不能正常显示,改进过,后来程序可以实现文本打开后字体维持原状。错误的使用颜色的函数已经没有问题,可以正常显示颜色。六、程序清单import java.awt.*;import java.awt.event.*;import java.io.*;import java.awt.GraphicsEnvironment;import javax.swing.*;import java.util.*;import java.awt.Graphics;class MyTextPad extends Frame implements ActionListener JTextArea tex
4、t; JScrollPane jsp; PopupMenu popm; Date date=new Date(); String str=; Dialog d,About; Choice c1,c2,c3; Button btn1,btn2; String Str1=宋体,Str2=普通,Str3=15 int temp=0; int Red=0,Green=0,Blue=0; Label lFind = new Label(查找字符串:); Label lReplace = new Label(替换字符串: TextField tFind = new TextField(10); TextF
5、ield tReplace = new TextField(10); Button bFind = new Button(查找 Button bReplace = new Button(替换 Button bReplaceAll=new Button(替换所有 Dialog dialog; Dialog findD; public MyTextPad(String str) super(str); text=new JTextArea(); text.setFont(new Font(,0,15); jsp=new JScrollPane(text); add(Center,jsp); fin
6、dD=new Dialog(this); addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) dispose(); ); d=new Dialog(this,字体选择 d.setBounds(150,150,320,200); findD.addWindowListener(new WindowAdapter() findD.setVisible(false); d.addWindowListener(new WindowAdapter() d.setVisible(false); c1=
7、new Choice();c2=new Choice();c3=new Choice(); GraphicsEnvironment ge=GraphicsEnvironment.getLocalGraphicsEnvironment(); String fontName=ge.getAvailableFontFamilyNames(); for(int i=0;ifontName.length;i+) c1.add(fontNamei); c2.add(粗体斜体粗体与斜体 for(int i=8;100; c3.add(+i); Panel p1=new Panel(); Panel p2=n
8、ew Panel(); p1.add(c1); p1.add(c2); 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() Ab
9、out.setVisible(false); About.setBounds(300,300,150,150); About.add(new Label(蒋俊涛的计事体1.0版本); Menu mn=new Menu(文件 MenuItem miNewFile=new MenuItem(新建,new MenuShortcut(KeyEvent.VK_N); MenuItem miOpenFile=new MenuItem(打开,new MenuShortcut(KeyEvent.VK_O); MenuItem miSaveFile=new MenuItem(保存,new MenuShortcu
10、t(KeyEvent.VK_S); MenuItem miExit=new MenuItem(退出,new 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.addAction
11、Listener(this); Menu mn1=new Menu(编辑 MenuItem miSelectAll=new MenuItem(全选,new MenuShortcut(KeyEvent.VK_P); MenuItem miClear=new MenuItem(清空 MenuItem miCopy=new MenuItem(复制,new MenuShortcut(KeyEvent.VK_C); MenuItem miPaste=new MenuItem(粘贴,new MenuShortcut(KeyEvent.VK_V); MenuItem miCut=new MenuItem(剪
12、切,new MenuShortcut(KeyEvent.VK_T); MenuItem miFind=new MenuItem(,new MenuShortcut(KeyEvent.VK_D); MenuItem miReplace=new MenuItem(,new MenuShortcut(KeyEvent.VK_R); MenuItem miAuto=new MenuItem(自动换行 miAuto.addActionListener(this); mn1.add(miSelectAll); mn1.add(miClear); mn1.add(miCopy); mn1.add(miPas
13、te); 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); miRepla
14、ce.addActionListener(this); Menu mn2=new Menu(格式 MenuItem miFont=new MenuItem(字体,new MenuShortcut(KeyEvent.VK_F); MenuItem miColor=new MenuItem(颜色选择,new MenuShortcut(KeyEvent.VK_K); MenuItem miTime=new MenuItem(插入时间 miFont.addActionListener(this); miColor.addActionListener(this); miTime.addActionLis
15、tener(this); mn2.add(miFont); mn2.add(miColor); mn2.add(miTime); Menu mn3=new Menu(帮助 MenuItem miAbout=new MenuItem(,new MenuShortcut(KeyEvent.VK_A); miAbout.addActionListener(this); mn3.add(miAbout); FileDialog findDlg = new FileDialog(this); Panel p5=new Panel(); Panel p6=new Panel(); Panel p7=new
16、 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.addActionList
17、ener(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=
18、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(
19、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); setVisible(true); cla
20、ss 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.get
21、ActionCommand(); if(strCmd.equals() text.setFont(new Font(Str1,Font.PLAIN,15); text.setForeground(Color.black); text.setText( try openFile(); saveFile(); catch(IOException e1) System.exit(0); text.selectAll(); if(strCmd.equals( text.setText( str=text.getSelectedText(); text.insert(str,text.getCaretP
22、osition(); text.replaceRange(,text.getSelectionStart(),text.getSelectionEnd(); d.setVisible(true); Color c=JColorChooser.showDialog(this,Color.black); text.setForeground(c); Red=c.getRed(); Green=c.getGreen(); Blue=c.getBlue(); if(e.getSource()=tFind|e.getSource()=bFind) find(); return; if(e.getSour
23、ce()=tReplace|e.getSource()=bReplace) text.requestFocus(); String s1=tReplace.getText(); if (text.getSelectedText().equals(tFind.getText() int start=text.getSelectionStart(); text.replaceRange(s1, text.getSelectionStart(), text.getSelectionEnd(); text.select(start,start+s1.length(); else if(e.getSou
24、rce()=bReplaceAll) str = text.getText(); String strFind = tFind.getText(); int start = 0; int end = str.length(); int len = strFind.length(); int count=0; if (start=end-len) for (;start = end - len; start+) if (str.substring(start, start + len).equals(strFind) count+; text.replaceRange(s1, start,start + len); if
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2