文本编辑器源代码
VB课程设计-文本编辑器

VB课程设计报告——文本编辑器学院名称:学生姓名:专业名称:班级:一、课程设计题目用Visual Basic程序设计语言编写一个简易的文本编辑器要求:有最基本的文本编辑功能,包括复制、剪切、粘贴、字体设置、背景颜色设置、字体颜色设置;同时拥有文本管理功能,包括打开文件、保存文件;以及完整的系统运行退出等功能,所有的操作可选择设定的快捷键。
二、课程设计目的虽然本学期的Visual Basic课程是自学的,相对于课堂学习有些不足,但通过平时的上机实验,初步掌握了VB程序设计的各种方法,学会了编写最基本的VB程序;对于完整的VB程序设计来讲是很不足的,平时掌握的只是单独的窗体(Form)程序编写,以及各种简单控件的使用,没有做到很好连贯性,所以有必要做一次完整的VB程序设计,结合所学的基本知识,使用多个窗体自成一套系统,加上各种控件的综合运用,初步设计一个合格的VB 应用程序;这样在巩固VB所学的同时,更好地学会程序设计的一些思想和方法,对于以后的编程学习或是工作有重要的实践意义。
三、课程设计说明题目为文本编辑器,即是最基本的文本编辑程序,首先必须做好文本编辑器本身的功能,然后对其完善,做成一个完整的小程序功能设计说明:功能是这个文本编辑器的核心内容,也就是程序的作用,它是用来做什么的;本程序就是用来编写文本的,编写过程中要利用到窗体(Form)一个,控件包括:RichTextBox1(超文本框)、CommonDialog(通用对话框),以及InputBox(消息框)、菜单编辑器等,。
要做的工作就是编写代码把这些控件和窗体等结合为一体,使得程序能够成为一体,顺畅运行。
本次设计在按照题目要求的前提下,为了完整地展示一个应用程序,在最初就设计为最基本的文本的编辑器,所以取名为“易记本”,就是简易记事本的简称,然后加入图标,在程序完成之后还进行了大包操作,得到应用程序的安装文件,最后安装在电脑上运行使用。
四.源代码Private Sub Command1_Click()Dim i As IntegerIf Text2.Text <> "123456" Theni = MsgBox("密码错误", 5 + vbExclamation, "警告")If i <> 6 ThenEndElseText2.Text = ""Text2.SetFocusEnd IfEnd IfForm1.HideForm2.ShowEnd SubPrivate Sub Form_Load()Text1.Text = ""Text1.MaxLength = 6Text2.Text = ""Text2.MaxLength = 6Text2.PasswordChar = "*"End SubPrivate Sub Text1_LostFocus()If Not IsNumeric(Text1.Text) Then MsgBox "帐号必须为数字", , "警告" Text1.Text = ""Text1.SetFocusEnd IfEnd SubPrivate Sub Command1_Click()Form2.HideForm3.ShowEnd SubPrivate Sub Command2_Click()Form2.HideForm4.ShowEnd SubPrivate Sub Command3_Click()Form2.HideForm5.ShowEnd SubPrivate Sub Color_Click() CommonDialog1.Action = 3Text1.ForeColor = CommonDialog1.Color End SubPrivate Sub Command1_Click()Form3.HideForm2.ShowEnd SubPrivate Sub Copy_Click()Dim st As Stringst = Text1.SelTextEnd SubPrivate Sub Cut_Click()Dim st As Stringst = Text1.SelTextText1.SelText = ""End SubPrivate Sub Exit_Click()EndEnd SubPrivate Sub Font_Click()CommonDialog1.Flags = cdlCFBoth Or cdlCFEffects CommonDialog1.Action = 4Text1.FontName = CommonDialog1.FileNameText1.FontSize = CommonDialog1.FontSizeText1.FontBold = CommonDialog1.FontBoldText1.FontItalic = CommonDialog1.FontItalicText1.FontStrikethru = CommonDialog1.FontStrikethru Text1.FontUnderline = CommonDialog1.FontUnderline Text1.ForeColor = CommonDialog1.ColorEnd SubSub New_Click()Text1.Text = ""Me.Caption = FileEnd SubSub Open_Click()CommonDialog1.Action = 1Text1.Text = ""Open CommonDialog1.FileName For Input As #1Do While Not EOF(1)Line Input #1, inputdataText1.Text = Text1.Text + inputdata + vbCrLfLoopClose #1End SubPrivate Sub Paste_Click()Text1.SelText = stEnd SubPrivate Sub Print_Click()CommonDialog1.Action = 5For i = 1 To CommonDialog1.CopiesPrinter.Print Text1.TextNext iPrinter.EndDocEnd SubPrivate Sub SaveAs_Click()CommonDialog1.FileName = "vb课设用.txt" CommonDialog1.DefaultExt = "txt"CommonDialog1.Action = 2Open CommonDialog1.FileName For Output As #1 Print #1, Text1.TextEnd SubDim arr As Long, sum As Long, a As IntegerPrivate Sub Command1_Click()a = HScroll1.ValueText1.Text = plus(a)Call isprime(a)End SubPrivate Sub Command2_Click()EndEnd SubPrivate Sub HScroll1_Change()Label2.Caption = HScroll1.ValueEnd SubSub isprime(max As Integer)Dim x As Integer, i As Integer, j As IntegerFor i = 2 To maxx = 0For j = 2 To i - 1If i Mod j = 0 Then x = 1Next jIf x = 0 Then Label2.Caption = Label2.Caption & i & " " Next iEnd SubFunction plus(a As Integer) As LongFor i = 1 To asum = sum + iNext iplus = sumEnd FunctionDim x1 As IntegerDim y1 As IntegerDim x2 As IntegerDim y2 As IntegerDim flag As BooleanPrivate Sub Command1_Click()On Error Resume NextCommonDialog1.CancelError = True CommonDialog1.DialogTitle = "颜色" CommonDialog1.ShowColorIf Err <> 32755 Then Picture1.ForeColor = CommonDialog1.Color End IfEnd SubPrivate Sub Command2_Click()Picture1.ClsEnd SubPrivate Sub Command3_Click()Form5.HideForm6.ShowEnd SubPrivate Sub Option1_Click()Picture1.DrawWidth = 1End SubPrivate Sub Option2_Click()Picture1.DrawWidth = 2End SubPrivate Sub Option3_Click()Picture1.DrawWidth = 4End SubPrivate Sub Option4_Click()Picture1.DrawWidth = 8End SubPrivate Sub Form_Load()Picture1.Scale (0, 0)-(400, 400)flag = FalseEnd SubPrivate Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) flag = Truex1 = Xy1 = YEnd SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If flag = False ThenExit SubEnd IfIf flag = True Thenx2 = Xy2 = YPicture1.Line (x1, y1)-(x2, y2)x1 = x2y1 = y2End IfEnd SubPrivate Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) flag = FalseEnd SubDim ctP As Single, ctDu() As Single, ctDuS As LongPrivate Sub Command1_Click()Picture1.AutoRedraw = True: ctP = 3.1415926Timer1.Interval = 20: Timer1.Enabled = Not Timer1.EnabledEnd SubPrivate Sub Command2_Click()Form7.HideForm6.ShowEnd SubPrivate Sub Form_Load()Me.Caption = "旋转的椭圆": Command1.Caption = "转/停"Text1.Text = "9 个": Timer1.Enabled = FalseEnd SubPrivate Sub Text1_Change()ctDuS = Val(Text1.Text)If ctDuS > 200 Then Text1.Text = "200"If ctDuS < 1 Then ctDuS = 1ReDim ctDu(0 To ctDuS)End SubPrivate Sub Timer1_Timer()Dim I As LongPicture1.DrawWidth = 3Picture1.ClsFor I = 0 To ctDuSctDu(I) = ctDu(I) + ctP * 0.01 * I / 9If ctDu(I) > ctP * 2 Then ctDu(I) = ctDu(I) - ctP * 2Show1 ctDu(I), &HFFFFFF / (ctDuS + 1) * I * 0.6NextDim x As Single, y As SingleStatic J As SinglePicture1.DrawWidth = 15x0 = Picture1.ScaleWidth * 0.5: y0 = Picture1.ScaleHeight * 0.5 Picture1.PSet (x0, y0), 255x = 1200: y = 0: J = J - 0.05If J < -ctP * 2 Then J = J + ctP * 2Zhuan J, x, yPicture1.PSet (x0 + x, y0 + y), RGB(0, 0, 255)End SubPrivate Sub Show1(ToJ As Single, Se As Long)Dim I As Single, x As Single, y As Single, x0 As Single, y0 As Single Dim a As Single, b As Single, x1 As Single, y1 As SingleIf Picture1.ScaleWidth < Picture1.ScaleHeight Thena = Picture1.ScaleWidth * 0.45Elsea = Picture1.ScaleHeight * 0.45End Ifb = a * 0.25x0 = Picture1.ScaleWidth * 0.5: y0 = Picture1.ScaleHeight * 0.5x = -a: y = 0: Zhuan ToJ, x, yx1 = a: y1 = 0: Zhuan ToJ, x1, y1Picture1.Line (x0 + x, y0 + y)-(x0 + x1, y0 + y1), Sex = 0: y = -b: Zhuan ToJ, x, yx1 = 0: y1 = b: Zhuan ToJ, x1, y1Picture1.Line (x0 + x, y0 + y)-(x0 + x1, y0 + y1), SeFor I = 0 To ctP * 2 Step 0.1x = a * Sin(I): y = b * Cos(I)Zhuan ToJ, x, yPicture1.Line -(x0 + x, y0 + y), SeNextx = a * Sin(I): y = b * Cos(I)Zhuan ToJ, x, yPicture1.Line -(x0 + x, y0 + y), SeEnd SubPrivate Sub Zhuan(ToJ As Single, x As Single, y As Single) Dim S As Single, J As SingleS = Sqr(x ^ 2 + y ^ 2)If S = 0 Then J = 0 Else J = y / SIf Abs(J) >= 1 ThenIf J > 0 Then J = ctP * 0.5 Else J = -ctP * 0.5ElseJ = Atn(J / Sqr(-J * J + 1))End IfIf x < 0 Then J = -ctP - Jx = S * Cos(J + ToJ): y = S * Sin(J + ToJ) End Sub Private Sub Command1_Click()EndEnd Sub五、运行结果六.心得体会通过本次课程设计,使我对VB的认识更加深入了一层,VB主要由两部分组成,一个是Visual 可视化界面设计,另一个是Basic程序设计。
文本编辑器的代码

import java.util.Date;import org.eclipse.swt.SWT;import org.eclipse.swt.widgets.ColorDialog;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.Event;import org.eclipse.swt.widgets.FontDialog;import org.eclipse.swt.widgets.Listener;import org.eclipse.swt.widgets.Shell;import org.eclipse.swt.widgets.ToolBar;import org.eclipse.swt.widgets.ToolItem;import org.eclipse.swt.custom.StyledText;import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent;import org.eclipse.swt.graphics.Color;import org.eclipse.swt.graphics.Font;import org.eclipse.swt.graphics.FontData;import org.eclipse.swt.graphics.RGB;import com.ibm.icu.text.SimpleDateFormat;import com.swtdesigner.SWTResourceManager; import org.eclipse.swt.widgets.Button;public class Notepad extends Shell {/*** Launch the application.* @param args*/public static void main(String args[]) {try {Display display = Display.getDefault();Notepad shell = new Notepad(display);shell.open();yout();while (!shell.isDisposed()) {if (!display.readAndDispatch()) {display.sleep();}}} catch (Exception e) {e.printStackTrace();}}/*** Create the shell.* @param display*/public Notepad(Display display) {super(display, SWT.CLOSE | SWT.MIN | SWT.TITLE);setImage(SWTResourceManager.getImage(Notepad.class, "/icons/progress/ani/3.png"));ToolBar toolBar = new ToolBar(this, SWT.FLA T | SWT.RIGHT);toolBar.setBounds(10, 157, 251, 32);final ToolItem bgColorButton = new ToolItem(toolBar, SWT.NONE);bgColorButton.setWidth(50);bgColorButton.setText(" bgColor ");final ToolItem forColorButton = new ToolItem(toolBar, SWT.NONE);forColorButton.setText(" forColor ");final ToolItem fontButton = new ToolItem(toolBar, SWT.NONE);fontButton.setWidth(50);fontButton.setText(" font ");final StyledText styledText = new StyledText(this, SWT.BORDER|SWT.WRAP|SWT.V_SCROLL);styledText.setBounds(10, 195, 251, 98);final StyledText styledText_1 = new StyledText(this, SWT.BORDER | SWT.WRAP|SWT.V_SCROLL);styledText_1.setEditable(false);styledText_1.setBounds(10, 10, 251, 141);SelectionAdapter listener_1=new SelectionAdapter(){public void widgetSelected(SelectionEvent e){Button b=(Button)e.widget;if(b.getText().equals("确定")){SimpleDateFormat dateFormat=new SimpleDateFormat(" MM-dd hh:mm:ss");String date=dateFormat.format(new Date());String c=styledText.getText();styledText_1.append("花蝴蝶"+date+":\n"+c+"\n");styledText.setText("");}else if(b.getText().equals("清空")){styledText.setText("");}}};Button button = new Button(this, SWT.NONE);button.setBounds(10, 297, 79, 27);button.setText("\u786E\u5B9A");button.addSelectionListener(listener_1);Button button_1 = new Button(this, SWT.NONE);button_1.setBounds(181, 297, 80, 27);button_1.setText("\u6E05\u7A7A");button_1.addSelectionListener(listener_1);createContents();final Shell shell=new Shell(display);Listener listener=new Listener(){public void handleEvent(Event event){if(event.widget==bgColorButton){ColorDialog dialog=new ColorDialog(shell);RGB rgb=dialog.open();if(rgb!=null){Color color=new Color(shell.getDisplay(),rgb);styledText.setForeground(color);styledText_1.setForeground(color);}}else if(event.widget==forColorButton){ColorDialog dialog=new ColorDialog(shell);RGB rgb=dialog.open();if(rgb!=null){Color color=new Color(shell.getDisplay(),rgb);styledText.setForeground(color);styledText_1.setForeground(color);}}else if(event.widget==fontButton){FontDialog dialog=new FontDialog(shell);FontData fontData=dialog.open();if(fontData!=null){Font font=new Font(shell.getDisplay(),fontData);styledText.setFont(font);styledText_1.setFont(font);}}}};bgColorButton.addListener(SWT.Selection,listener);forColorButton.addListener(SWT.Selection,listener);fontButton.addListener(SWT.Selection,listener);}/*** Create contents of the shell.*/protected void createContents() {setText("Notepad");setSize(277, 364);}@Overrideprotected void checkSubclass() {// Disable the check that prevents subclassing of SWT components }}。
分享10个程序员常用的的代码文本编辑器

分享10个程序员常⽤的的代码⽂本编辑器通常操作系统和软件开发包中都包含⽂本编辑器,可以⽤来编辑配置⽂件,⽂档⽂件和源代码。
下⾯是笔者总结的10个最好的免费代码⽂本编辑器:1.NOTEPAD++NOTEPAD++是⼀款免费⼜优秀的⽂本编辑器,⽀持在MS Windows环境下运⾏的多种编程语⾔。
NOTEPAD++⽀持超过50种编程、脚本和标记语⾔的语法⾼亮显⽰和代码折叠,能让⽤户迅速减⼩或扩⼤代码段以便查阅整个⽂档。
⽤户也可以⼿动设置当前语⾔,覆盖默认语⾔。
该程序还⽀持⾃动完成某些编程语⾔的API⼦集。
2.VIMVIM是⼀个可⾼度⾃由配置的⽂本编辑器。
它是Vi编辑器的改进版,同时也是免费软件。
该应有程序的建⽴是为了处理代码以及其他很多事情,⽽不只是为了写电⼦邮件和打开配置⽂件。
它允许你编辑⽂本并保存简单的⽂本⽂件,但它的主要功能是还是编辑代码。
它⽀持语法⾼亮显⽰和⾏编号,这是写程序必备的两个基本功能。
⽤户也可以改变界⾯颜⾊以便增加代码的可视性。
对于⽂本编辑,VIM这个程序囊括了多种语⾔的拼写检查器,并有建议如何更正拼写错误的能⼒。
甚⾄是当你正在编写代码的时候,它也能派上⽤场,因为该应⽤程序只检查不被识别为代码的⽂本。
当然你也可以快速地从这个错误跳到下⼀个以便更好地校对⽂本。
VIM是程序员和开发⼈员应对各种⽂本编辑的最佳选择。
3.GNU EmacsEmacs是⼀个可移植、可扩展、免费的⽂本编辑器。
Emacs提供了⼀些命令来管理语句和段落,⾼亮的语法使得源代码更易于阅读,以及“键盘宏”的⽅式来执⾏⽤户定义的编辑命令。
Emacs可以在若⼲个操作系统上运⾏,⽆论你使⽤的是哪⼀种机器类型。
这让程序员⾮常受⽤。
如果你使⽤的是通⽤的编程语⾔,Emacs还会为你提供模式以及相应的排版和布局,更加⽅便你编辑代码。
Emacs或许不是最简单的⼯具,但它绝对是最强⼤的编辑器之⼀。
相⽐vim,Emacs的启动时间更长,所需要的内存也更多。
文章编辑程序源代码

#include<iostream.h>#include <string.h>#include <stdio.h> /*文本每行以字符串形式存储,行与行之间以链表存储*/typedef struct line{char *data;struct line *next;}LINE; /*创建一链表,同时向里面输入文本数据*/void Create(LINE * &head){printf ("请输入一页文章,以Ctrl+E(^E)为结尾(每行最多输入80字符!):\n");LINE *p=new LINE; /*首先为链表建立一个附加表头结点*/ head=p; /*将p付给表头指针*/char tmp[100];while(1){gets(tmp); /*输入字符串!*/if(strlen(tmp)>80){printf("每行最多输入80字符");break;}if(tmp[0]==5)break; /*如果发现输入 ^E,则退出输入*/p=p->next=new LINE;p->data=new char[strlen(tmp)+1]; /*为结点分配空间 */strcpy(p->data,tmp);if(tmp[strlen(tmp)-1]==5) /*除去最后一个控制符 ^E */{p->data[strlen(tmp)-1]='\0';break;}}p->next=NULL; /*最后的一个指针为空 */head=head->next;}/*统计字母数*/int CountLetter(LINE * &head){LINE *p=head;int count=0;do{int Len=strlen(p->data); /*计算当前 data 里的数据元素的个数*/for(int i=0;i<Len;i++)if((p->data[i]>='a'&&p->data[i]<='z')||(p->data[i]>='A'&&p->data[i]<='Z')) /*计算字母数*/count++;}while((p=p->next)!=NULL); /*遍历链表*/return count; /*返回文章的字母总数*/}/*统计数字数*/int CountNumber(LINE * &head){LINE *p=head;int count=0;do{int Len=strlen(p->data); /*计算当前 data 里的数据元素的个数*/ for(int i=0;i<Len;i++)if(p->data[i]>=48 && p->data[i]<=57)count++;/*计算数字数,ASCII码*/}while((p=p->next)!=NULL); /*遍历链表*/return count;}/*统计空格数*/int CountSpace(LINE * &head){LINE *p=head;int count=0;do{int Len=strlen(p->data); /*计算当前 data 里的数据元素的个数*/ for(int i=0;i<Len;i++)if(p->data[i]==32)count++; /*计算空格数,空格ASCII码为32*/ }while((p=p->next)!=NULL); /*遍历链表*/return count;}/*统计文章的总字数*/int CountAll(LINE * &head){LINE *p=head; /*保存链表的首地址*/int count=0;do /*计算总字符数*/{count+=strlen(p->data);}while((p=p->next)!=NULL); /*遍历链表*/return count;}/*统计str在文章中出现的次数*/int FindString(LINE * &head,char *str){LINE *p=head;int count=0;int h=0;int len1=0; /*保存当前行的总字符数*/ int len2=strlen(str); /*待统计字符串的长度*/ int i,j,k;do{len1=strlen(p->data); /*当前行的字符数*/for(i=0;i<len1;i++) /*字符匹配*/{if(p->data[i]==str[0]){k=0;for(j=0;j<len2;j++)if(p->data[i+j]==str[j]) k++;if(k==len2) {count++;i=i+k-1;}}}}while((p=p->next)!=NULL); /*遍历链表*/return count;}/*删除指定的字符串*/void delstringword(char *s,char *str)/* *s为输入的字符串,*str为将要删除的字符*/{char *p=strstr(s,str); /*从字符串s中寻找str第一次出现的位置*/ char tmp[80];int len=strlen(s);int i=len-strlen(p);int j=i+strlen(str);int count=0;for(int m=0;m<i;m++)tmp[count++]=s[m];for(int n=j;n<len;n++)tmp[count++]=s[n];tmp[count]='\0';strcpy(s,tmp); /*返回新的字符串*/}void DelString(LINE * &head,char *str){LINE *p=head;do{if(strstr(p->data,str)!=NULL)delstringword(p->data,str);}while((p=p->next)!=NULL); /*遍历链表*/}/*向屏幕输出文章*/void OutPut(LINE * &head){LINE *p=head;do{printf("%s\n",p->data);}while((p=p->next)!=NULL); /*遍历链表*/}void main(){LINE *head;Create(head);printf("输入的文章为:\n");OutPut(head);printf("\n");printf("全部字母数:%d \n",CountLetter(head));printf("数字个数:%d \n",CountNumber(head));printf("空格个数: %d \n",CountSpace(head));printf("文章总字数: %d \n",CountAll(head));char str1[20],str2[20];printf("\n");printf("请输入要统计的字符串:");scanf("%s",str1);printf("%s出现的次数为:%d \n",str1,FindString(head,str1));printf("\n");printf("请输入要删除的某一字符串:");scanf("%s",str2);DelString(head,str2);printf("删除%s后的文章为:\n",str2);OutPut(head);}。
文本编辑器源码

ColorSlider2.setPaintTicks(true);
ColorSlider3.setPaintTicks(true);
ColorSlider1.setMajorTickSpacing(51);
ColorSlider2.setMajorTickSpacing(51);
public class EditPanel extends JPanel
{
public EditPanel()
{
JPanel FontPanel = new JPanel();
JPanel BackColorPanel = new JPanel();
JPanel TextAreaPanel = new JPanel();
ColorSlider1.setPaintTicks(true);
ColorSlider2.setPaintTicks(true);
ColorSlider3.setPaintTicks(true);
ColorSlider1.setPaintLabels(true);
ColorSlider2.setPaintLabels(true);
CopyItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,InputEvent.CTRL_DOWN_MASK));
CopyItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,InputEvent.CTRL_DOWN_MASK));
Action pictureAction = new PictureAction();
java文本编辑器源码

/** To change this template, choose Tools | Templates* and open the template in the editor.*/package NotepadDemo;/**** @author DELL*/import java.awt.BorderLayout;import java.awt.FileDialog;import java.awt.Font;import java.awt.datatransfer.Clipboard;import java.awt.datatransfer.DataFlavor;import java.awt.datatransfer.StringSelection;import java.awt.datatransfer.Transferable;import java.awt.datatransfer.UnsupportedFlavorException;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;import javax.swing.JFrame;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTextArea;import javax.swing.border.TitledBorder;public class NotepadDemo extends JFrame {private static final long serialVersionUID = -5355432125621015300L;private String url = null;//文件路径private String str=null;//复制或剪切的字符串private StringSelection stringSelection=null;private Clipboard clipboard=new Clipboard(str);private Transferable transferable=null;private DataFlavor flavor=null;public NotepadDemo() {init();}private void init() {setTitle("文本编辑器");setSize(500, 600);setContentPane(createContentPane());//添加主面板}/*创建主面板*/private JPanel createContentPane() {JPanel pane = new JPanel(new BorderLayout());pane.add(BorderLayout.NORTH, createChocePane());//添加菜单栏pane.add(createAreaPane());//添加文本编辑区域return pane;}/*创建菜单栏,以及实现功能*/private JPanel createChocePane() {JPanel pane = new JPanel();JMenuBar menuBar1 = new JMenuBar();JMenu menu = new JMenu("文件");menuBar1.add(menu);JMenuItem menuIt1 = new JMenuItem("新建");JMenuItem menuIt2 = new JMenuItem("打开");JMenuItem menuIt3 = new JMenuItem("保存");JMenuItem menuIt4 = new JMenuItem("另存为");menu.add(menuIt1);menu.add(menuIt2);menu.add(menuIt3);menu.add(menuIt4);JMenuBar menuBar2 = new JMenuBar();JMenu menu2 = new JMenu("编辑");menuBar2.add(menu2);JMenuItem menuIt5 = new JMenuItem("复制");JMenuItem menuIt6 = new JMenuItem("剪切");JMenuItem menuIt7 = new JMenuItem("粘帖");menu2.add(menuIt5);menu2.add(menuIt6);menu2.add(menuIt7);JMenuBar menuBar3 = new JMenuBar();JMenu menu3 = new JMenu("帮助");menuBar3.add(menu3);JMenuItem menuIt8 = new JMenuItem("关于记事本");menu3.add(menuIt8);pane.add(menuBar1);pane.add(menuBar2);pane.add(menuBar3);menuIt1.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {testArea.setText(null);}});menuIt2.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {final FileDialog fd = new FileDialog(new JFrame(), "查找文件",FileDialog.LOAD);fd.setVisible(true);if (fd.getDirectory() != null && fd.getFile() != null) {testArea.setText(null);url = fd.getDirectory() + fd.getFile();try {BufferedReader in = new BufferedReader(new FileReader(url));for (int i = 0;; i++) {testArea.append(in.readLine());if (in.read() == -1) {break;} elsecontinue;}} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}}});menuIt3.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {if (url==null) {url="D:\\文本编辑器文本文档.txt";}File f = new File(url);BufferedWriter out = null;try {out = new BufferedWriter(new FileWriter(url));f.createNewFile();out.append(testArea.getText());out.flush();} catch (IOException e1) {e1.printStackTrace();} finally {try {out.close();} catch (IOException e1) {e1.printStackTrace();}}}});menuIt4.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {FileDialog fd = new FileDialog(new JFrame(), "保存文本",FileDialog.SAVE);fd.setVisible(true);if (url!=null) {File f = new File(url);BufferedWriter out = null;try {f.createNewFile();out = new BufferedWriter(new FileWriter(url));out.append(testArea.getText());out.flush();} catch (IOException e) {e.printStackTrace();} finally {try {out.close();} catch (IOException e) {e.printStackTrace();}}}}});menuIt5.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {str=testArea.getSelectedText();stringSelection=new StringSelection(str);clipboard.setContents(stringSelection, null);}});menuIt6.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent arg0) {str=testArea.getSelectedText();stringSelection=new StringSelection(str);clipboard.setContents(stringSelection, null);int start=testArea.getSelectionStart();int end=testArea.getSelectionEnd();testArea.replaceRange( null,start,end);}});menuIt7.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {transferable=clipboard.getContents(this);flavor=DataFlavor.stringFlavor;if (transferable.isDataFlavorSupported(flavor)) {int start=testArea.getSelectionStart();int end=testArea.getSelectionEnd();testArea.replaceRange( null,start,end);int pos=testArea.getCaretPosition();try {str=(String)transferable.getTransferData(flavor);testArea.insert(str, pos);} catch (UnsupportedFlavorException e1) {e1.printStackTrace();} catch (IOException e1) {e1.printStackTrace();}}}});menuIt8.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {JOptionPane.showMessageDialog(null,"原创");}});return pane;}JTextArea testArea;private JScrollPane createAreaPane() {JScrollPane pane = new JScrollPane();pane.setBorder(new TitledBorder("编辑区域"));testArea = new JTextArea();testArea.setFont(new Font("宋体", Font.BOLD, 13));testArea.setLineWrap(true);pane.getViewport().add(testArea);return pane;}public static void main(String[] args) {NotepadDemo td = new NotepadDemo();td.setVisible(true);}}。
分享一个Delphi制作的文档编辑器源代码(仿Word)

分享⼀个Delphi制作的⽂档编辑器源代码(仿Word)
功能挺多的,就是很多地⽅都没有完善。
不过简单使⽤,是没有问题的。
我也忘记是在哪个⽹站下载的,可能是Git国外的⽹站。
仿Word⽂档编辑器,不过其实没有必要的,因为⽤户会直接使⽤微软或者其他软件来制作⾃⼰的⽂档。
但是却具有参考价值,虽然代码需要优化的地⽅还有很多。
⽐如那些添加控件这些可以去除,把代码结构处理得紧凑⼀些,⽽且增加更多可以⾃定义的地⽅就更理想了。
其实⼤家最最讨厌都是⼀些滚动条和控件背景颜⾊都⽆法⾃定义,都被写得死死的,就像原来Vcl那些玩意⼀样。
想弄个⾃定义界⾯都办不到。
这套代码也是这样,所以需要⼤家⾃⼰改。
下⾯这个是我改的,多页功能,我去掉了,改成单页,跟RichEdit这种类型⼀样。
不过完全⽀持表格、图⽚、GIF图⽚这些添加,⽽且可以⾃定义编辑框背景图⽚的添加和更换。
这样⼀来,也算是解决了⼀直以来的⼼愿。
⾄少收集和管理各种⽂档资料更加⽅便了。
在这⾥提供原来代码的下载地址,原来的忘记了:
有兴趣的,⾃⼰下载看看,⾄于我改的就不提供了。
它⾥⾯带有作者的通讯⽅式,有兴趣可以联系交流。
25编程器源码

25编程器源码以下是一些编程器的源代码,可以帮助您在编写软件时提高效率和准确性。
1. 文本编辑器:一个简单的文本编辑器,可以让用户打开、编辑和保存文本文件。
它具有基本的文本编辑功能,如复制、粘贴和查找/替换。
```#include <iostream>#include <fstream>int main() {std::string filename;std::cout << 'Enter filena ';std::cin >> filename;std::ifstream file(filename);if (!file) {std::cout << 'Error opening the file!' << std::endl; return 1;}std::string line;while (std::getline(file, line)) {std::cout << line << std::endl;}file.close();return 0;}```2. 图片处理器:一个可以打开、编辑和保存图像文件的程序。
它可以执行一些基本的图像操作,如调整大小、旋转和应用滤镜。
```#include <iostream>#include <opencv2/opencv.hpp>int main() {std::string filename;std::cout << 'Enter filena ';std::cin >> filename;cv::Mat image = cv::imread(filename);if (image.empty()) {std::cout << 'Error opening the image!' << std::endl; return 1;}// Perform some image processing operations herecv::imshow('Image', image);cv::waitKey(0);cv::destroyAllWindows();return 0;}```3. 数据库管理器:一个用于连接和管理数据库的程序。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
/* A Screen Editer Subsystem */#define TURBOC#include <stdio.h>#include <dos.h>#include <string.h>#include <bios.h>#include <conio.h>#define BUF_SIZE 32000#define LINE_LEN 79-2#define MAX_LINES 24-1#define KILL_BUF_SIZE 4*LINE_LEN/***********************************************************/char buf[BUF_SIZE];char *curloc,*endloc;int scrnx,scrny;char killbuf[KILL_BUF_SIZE];char *helpline="F1:save F2:load F3:find F4:replace ^K:kill line ^Y:Yank ^Z:qiut"; /*************************************************************/ void edit(char *fname),help(void);void gotoxy(int x,int y),clrline(int y);void edit_clr_col(int x,int y),clrscr(void);void printline(char *p),delete_char(void);void search(void),kill_line(void);void scrolldn(int x,int y);void scrollup(int topx,int topy,int endx,int endy);void upline(void);void downline(void),left(void),right(void);void display_scrn(int x,int y,char *p);void pagedown(void),pageup(void),replace(void);void home(void),gotoend(void),yank(void);int load(char *fname),save(char *fname);void edit_gets(char *str);void draw_border(int,int,int,int,int);/***************************************************/main(int argc,char *argv[]){union REGS r;char fname[80];if(argc<2){draw_border(0,0,78,24,0x1f);draw_border(20,12,60,14,0x2f);gotoxy(20,11);printf("\7FILE NAME:");gotoxy(21,13);gets(fname);edit(fname);}if(argc==2){strupr(argv[1]);if(strstr(argv[1],".EXE")||strstr(argv[1],".COM")||\strstr(argv[1],".OBJ")||strstr(argv[1],".LIB")){printf("\7Can't edit file :%s",argv[1]);exit(1);}else edit(argv[1]);}r.h.ah=6;r.h.al=0;r.h.ch=0;r.h.cl=0;r.h.dh=24;r.h.dl=79;r.h.bh=7;int86(0x10,&r,&r);gotoxy(1,1);}/******************************************************************/ void edit(char *fname){union k{char ch[2];unsigned i;}key;char name[80];/* try to load the file */if(!load(fname))curloc=endloc=buf;strcpy(name,fname);/* set initial values to X,Y coordinate vars */scrnx=scrny=0;display_scrn(0,0,curloc);help();gotoxy(1,1);/* editer main loop . */do{#ifdef TURBOCkey.i=bioskey(0);#endifif(!key.ch[0]){switch(key.ch[1]){case 59: /*F1 :save file */save(name);break;case 60: /*F2: load file */clrline(MAX_LINES);gotoxy(1,MAX_LINES);printf("Enter filename :");edit_gets(name);strupr(name);if(strstr(name,".EXE")||strstr(name,".COM")||\strstr(name,".OBJ")||strstr(name,".LIB")){gotoxy(1,MAX_LINES);printf("\7Can't edit file: %s",name);getch();help();break;}if( * name) load(name);help();display_scrn(0,0,curloc);scrnx=scrny=0;break;case 61:search();break;case 62:replace();break;case 71:home();break;case 79:gotoend();break;case 75: /*left*/left();break;case 77:right();break;case 72:upline();break;case 80:downline();break;case 73:pageup();break;case 81:pagedown();break;case 83: /*Del*/if(curloc<endloc) delete_char();break;}if(curloc<buf){scrnx=scrny=0;curloc=buf;}gotoxy(scrnx+1,scrny+1); /*postion cursor */ }else{switch(key.ch[0]){case '\r':/*see if buffer is full */if(endloc==buf+BUF_SIZE-2) break;/* move contents of file below current location down one byte to make room for the RETURN.*/ memmove(curloc+1,curloc,endloc-curloc+1);*curloc=key.ch[0]; /*put RETURN in file *//*clear rest of line */edit_clr_col(scrnx,scrny);scrnx=0;scrny++;/*move text on screen down */if(scrny==MAX_LINES-1){/*at bottom of page */scrny=MAX_LINES-2;scrollup(1,1,LINE_LEN,scrny+1);}else scrolldn(scrnx+1,scrny+1);gotoxy(scrnx+1,scrny+1);printline(curloc);endloc++;/* advance the end of file pointer */ break;case '\b':if(curloc==buf) break;left();delete_char();break;case 11:kill_line();break;case 25:yank();break;case 26:clrline(MAX_LINES);gotoxy(1,MAX_LINES);printf("If saved file,press[Y]exit\7");if(tolower(getch())=='y') goto end;help();break;default: /* enter keystroke into file *//*see if buf is full */if(endloc==buf+BUF_SIZE-2) break;/*can't type past end of line */if(scrnx==LINE_LEN) break;memmove(curloc+1,curloc,endloc-curloc+1); *curloc=key.ch[0];putch(*curloc);gotoxy(scrnx+1,scrny+1);printline(curloc+1);curloc++;endloc++;}gotoxy(scrnx+1,scrny+1);}}while(1);end:printf("\n");}/**************************************************************************** Display a line pointed to by p.****************************************************************************/ void printline(register char *p){register int i;i=scrnx+1;while(*p!='\r'&&*p&&i<LINE_LEN){putch(*p);p++;i++;}}/**************************************************************************** Insert previously killled line.****************************************************************************/ void yank(void){char *p;p=killbuf;while(*p){memmove(curloc+1,curloc,endloc-curloc+1);*curloc=*p;if(scrnx<LINE_LEN){putch(*curloc);scrnx++;}endloc++;p++;}}/*******************************************************//* Delete the line at the current location */void kill_line(void){register int i;char *p,*killbufptr;if(*curloc=='\r'){delete_char();return;}edit_clr_col(scrnx,scrny); /*clear to CR *//* find out hoe many characters are in the line */p=curloc;i=0;killbufptr=killbuf;while(*p!='r'&&p<endloc){i++;*killbufptr=*p;p++;if(killbufptr<killbuf+KILL_BUF_SIZE-2) killbufptr++;}*killbufptr='\0';/* remove the line */memmove(curloc,curloc+i,endloc-curloc);endloc-=i;}/*********************************************************************** Global search and replace***********************************************************************/ void replace(void){register int len1;char str1[80],str2[80];char *p,*p2;clrline(MAX_LINES);gotoxy(1,MAX_LINES);printf("enter string to replace :");edit_gets(str1);clrline(MAX_LINES);gotoxy(1,MAX_LINES);printf("enter replacement:");edit_gets(str2);p=curloc;len1=strlen(str1);while(*str1){/*search for the string */while(*p && strncmp(str1,p,len1)) p++; if(!*p){clrline(MAX_LINES);gotoxy(1,MAX_LINES);printf("No found string %s",str1); getch();help();break;} /* not found *//* remove old string */memmove(p,p+len1,endloc-p);endloc-=len1;/*insert new string */p2=str2;while(*p2){memmove(p+1,p,endloc-p+1);*p=*p2;p++;endloc++;p2++;}}clrscr();/* find location of top screen */p=curloc;for(len1=scrny;len1>=0&&p<buf;){p--;if(*p=='r') len1--;}if(*p=='r') p++;/* redisplay current screen */display_scrn(0,0,p);help();}void delete_char(void){gotoxy(scrnx+1,scrny+1);if(*curloc=='r'){scrollup(1,scrny+1+1,LINE_LEN,MAX_LINES-1);memmove(curloc,curloc+1,endloc-curloc);endloc--;display_scrn(scrnx,scrny,curloc);help();}else{memmove(curloc,curloc+1,endloc-curloc);endloc--;printline(curloc);printf("");}}/************************************************************************* Display help line.*************************************************************************/ void help(void){gotoxy(1,MAX_LINES);printf(helpline);}/************************************************************************* Move cuuren location left*************************************************************************/ void left(void){if(curloc==buf) return;scrnx--;if(scrnx<0){scrnx=0;upline(); /*go up to next line *//* find end of line */while(*curloc!='r'){curloc++;scrnx++;}}else curloc--;}/********************************************************************** Move current position right.**********************************************************************/ void right(void){if(curloc+1>endloc) return;scrnx++;/* if at the end of line,go to the next one. */if(scrnx>LINE_LEN||*curloc=='\r'){scrnx=0;scrny++;if(scrny==MAX_LINES-1) /* at end of screen */{scrny=MAX_LINES-2;downline();/* move cursor and current loc to start of new line */curloc--;while(*curloc!='\r') curloc--;curloc++;scrnx=0;}else curloc++;}else curloc++;}/**********************************************************************/ void search(void){char str[80];register char *p;int len,i;clrline(MAX_LINES);gotoxy(1,MAX_LINES);printf("search string :");edit_gets(str);if(! *str){help();return;}p=curloc;len=strlen(str);while(*p&&strncmp(str,p,len)) p++;if(! *p){gotoxy(1,MAX_LINES);printf("\7No found string %s!",str);getch();help();return;} /* not found */i=0;while(p>buf&&*p!='\r'){p--;i++;}p++;i--;/* reposition curren location to start of match */curloc=p+i;scrnx=i;scrny=0;clrscr();display_scrn(0,0,p);help();}/***************************************************************************** Move up a line.*****************************************************************************/ void upline(void){register int i;char *p;if(curloc==buf)return;p=curloc;if(*p=='\r') p--;for(;*p!='\r'&&p<buf;p--);if(*p=='\r')return;curloc=p;curloc--;i=scrnx; /* save X coordinate *//* find start of next line */while(*curloc!='\r'&&curloc>buf) curloc--;scrny--;scrnx=0;curloc++;/* if at top of screen ,must stop */if(scrny<0){scrolldn(1,1);scrny=0;gotoxy(1,1);printline(curloc);}while(i&&*curloc!='\r'){curloc++;scrnx++;i--;}}/*************************************************************************** Move down one line,keep previous scrnx location if possible**************************************************************************/ void downline(void){register int i;char *p;i=scrnx;p=curloc;while(*p!='\r'&&p<endloc) p++;if(p==endloc) return;p++;curloc=p;scrny++;scrnx=0;if(scrny==MAX_LINES-1){scrny=MAX_LINES-2;scrollup(1,1,LINE_LEN,MAX_LINES-1);gotoxy(scrnx+1,scrny+1);printline(curloc);}while(i&& *curloc!='\r' && curloc<endloc){curloc++;scrnx++;i--;}}/**************************************************************************** Display a screen full of text (up to 24 lines)***************************************************************************/ void display_scrn(int x,int y,char *p){register int i,j;gotoxy(x+1,y+1);textcolor(WHITE);textbackground(BLUE);i=0;while(y<MAX_LINES-1&&*p){switch(*p){case '\r': printf("\n");y++;gotoxy(1,y+1);i=0;break;case '\x09':for(j=0;j<8;j++){printf(" ");i++;}default:if(i<LINE_LEN) putch(*p);i++;}p++;}}/**************************************************************************** Page down MAX_LINES lines*****************************************************************************/ void pagedown(void){register int i;clrscr();for(i=0;i<MAX_LINES&&curloc<endloc;){if(*curloc=='\r') i++;curloc++;}help();scrnx=0;scrny=0;display_scrn(0,0,curloc);}/*************************************************************************** Page up MAX_LINES line***************************************************************************/ void pageup(void){register int i;clrscr();for(i=0;i<MAX_LINES&&curloc>buf;){if(*curloc=='\r') i++;curloc--;}scrnx=scrny=0;display_scrn(0,0,curloc);help();}/************************************************************************** Go to the end of the file**************************************************************************/ void gotoend(void){int i;char *p;p=curloc;for(i=scrnx;*p!='\r'&&p<endloc;){scrnx++;p++;i++;}gotoxy(scrnx+1,scrny+1);curloc=p;}/**************************************************************************** Load a file****************************************************************************/ int load(char *fname){FILE *fp;char ch,*p;int i;draw_border(0,0,78,24,0x2f);clrscr();if((fp=fopen(fname,"rb"))==NULL) return 0;gotoxy(1,1);p=buf;while(!feof(fp)&&p!=buf+BUF_SIZE-2){ch=getc(fp);if(ch=='\x09')for(i=0;i<8;i++,p++) *p='\x20';else if(ch!='\n'&&ch!=EOF){*p=ch;p++;}}*p='\0';fclose(fp);curloc=endloc=p;clrscr();curloc=buf;help();scrnx=scrny=0;display_scrn(0,0,curloc);}/****************************************************************************** ***Go to top the file******************************************************************************/ void home(void){curloc-=scrnx;scrnx=0;gotoxy(scrnx+1,scrny);}/****************************************************************************** Save a file*****************************************************************************/ int save(char *fname){int i;FILE *fp;char *p,name[80];if(!*fname){clrline(MAX_LINES);gotoxy(1,MAX_LINES);printf("filename:");gets(name);}else strcpy(name,fname);if((fp=fopen(name,"wb"))==NULL) return 0;p=buf;while(p!=endloc){if(*p!='\r')putc(*p,fp);else{putc('\r',fp);putc('\n',fp);}p++;}fclose(fp);clrline(MAX_LINES);printf("file %s already saved.",name);help();return 1;}/****************************************************************************** Read a string from the keyboard*****************************************************************************/ void edit_gets(char *str){char *p;p=str;for(;;){*str=getch();if(*str=='\r'){*str='\0';return;}if(*str=='\b'){if(str>p){str--;putch('\b');putch(' ');putch('\b');}}else{putch(*str);str++;}}}/****************************************************************************** *Read and save cursor coordinates******************************************************************************/ void cursor_pos(void){union REGS i,o;i.h.ah=3;int86(16,&i,&o);}/****************************************************************************** **Send cursor to specified X,Y(0,0 is upper left corner).*****************************************************************************/ void gotoxy(int x,int y){union REGS i;i.h.dh=y;i.h.dl=x;i.h.ah=2;i.h.bh=0;int86(16,&i,&i);}/***************************************************************************** Clear entire line given its Y coordinate*****************************************************************************/ void clrline(int y){register int i;gotoxy(1,y);for(i=0;i<LINE_LEN;i++) putch(' ');textcolor(WHITE);textbackground(BLUE);}/**************************************************************************** Clear to end of specified line.****************************************************************************/ void edit_clr_col(int x,int y){char *p;p=curloc;gotoxy(x+1,y+1);for(;x<LINE_LEN&&*p!='\r'&&*p;x++,p++){printf(" ");}}/**************************************************************************** Clear the screen.****************************************************************************/ void clrscr(void){union REGS r;r.h.ah=6;r.h.al=0;r.h.ch=1;r.h.cl=1;r.h.dh=MAX_LINES-1;r.h.dl=LINE_LEN;r.h.bh=0x1f;int86(0x10,&r,&r);}/*************************************************************************** Scroll down the screen.***************************************************************************/ void scrolldn(int x,int y){union REGS r;r.h.ah=7;r.h.al=1;r.h.ch=y;r.h.cl=x;r.h.dh=MAX_LINES-1;r.h.dl=LINE_LEN;r.h.bh=0x1f;int86(0x10,&r,&r);}/**************************************************************************** Srcoll up the screen.****************************************************************************/ void scrollup(int topx,int topy,int endx,int endy){union REGS r;r.h.ah=6;r.h.al=1;r.h.ch=topy;r.h.cl=topx;r.h.dh=endy;r.h.dl=endx;r.h.bh=0x1f;int86(0x10,&r,&r);}/**************************************************************************/ void draw_border(int beginx,int beginy,int endx,int endy,int attr){int i;union REGS r;r.h.ah=6;r.h.al=0;r.h.ch=beginy;r.h.cl=beginx;r.h.dh=endy;r.h.dl=endx+1;r.h.bh=attr;int86(0x10,&r,&r);for(i=beginx;i<endx;i++){ gotoxy(i,beginy);putchar(196);gotoxy(i,endy);putchar(196);}for(i=beginy;i<=endy;i++){gotoxy(beginx,i);putchar(179);gotoxy(endx,i);putchar(179);}gotoxy(beginx,beginy);putchar(218);gotoxy(beginx,endy);putchar(192);gotoxy(endx,beginy);putchar(191);gotoxy(endx,endy);putchar(217);}。