记事本-编程实例

合集下载

实验三利用记事本等编制程序,.

实验三利用记事本等编制程序,.

实验三:利用记事本等编制程序,将程序导入并利用模拟功能进行轨迹检验一、使用记事本或写字板,编写简单零件的数控车床加工程序对几何形状简单、单一的切削路线,如:外径、内径、端面的切削,若加工余量较大,刀具常常要反复地执行相同的动作,才能达到工件要求的尺寸。

要完成上述加工,在一个程序中就要写入很多的程序段,为了简化程序,减少程序所占内存,数控机床设有各种固定循环指令,只需用一个指令,一个程序段,便可完成一次乃至多次重复的切削动作。

轴向(圆柱或圆锥)切削循环指令(G90)如图3-1所示,刀具从循环起点开始按矩形循环,其加工顺序按1,2,3,4进行,最后又回到循环起点。

图中虚线表示按R快速移动,点划线表示按F指定的工件进给速度移动。

图3-1(a)和(b)分别为圆柱或圆锥切削循环示意图。

(1)圆柱面切削循环指令格式:G90 X(U)- Z(W)- F-;(2)圆锥面切削循环指令格式:G90 X(U)- Z(W)- I- F-;功能:进行外圆及内孔直线加工和锥面加工循环,可以简化编程。

其中:X、Z为切削终点坐标;U、W为切削终点相对于循环起点坐标值的增量;I为工件加工锥面大小端直径差的1/2,当锥面的起点坐标大于终点坐标时为正,反之为负;F为切削进给速度。

注意事项如下。

(1)使用循环切削指令,刀具必须先定位至循环起点,再执行循环切削指令,且完成一循环切削后,刀具仍回到此循环起点。

(2)G90是模态指令。

一旦规定,以下程序段一直有效,在完成固定切削循环后,用另一个G代码来取消。

格式中的I(R)值在圆柱切削时是不用的,在圆锥切削时才要用,这一点,我们可从图3-1中清楚看到。

(a)(b)图3-1 轴向(圆柱或圆锥)切削循环指令G90(a)(b)图3-2 轴向(圆柱或圆锥)切削循环指令G90应用如图3-2(a)所示, 加工余量(Z向)为:30mm,如果进刀量为5mm(直径测量),就分3次循环。

设循环起点为A点(50,52)。

C_实验-记事本(带源码)

C_实验-记事本(带源码)

记事本实验报告一、实验目的创建一个Windows窗体应用程序,实现记事本的基本功能,具体包括新建文件、打开文件、保存文件、查找等功能。

该实验的目的是掌握:(一)窗体程序的开发(二)常用控件的使用(三)常用事件的处理(四)对话框的设计和使用(五)文件访问的基本方法二、实验内容(一)主窗口Form1图1 主窗口主窗口界面如图1所示,功能包括基本编辑操作、主菜单和其它快捷键功能。

1、编辑功能用文本框实现。

2、窗口标题与文件名相一致。

未打开文件时为“无标题”,打开文件(另存为)后为文件名。

3、支持菜单的热键和快捷键。

二者的区别是前者是激活菜单且显示出该菜单项时有效,后者在任何时候有效。

4、实现新建、打开、保存和查找功能。

5、支持F3(查找下一个)。

表1 Form1控件列表using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.IO;namespace WindowsFormsApplication1{public partial class Form1 : Form{public Form2 fm2 = null;public string searchText = "";public Form1(){InitializeComponent();}private void saveFile(){if (textBox1.Text.Length > 0 && textBox1.Modified) {if (MessageBox.Show("想保存文件吗?", "记事本",MessageBoxButtons.YesNoCancel,MessageBoxIcon.Warning) == DialogResult.Yes){SaveFileDialog d = new SaveFileDialog();d.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";if (d.ShowDialog() == DialogResult.OK){FileStream fs = File.OpenWrite(d.FileName);StreamWriter sr = new StreamWriter(fs);sr.Write(textBox1.Text);sr.Flush();fs.Close();}}}}private void文件NToolStripMenuItem_Click(object sender, EventArgs e) {saveFile();textBox1.Text = "";Text = "无标题 - 记事本";}private void OpenFile(){OpenFileDialog d = new OpenFileDialog();d.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";if (d.ShowDialog() == DialogResult.OK){FileStream fs = File.OpenRead(d.FileName);StreamReader sr = new StreamReader(fs);string s;string s1 = "";while ((s = sr.ReadLine()) != null){s1 += s;}textBox1.Text = s1;string fname = d.FileName.Substring(stIndexOf("\\") + 1);Text = fname + " - 记事本";}}private void打开OToolStripMenuItem_Click(object sender, EventArgs e) {saveFile();OpenFile();}private void保存SToolStripMenuItem_Click(object sender, EventArgs e) {saveFile();}private void查找FToolStripMenuItem_Click(object sender, EventArgs e) {if (fm2 == null){fm2 = new Form2();fm2.fm1 = this;Form2.textBox2 = textBox1;fm2.Show();}elsefm2.Activate();}private void textBox1_KeyDown(object sender, KeyEventArgs e){if (e.KeyCode == Keys.A && e.Control && !e.Shift && !e.Alt){textBox1.SelectAll();e.Handled = true;}else if (e.KeyCode == Keys.F3 && !e.Control && !e.Shift && !e.Alt) {Form2.findNext();}}}}(二)查找对话框图2 查找对话框查找对话框的界面(图2)与记事本的相同。

python实现简易的记事本

python实现简易的记事本

python实现简易的记事本运⾏效果完整代码from tkinter import *from tkinter.filedialog import *from tkinter.messagebox import *import osfilename=''def author():showinfo('⼤道⾄简','简易记事本第⼀版')def power():showinfo('版权信息','本公司保留版权信息,不可以把本软件⽤于商业⽬的!')def myopen():global filenamefilename=askopenfilename(defaultextension='.txt')if filename=='':filename=Noneelse:root.title('简易记事本'+os.path.basename(filename))textPad.delete(1.0,END)f=open(filename,'r')textPad.insert(1.0,f.read())f.close()def new():global root,filename,textPadroot.title('未命名⽂件')filename=NonetextPad.delete(1.0,END)def save():global filenametry:f=open(filename,'w')msg=textPad.get(1.0,'end')f.write(msg)f.close()except:saveas()def saveas():f=asksaveasfile(initialfile='未命名.txt',defaultextension='.txt')global filenamefilename=ffh=open(f,'w')msg=textPad.get(1.0,END)fh.write(msg)fh.close()root.title('简易记事本'+os.path.basename(f))def cut():global textPadtextPad.event_generate('<<Cut>>')def copy():global textPadtextPad.event_generate('<<Copy>>')def paste():global textPadtextPad.event_generate('<<Paste>>')def undo():global textPadtextPad.event_generate('<<Undo>>')def redo():global textPadtextPad.event_generate('<<Redo>>')def select_all():global textPadtextPad.tag_add('sel','1.0','end')def find():global roott=Toplevel(root)t.title('查找')t.geometry('260x60+200+250')t.transient(root)Label(t,text='查找:').grid(row=0,column=0,sticky='e')v=StringVar()e=Entry(t,width=20,textvariable=v)e.grid(row=0,column=1,padx=2,pady=2,sticky='we')e.focus_set()c=IntVar()Checkbutton(t,text='不区分⼤⼩写',variabel=c).grid(row=1,column=1,sticky='e')Button(t,text='查找所有',command=lambda :search(v.get(),c.get(),textPad,t,e)).grid(row=0, column=2,sticky='e'+'w',padx=2,pady=2)def close_search():textPad.tag_remove('match','1.0',END)t.destroy()t.protocol('WM_DELETE_WINDOW',close_search)#def search(needle,cssnstv,textPad,t,e):textPad.tag_remove('match','1.0',END)count=0if needle:pos='1.0'while True:pos=textPad.search(needle,pos,nocase=cssnstv,stopindex=END)if not pos:breaklastpos=pos+str(len(needle))textPad.tag_add('match',pos,lastpos)count+=1pos=lastpostextPad.tag_config('match',foreground='yellow',background='green')e.focus_set()t.title(str(count)+'个被匹配')def popup(event):global editmenu_popup(event.x_root,event.y_root)root=Tk()root.title('简易记事本第⼀版')root.geometry('300x300+100+100')#geometry(wxh+xoffset+yoffset)menubar=Menu(root)#制作菜单实例,依附于⽗窗⼝root上⾯filemenu=Menu(menubar)#制作⽂件菜单项,依附于menubar菜单上⾯menubar.add_cascade(label='⽂件',menu=filemenu)#增加分层菜单filemenu.add_command(label='新建',accelerator='Ctrl+N',command=new)filemenu.add_command(label='打开',accelerator='Ctrl+O',command=myopen) filemenu.add_command(label='保存',accelerator='Ctrl+S',command=save)filemenu.add_command(label='另存为',accelerator='Ctrl+Alt+S',command=saveas) editmenu=Menu(menubar)#制作编辑菜单项,依附于menubar菜单上⾯menubar.add_cascade(label='编辑',menu=editmenu)editmenu.add_command(label='撤销',accelerator='Ctrl+Z',command=undo)editmenu.add_command(label='重做',accelerator='Ctrl+Y',command=redo)editmenu.add_command(label='剪切',accelerator='Ctrl+X',command=cut)editmenu.add_command(label='复制',accelerator='Ctrl+C',command=copy)editmenu.add_command(label='粘贴',accelerator='Ctrl+V',command=paste)editmenu.add_separator()editmenu.add_command(label='查找',accelerator='Ctrl+F',command=find)editmenu.add_command(label='全选',accelerator='Ctrl+A',command=select_all) aboutmenu=Menu(menubar)#制作关于菜单项,依附于menubar菜单上⾯menubar.add_cascade(label='关于',menu=aboutmenu)#增加分层菜单aboutmenu.add_command(label='作者',command=author)aboutmenu.add_command(label='版权',command=power)root.config(menu=menubar)shortcutbar=Frame(root,height=25,bg='light sea green')shortcutbar.pack(expand=NO,fill=X)Inlabel=Label(root,width=2,bg='antique white')Inlabel.pack(side=LEFT,anchor='nw',fill=Y)textPad=Text(root,undo=True)textPad.pack(expand=YES,fill=BOTH)scroll=Scrollbar(textPad)textPad.config(yscrollcommand=scroll.set)scroll.config(command=textPad.yview)scroll.pack(side=RIGHT,fill=Y)textPad.bind('<Control-N>',new)textPad.bind('<Control-n>',new)textPad.bind('<Control-O>',myopen)textPad.bind('<Control-o>',myopen)textPad.bind('<Control-S>',save)textPad.bind('<Control-s>',save)textPad.bind('<Control-A>',select_all)textPad.bind('<Control-a>',select_all)textPad.bind('<Control-f>',find)textPad.bind('<Control-F>',find)textPad.bind('<Control-3>',popup)root.mainloop()以上就是python 实现简易的记事本的详细内容,更多关于python 实现记事本的资料请关注其它相关⽂章!。

实验三利用记事本等编制程序,.

实验三利用记事本等编制程序,.

实验三:利用记事本等编制程序,将程序导入并利用模拟功能进行轨迹检验一、使用记事本或写字板,编写简单零件的数控车床加工程序对几何形状简单、单一的切削路线,如:外径、内径、端面的切削,若加工余量较大,刀具常常要反复地执行相同的动作,才能达到工件要求的尺寸。

要完成上述加工,在一个程序中就要写入很多的程序段,为了简化程序,减少程序所占内存,数控机床设有各种固定循环指令,只需用一个指令,一个程序段,便可完成一次乃至多次重复的切削动作。

轴向(圆柱或圆锥)切削循环指令(G90)如图3-1所示,刀具从循环起点开始按矩形循环,其加工顺序按1,2,3,4进行,最后又回到循环起点。

图中虚线表示按R快速移动,点划线表示按F指定的工件进给速度移动。

图3-1(a)和(b)分别为圆柱或圆锥切削循环示意图。

(1)圆柱面切削循环指令格式:G90 X(U)- Z(W)- F-;(2)圆锥面切削循环指令格式:G90 X(U)- Z(W)- I- F-;功能:进行外圆及内孔直线加工和锥面加工循环,可以简化编程。

其中:X、Z为切削终点坐标;U、W为切削终点相对于循环起点坐标值的增量;I为工件加工锥面大小端直径差的1/2,当锥面的起点坐标大于终点坐标时为正,反之为负;F为切削进给速度。

注意事项如下。

(1)使用循环切削指令,刀具必须先定位至循环起点,再执行循环切削指令,且完成一循环切削后,刀具仍回到此循环起点。

(2)G90是模态指令。

一旦规定,以下程序段一直有效,在完成固定切削循环后,用另一个G代码来取消。

格式中的I(R)值在圆柱切削时是不用的,在圆锥切削时才要用,这一点,我们可从图3-1中清楚看到。

(a)(b)图3-1 轴向(圆柱或圆锥)切削循环指令G90(a)(b)图3-2 轴向(圆柱或圆锥)切削循环指令G90应用如图3-2(a)所示, 加工余量(Z向)为:30mm,如果进刀量为5mm(直径测量),就分3次循环。

设循环起点为A点(50,52)。

编写一个记事本程序-要求:-用图形用户界面实现。-能实现编辑、保存、另存为、查找替换等功能。

编写一个记事本程序-要求:-用图形用户界面实现。-能实现编辑、保存、另存为、查找替换等功能。

编写一个记事本程序-要求:-用图形用户界面实现。

-能实现编辑、保存、另存为、查找替换等功能。

import java.io.*;import java.util.Calendar;import java.awt.*;import java.awt.event.*;import javax.swing.*;public class NoteBook extends JFrame implementsActionListener,ItemListener,WindowListener,MouseListener{ Container c = this.getContentPane();JMenuBar jmb = new JMenuBar();JColorChooser jcc = new JColorChooser();JMenu jm1 = new JMenu("文件(F)");JMenu jm2 = new JMenu("编辑(E)");JMenu jm3 = new JMenu("格式(O)");JMenu jm4 = new JMenu("查看(V)");JMenu jm5 = new JMenu("帮助(H)");JMenuItem jmi1 = new JMenuItem("新建(N)");JMenuItem jmi2 = new JMenuItem("打开(O)");JMenuItem jmi3 = new JMenuItem("保存(S)");JMenuItem jmi4 = new JMenuItem("退出(X)");JMenuItem jmi5 = new JMenuItem("撤消(U)");JMenuItem jmi6 = new JMenuItem("复制(C)");JMenuItem jmi7 = new JMenuItem("粘贴(P)");JMenuItem jmi8 = new JMenuItem("剪切(T)");JMenuItem jmi12 = new JMenuItem("日期和时间");JMenuItem jmi9 =m new JMenuItem("字体(E)");JCheckBoxMenuItem jcbmi = new JCheckBoxMenuItem("自动换行(W)"); JMenuItem jmi10 = new JMenuItem("删除(S)");JMenuItem jmi11 = new JMenuItem("背景颜色(H)");JTextArea jta = new JTextArea(15,15);JScrollPane jsp = new JScrollPane(jta);//PupolMenu pm = new Pupolmenu();NoteBook(){this.addWindowListener(this);c.setLayout(new BorderLayout());c.add(jmb,BorderLayout.NORTH);this.setTitle("新建文本文档");jmb.add(jm1);jm1.setMnemonic('f');jm1.addActionListener(this);jmb.add(jm2);jm2.setMnemonic('e');jmb.add(jm3);jm3.setMnemonic('o');jmb.add(jm4);this.setVisible(true);}public void actionPerformed(ActionEvent e){ if(e.getSource()==jmi1){jta.setText("");this.setTitle("无标题- 记事本");}if(e.getSource()==jmi2){File f1;JFileChooser jfc1 = new JFileChooser();int num1 = jfc1.showOpenDialog(this);if(num1==JFileChooser.APPROVE_OPTION){ try{f1 = jfc1.getSelectedFile();this.setTitle(f1.getName());FileReader fr = new FileReader(f1); BufferedReader br = new BufferedReader(fr); String str;while((str = br.readLine())!=null){jta.setText(str);}fr.close();br.close();}catch(FileNotFoundException e1){e1.printStackTrace();}catch(IOException e2){e2.printStackTrace();}}}if(e.getSource()==jmi3){File f2 = null;JFileChooser jfc2 = new JFileChooser();int num2 = jfc2.showSaveDialog(this);if(num2==JFileChooser.APPROVE_OPTION){ f2=jfc2.getSelectedFile();this.setTitle(f2.getName());try{FileWriter fw = new FileWriter(f2); BufferedWriter bw = new BufferedWriter(fw); bw.write(jta.getText());bw.close();fw.close();}catch(IOException e2){e2.printStackTrace();}}if(e.getSource()==jmi4){int a = JOptionPane.showConfirmDialog(this,"文件已被改变,是否要保存?","提示",JOptionPane.YES_NO_CANCEL_OPTION);if(a==1){this.dispose();}else if(a==0){File f2 = null;JFileChooser jfc2 = new JFileChooser();int num2 = jfc2.showSaveDialog(this);if(num2==JFileChooser.APPROVE_OPTION){f2=jfc2.getSelectedFile();this.setTitle(f2.getName());try{FileWriter fw = new FileWriter(f2);BufferedWriter bw = new BufferedWriter(fw);bw.write(jta.getText());bw.close();fw.close();}catch(IOException e2){e2.printStackTrace();}this.dispose();}}}if(e.getSource()==jmi12){Calendar c1 =Calendar.getInstance();int y = c1.get(Calendar.YEAR);int m = c1.get(Calendar.MONTH);int d = c1.get(Calendar.DATE);int h = c1.get(Calendar.HOUR);int m1 = c1.get(Calendar.MINUTE);int m2 = m+1;jta.setText(y+"年"+m2+"月"+d+"日"+h+":"+m1);}if(e.getSource()==jmi11){Color ccc = JColorChooser.showDialog(this,"color",Color.BLACK); jta.setSelectedTextColor(ccc);jta.setBackground(ccc);}if(e.getSource()==jmi10){jta.replaceRange("",jta.getSelectionStart(),jta.getSelectionEnd()); }mHelp = new JMenu("帮助(H)");mHelp.setMnemonic(KeyEvent.VK_H);mHelp.add(new JMenuItem("帮助主题"));mHelp.addSeparator();mHelp.add(new JMenuItem("关于计算器"));mPaste.setEnabled(true);} else if(s.equals("粘贴(P)")){ tResult.setText(copyBoard.toString());} else if(s.equals("CE")){//如果是CE则清除文本框tResult.setText("0.");} else if(s.equals("Backspace")){//如果是backspace则删除一个字符。

java编程-记事本-全部功能都实现

java编程-记事本-全部功能都实现

两个放到同个包中,一起运行1.记事本.javaimport ;public class记事本 {public static void main(String args[]){W indow window1=new Window();w indow1.setTitle("记事本");w indow1.setVisible(true);}}2.Window.javaimport javax.swing.*;importimport java.io.*;importimport ;import ;import ;import ;importimportimport java.awt.*;importimport java.util.*;importimport ;import ;importimportimport ;import ;importpublic class Window extends JFrame implements ActionListener{ JMenuBar menubar;JMenu menu,menu1,menu2,itemLine,menu3,menu4;JSplitPane splitPane;JMenuItem itemNew,itemOpen,itemSave,itemSaveAs,itemPrint,itemExit;JMenuItem itemCopy,itemCut,itemPaste,itemDelete;JMenuItem itemFont,line1,line2,itemhelp,itemabout;JTextArea text,text1;JLabel lblStatus;JTextField field;KeyHandler kHandler=new KeyHandler();JPopupMenu popupMenu;JToolBar statusBar;JCheckBoxMenuItem itemstate;Window(){init();intGUI();setBounds(500,150,500,500);setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);}void intGUI(){text=new JTextArea();add(new JScrollPane(text),BorderLayout.CENTER);text.addKeyListener(kHandler);lblStatus=new JLabel("未修改");}void init(){ //建立一个菜单menubar=new JMenuBar(); //建立文件菜单项menu=new JMenu("文件(F)");menubar.add(menu);setJMenuBar(menubar);itemNew=new JMenuItem("新建");itemOpen=new JMenuItem("打开");itemSave=new JMenuItem("保存");itemSaveAs=new JMenuItem("另存为");itemPrint=new JMenuItem("打印 ");itemExit=new JMenuItem("退出");menu.add(itemNew);menu.add(itemOpen);menu.add(itemSave);menu.add(itemSaveAs);menu.add(itemPrint);menu.add(itemExit);itemNew.addActionListener(this);itemNew.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,InputEvent.CTRL_MASK) );itemOpen.addActionListener(this);itemOpen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,InputEvent.CTRL_MASK ));itemSave.addActionListener(this);itemSave.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,InputEvent.CTRL_MASK ));itemSaveAs.addActionListener(this);itemPrint.addActionListener(this);itemPrint.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P,InputEvent.CTRL_MAS K));itemExit.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) {if(lblStatus.getText().equals("已修改")){int confirm=JOptionPane.showConfirmDialog(null, "文件已修改,要保存吗?");if(confirm==JOptionPane.OK_OPTION)save();else if(confirm==JOptionPane.CANCEL_OPTION)return;else if(confirm==JOptionPane.CLOSED_OPTION)return;}System.exit(0);}});itemExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E,InputEvent.CTRL_MASK ));menu1=new JMenu("编辑(E)"); //建立编辑菜单项menubar.add(menu1);setJMenuBar(menubar);itemCopy=new JMenuItem("复制");itemCut=new JMenuItem("剪切");itemPaste=new JMenuItem("粘贴");itemDelete=new JMenuItem("删除");menu1.add(itemCopy);menu1.add(itemCut);menu1.add(itemPaste);menu1.add(itemDelete);itemCopy.addActionListener(this);itemCopy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,InputEvent.CTRL_MASK ));itemCut.addActionListener(this);itemCut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,InputEvent.CTRL_MASK) );itemPaste.addActionListener(this);itemPaste.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,InputEvent.CTRL_MAS K));itemDelete.addActionListener(this);itemDelete.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE,0));menu2=new JMenu("格式(O)"); //建立格式菜单项menubar.add(menu2);setJMenuBar(menubar);itemLine=new JMenu("自动换行"); //建立二级菜单项line1=new JMenuItem("选择自动换行");line2=new JMenuItem("取消自动换行");itemLine.add(line1);itemLine.add(line2);menu2.add(itemLine);line1.addActionListener(this);line2.addActionListener(this);itemFont=new JMenuItem("字体");menu2.add(itemFont);itemFont.addActionListener(this);menu3=new JMenu("查看(V)"); //建立查看菜单项menubar.add(menu3);setJMenuBar(menubar);itemstate=new JCheckBoxMenuItem("状态栏"); //设置选勾菜单项menu3.add(itemstate);itemstate.addActionListener(this);menu4=new JMenu("帮助(H)"); //建立帮助菜单项menubar.add(menu4);setJMenuBar(menubar);itemhelp=new JMenuItem("查看帮助");menu4.add(itemhelp);itemhelp.addActionListener(this);itemabout=new JMenuItem("关于记事本");menu4.add(itemabout);itemabout.addActionListener(this);}public void actionPerformed(ActionEvent e){ //选择if(e.getSource()==itemCopy)text.copy();else if(e.getSource()==itemCut)text.cut();else if(e.getSource()==itemPaste)text.paste();else if(e.getSource()==itemNew)inew();else if(e.getSource()==itemSave)save();else if(e.getSource()==itemOpen)open();else if(e.getSource()==itemSaveAs)saveas();else if(e.getSource()==itemPrint)print();else if(e.getSource()==itemDelete)delete();else if(e.getSource()==line1)text.setLineWrap(true); //激活自动换行功能else if(e.getSource()==line2)text.setLineWrap(false);else if(e.getSource()==itemFont)font();else if(e.getSource()==itemstate){if(itemstate.getState())state();elsestatusBar.setVisible(false); //状态栏不可见}else if(e.getSource()==itemhelp)itemhelp();else if(e.getSource()==itemabout)itemabout();}void itemhelp(){String message = "1.记事本软件界面很简洁,使用方法简单,但是也仅拥有着基本文字编辑的功能。

ActionScript编程 综合实例:简单记事本程序

ActionScript编程 综合实例:简单记事本程序

ActionScript编程综合实例:简单记事本程序Windows操作系统自带有记事本程序,用户可以在记事本中输入文字,并可设置这些文字的字体、大小、颜色等属性。

其实,在Flash 中通过ActionScript代码也可以制作简单地记事本程序,如图19-1所示。

图19-1 简单记事本程序制作过程:(1)新建550×400像素的空白文档,将背景素材图像导入到舞台,并将ComboBox 和ColorPicker 组件拖入到【库】面板中,如图19-2所示。

图19-2 拖入组件(2)在舞台的下面绘制两个大小相近的圆角矩形,并设置其Alpha 值分别为“60%”和“50%”,如图19-3所示。

图19-3 绘制圆角矩形(3)在相同文件夹中新建名称为Text 的ActionScript 文件,并在该文件中使用import 语句导入所需的类,以及创建包、Text 类和Text()主函数,如下所示。

package {import flash.display.Sprite; import flash.text.TextField; importflash.text.TextFieldAutoSize;import flash.text.TextFormat; import flash.text.TextFieldType; import boBox; import flash.events.Event; import fl.controls.ColorPicker;public class Text extends Sprite {var content_txt:TextField; //用于显示文本内容的文本字段var color_txt:TextField; //用于显示颜色值的文本字段public function Text() { //主函数体 } } }(4)创建名称为createTitle 的函数,该函数创建一个用于显示标题的文本字段,并为其定义文本样式,如下所示。

Python基于Tkinter实现的记事本实例

Python基于Tkinter实现的记事本实例
这篇文章主要给大家介绍了关于pyqt5如何让qmessagebox按钮显示中文的相关资料文中通过示例代码介绍的非常详细对大家学习或者使用pyqt5具有一定的参考学习价值需要的朋友们下面来一起学习学习吧
Python基于 Tkinter实现的记事本实例
本文实例讲述了Python基于Tkinter实ห้องสมุดไป่ตู้的记事本。分享给大家供大家参考。具体如下:
t = te.get('0.0','10.0') f = open(mi.get(),'w') f.write(t) Button(text = 'Save' , command = save).pack(side = RIGHT) Button(text = 'Exit' , command = root.quit).pack(side = RIGHT) mainloop()
from Tkinter import * root = Tk('Simple Editor') mi=StringVar() Label(text='Please input something you like~' ).pack() te = Text(height = 30,width =100) te.pack() Label(text=' File name ').pack(side = LEFT) Entry(textvariable = mi).pack(side = LEFT) mi.set('*.txt') def save():
希望本文所述对大家的Python程序设计有所帮助。

用记事本编写整人小程序

用记事本编写整人小程序

不需要任何编程基础,不需要任何编程软件,只需使用电脑里自带的记事本软件就可以轻松编写出整人的小程序,甚至是病毒。

首先,单击右键,新建一个文本文档,输入:msgbox"你是猪!"然后,点击文件->另存为->保存类型:所有文件->文件名xxxx.vbs,名字随便起,但一定要记得把后缀名改为 .vbs。

然后打开刚保存的xxxx.vbs哈哈,很好玩吧,双引号里的内容”你是猪!”可以随意更改,但双引号一定要用英文输入法来写。

嗯,下面正式开始整人。

按照前面说的,在记事本上输入如下图,并保存为55.vbs。

其中wscript.Sleep 500为停留500毫秒,可随便更改下面这段代码就是一个启动关机程序的东东,300这个数是指300秒倒计时,这个数字也可以随便改,这段代码也可以独立保存出来作为一个关机程序dim WSHshellset WSHshell = wscript.createobject("wscript.shell")WSHshell.Run "cmd.exe /c shutdown -s -t 300"打开这个文件,如果你点击“是”,你就会进入一个死循环中,就是不断地弹出对话框。

解决方法是按下Alt+Ctrl+Delete键,选择“进程”,把wscript.exe结束掉。

如果点击“否”,则进入关机倒计时,解决方法是点击“开始”->“运行”,在对话框里输入shutdown -a ,再点击“确定”即可。

最后嘛,把这文件创建桌面快捷方式,然后把图标换了,换成QQ什么的,你懂的,呵呵。

当然,这种VBS编程还有很多好玩的地方,比如病毒,我也收藏有几个,由于我是一等一的良好市民,就不写上来了。

最后再送上一个程序:dim adoa=inputbox("输入123,否则关机。

")if a="123" thenmsgbox" 很遗憾,你中招了,这是整人程序,你就等着关机吧"WSHshell.Run "cmd.exe /c shutdown -s -t 300"wscript.sleep 1000exit doelsemsgbox"乖点,输入123"end ifloop。

C#编写一个简单记事本功能

C#编写一个简单记事本功能

C#编写⼀个简单记事本功能本⽂实例为⼤家分享了C#编写记事本的具体代码,供⼤家参考,具体内容如下using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace Notepad{public partial class frmNotepad : Form{//****************************************/*布尔变量b⽤于判断⽂件是新建的还是从磁盘打开的 true 表⽰从磁盘打开,false表⽰⽂件是新建的,默认值为false*/bool b = false;/*布尔变量s⽤于判断⽂件是否被保存 true 表⽰已经被保存,false表⽰未被保存,默认值为true*/bool s = true;//***********************************public frmNotepad(){InitializeComponent();richTextBox1.Text = "";}//***********************************************// 多格式⽂本框的TextChanged事件代码//************************************************private void richTextBox1_TextChanged(object sender, EventArgs e){//⽂本框被修改后,设置s为false,表⽰⽂件未保存s = false;}//*****************************************// 【⽂件】菜单各菜单项的单击代码//*******************************************//*****************************************// 【新建】菜单代码//*********************************************private void 新建NToolStripMenuItem_Click(object sender, EventArgs e){//判断当前⽂件是否是从磁盘打开,或者新建时⽂档不为空,并且⽂件未被保存if(b == true || richTextBox1.Text.Trim() != ""){//若⽂件未保存if(s == false){string result;result = MessageBox.Show("⽂件尚未保存,是否保存?", "保存⽂件", MessageBoxButtons.YesNoCancel).ToString(); switch(result){case"Yes"://若⽂件是从磁盘打开的if(b == true){//按⽂件打开的路径保存⽂件richTextBox1.SaveFile(sdlgNotepad.FileName);}else if(sdlgNotepad.ShowDialog()==DialogResult.OK){richTextBox1.SaveFile(sdlgNotepad.FileName);}s = true;richTextBox1.Text = "";break;case"No":b = false;richTextBox1.Text = "";break;}}}}//*******************************************// 【保存】菜单代码//********************************************private void 保存SToolStripMenuItem_Click(object sender, EventArgs e){//若⽂件从磁盘打开并且修改了其中内容if(b == true && richTextBox1.Modified == true){richTextBox1.SaveFile(odlgNotepad.FileName);s = true;}else if(b == false && richTextBox1.Text.Trim() != "" &&sdlgNotepad.ShowDialog() == DialogResult.OK){//保存⽂件richTextBox1.SaveFile(sdlgNotepad.FileName);s = true;b = true;odlgNotepad.FileName = sdlgNotepad.FileName;}}//**********************************************// 【打开】菜单代码//************************************************private void 打开OToolStripMenuItem_Click(object sender, EventArgs e){//判断当前⽂件是否是从磁盘打开,或者新建时⽂档不为空,并且⽂件未被保存try{if (b == true || richTextBox1.Text.Trim() != ""){if (s == false){string result;result = MessageBox.Show("⽂件尚未保存,是否保存?", "保存⽂件", MessageBoxButtons.YesNoCancel).ToString(); switch (result){case "Yes"://若⽂件是从磁盘打开的if (b == true){//按⽂件打开的路径保存⽂件richTextBox1.SaveFile(sdlgNotepad.FileName);}else if (sdlgNotepad.ShowDialog() == DialogResult.OK){richTextBox1.SaveFile(sdlgNotepad.FileName);}s = true;richTextBox1.Text = "";break;case "No":b = false;richTextBox1.Text = "";break;}}}odlgNotepad.RestoreDirectory = true;if ((odlgNotepad.ShowDialog() == DialogResult.OK) && odlgNotepad.FileName != ""){//打开⽂件richTextBox1.LoadFile(odlgNotepad.FileName);b = true;}s = true;}catch(Exception ex){}}//************************************// 【另存为】菜单代码//*****************************************private void 另存为AToolStripMenuItem_Click(object sender, EventArgs e) {if(sdlgNotepad.ShowDialog() == DialogResult.OK){richTextBox1.SaveFile(sdlgNotepad.FileName);s = true;}}//***************************************// 【退出】菜单代码//******************************************private void 退出XToolStripMenuItem_Click(object sender, EventArgs e) {//结束程序运⾏Application.Exit();}//************************************// 【编辑】菜单各菜单项的单击代码//*********************************************// 【撤销】菜单代码private void 撤消UToolStripMenuItem_Click(object sender, EventArgs e) {//撤销操作richTextBox1.Undo();}// 【复制】菜单代码private void 复制CToolStripMenuItem_Click(object sender, EventArgs e) {//复制richTextBox1.Copy();}// 【剪切】菜单代码private void 剪切TToolStripMenuItem_Click(object sender, EventArgs e) {//剪切richTextBox1.Cut();}// 【粘贴】菜单代码private void 粘贴PToolStripMenuItem_Click(object sender, EventArgs e) {//粘贴richTextBox1.Paste();}// 【全选】菜单代码private void 全选AToolStripMenuItem_Click(object sender, EventArgs e) {//全选richTextBox1.SelectAll();}//*************************************// 【格式】菜单代码//***************************************private void ⼯具TToolStripMenuItem_Click(object sender, EventArgs e) {}// 【⾃动换⾏】菜单代码private void ⾃定义CToolStripMenuItem_Click(object sender, EventArgs e) {if(⾃定义CToolStripMenuItem.Checked == false)//选中⾃动换⾏⾃定义CToolStripMenuItem.Checked = true;//设置为⾃动换⾏richTextBox1.WordWrap = true;}else{//未选中⾃动换⾏⾃定义CToolStripMenuItem.Checked = false;//设置为不⾃动换⾏richTextBox1.WordWrap = false;}}// 【字体】菜单代码private void 选项OToolStripMenuItem_Click(object sender, EventArgs e){fdlgNotepad.ShowColor = true;if(fdlgNotepad.ShowDialog() == DialogResult.OK){richTextBox1.SelectionColor = fdlgNotepad.Color;richTextBox1.SelectionFont = fdlgNotepad.Font;}}//************************************// 【帮助】菜单代码//************************************// 【关于】菜单代码private void 关于AToolStripMenuItem_Click(object sender, EventArgs e){MessageBox.Show("wky 编写", "关于\"记事本\"", MessageBoxButtons.OK);}//***************************************// 计时器控件的Tick事件代码//************************************private void tmrNotepad_Tick(object sender, EventArgs e){//获取系统当前时间,并显⽰在状态栏中tssLbl2.Text = System.DateTime.Now.ToString();}private void 粘贴PToolStripButton_Click(object sender, EventArgs e){richTextBox1.Paste();}}}以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。

简单记事本java源码实例

简单记事本java源码实例

简单记事本java源码实例本⽂实例讲述了简单记事本java实现代码。

分享给⼤家供⼤家参考。

具体如下:完整代码如下:复制代码代码如下:import java.awt.*;import java.io.*;import java.awt.datatransfer.*;import java.awt.event.*;public class Main extends Frame implements ActionListener {private static final long serialVersionUID = 1L;TextArea textArea = new TextArea();MenuBar menuBar = new MenuBar();Menu fileMenu = new Menu("File");MenuItem newItem = new MenuItem("New");MenuItem openItem = new MenuItem("Open");MenuItem saveItem = new MenuItem("Save");MenuItem saveAsItem = new MenuItem("Save As");MenuItem exitItem = new MenuItem("Exit");Menu editMenu = new Menu("Edit");MenuItem selectItem = new MenuItem("Select All");MenuItem copyItem = new MenuItem("Copy");MenuItem cutItem = new MenuItem("Cut");MenuItem pasteItem = new MenuItem("Paste");String fileName = null;Toolkit toolKit=Toolkit.getDefaultToolkit();Clipboard clipBoard=toolKit.getSystemClipboard();private FileDialog openFileDialog = new FileDialog(this,"Open File",FileDialog.LOAD);private FileDialog saveAsFileDialog = new FileDialog(this,"Save File As",FileDialog.SAVE); public Main(){setTitle("记事本程序-by Jackbase");setFont(new Font("Times New Roman",Font.PLAIN,12));setBackground(Color.white);setSize(400,300);fileMenu.add(newItem);fileMenu.add(openItem);fileMenu.addSeparator();fileMenu.add(saveItem);fileMenu.add(saveAsItem);fileMenu.addSeparator();fileMenu.add(exitItem);editMenu.add(selectItem);editMenu.addSeparator();editMenu.add(copyItem);editMenu.add(cutItem);editMenu.add(pasteItem);menuBar.add(fileMenu);menuBar.add(editMenu);setMenuBar(menuBar);add(textArea);addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){System.exit(0);}});newItem.addActionListener(this);openItem.addActionListener(this);saveItem.addActionListener(this);saveAsItem.addActionListener(this);exitItem.addActionListener(this);selectItem.addActionListener(this);copyItem.addActionListener(this);cutItem.addActionListener(this);pasteItem.addActionListener(this);}public void actionPerformed(ActionEvent e) { //监听事件Object eventSource = e.getSource();if(eventSource == newItem){textArea.setText("");}else if(eventSource == openItem){openFileDialog.show();fileName = openFileDialog.getDirectory()+openFileDialog.getFile();if(fileName != null)readFile(fileName);}else if (eventSource == saveItem){if(fileName != null)writeFile(fileName);}else if(eventSource == saveAsItem){saveAsFileDialog.show();fileName = saveAsFileDialog.getDirectory()+saveAsFileDialog.getFile();if (fileName!= null)writeFile(fileName);}else if(eventSource == selectItem){textArea.selectAll();}else if(eventSource == copyItem){String text=textArea.getSelectedText();StringSelection selection=new StringSelection(text);clipBoard.setContents(selection,null);}else if(eventSource == cutItem){String text=textArea.getSelectedText();StringSelection selection=new StringSelection(text);clipBoard.setContents(selection,null);textArea.replaceRange("",textArea.getSelectionStart(),textArea.getSelectionEnd()); }else if(eventSource == pasteItem){Transferable contents=clipBoard.getContents(this);if(contents==null) return;String text;text="";try{text=(String)contents.getTransferData(DataFlavor.stringFlavor);}catch(Exception exception){}textArea.replaceRange(text,textArea.getSelectionStart(),textArea.getSelectionEnd()); }else if(eventSource == exitItem){System.exit(0);}}public void readFile(String fileName){ //读取⽂件处理try{File file = new File(fileName);FileReader readIn = new FileReader(file);int size = (int)file.length();int charsRead = 0;char[] content = new char[size];while(readIn.ready())charsRead += readIn.read(content, charsRead, size - charsRead);readIn.close();textArea.setText(new String(content, 0, charsRead)); }catch(IOException e){System.out.println("Error opening file");}}public void writeFile(String fileName){ //写⼊⽂件处理 try{File file = new File (fileName);FileWriter writeOut = new FileWriter(file);writeOut.write(textArea.getText());writeOut.close();}catch(IOException e){System.out.println("Error writing file");}}@SuppressWarnings("deprecation")public static void main(String[] args){Frame frame = new Main(); //创建对象frame.show(); //是对象显⽰}}运⾏结果如下图所⽰:希望本⽂所述对⼤家的java程序设计有所帮助。

记事本的程序设计及代码示例

记事本的程序设计及代码示例

记事本的程序设计及代码示例记事本是一种常见的应用程序,用于记录和编辑文本内容。

在本文中,我们将探讨记事本的程序设计,并给出一个基于Python语言的代码示例。

一、程序设计思路在设计记事本程序时,我们需要考虑以下几个方面:1. 用户界面设计:记事本的用户界面应简洁直观,方便用户输入和编辑文本内容。

可以采用菜单栏、工具栏和文本区域等组件,让用户可以进行打开、保存、复制、粘贴、查找替换等操作。

2. 功能设计:记事本应具备基本的文本编辑功能,如插入、删除、复制、粘贴和撤销等。

此外,还可以添加其他高级功能,如自动保存、自动换行、字体调整以及批量替换等。

3. 文件操作:记事本需要支持文件的打开和保存功能。

用户可以通过打开功能选择要编辑的文本文件,保存功能可以将编辑的内容保存为文件。

同时,还可以支持文件拖拽和快捷键操作。

二、代码示例下面是一个基于Python语言的记事本代码示例:```pythonimport tkinter as tkfrom tkinter import filedialogwindow = ()window.title("记事本")# 创建文本区域text_area = tk.Text(window)text_area.pack()# 打开文件函数def open_file():file_path = filedialog.askopenfilename() if file_path:with open(file_path, 'r') as file:text_area.delete(1.0, tk.END)text_area.insert(tk.END, file.read()) # 保存文件函数def save_file():file_path = filedialog.asksaveasfilename() if file_path:with open(file_path, 'w') as file:file.write(text_area.get(1.0, tk.END))menu_bar = tk.Menu(window)window.config(menu=menu_bar)# 添加文件菜单file_menu = tk.Menu(menu_bar, tearoff=False)menu_bar.add_cascade(label="文件", menu=file_menu)file_menu.add_command(label="打开", command=open_file)file_menu.add_command(label="保存", command=save_file)file_menu.add_separator()file_menu.add_command(label="退出", command=window.quit)# 运行主窗口window.mainloop()```以上代码使用Python的tkinter库创建了一个简易的记事本应用程序。

C#实现简单记事本程序

C#实现简单记事本程序

C#实现简单记事本程序本⽂实例为⼤家分享了使⽤C#写出⼀个简单的记事本程序,供⼤家参考,具体内容如下编程语⾔: C#编程环境: Visual Studio 2013运⾏环境: .NET Framework 4.5预览:功能:标题栏显⽰⽂件标题菜单栏各类菜单命令⽂件- 新建- 打开- 保存- 另存为- 页⾯设置- 打印- 退出编辑 - 撤销- 剪切- 复制- 粘贴- 全选- 时间/⽇期格式 - ⾃动换⾏- 字体视图 - 状态栏- ⼯具栏- 全屏模式帮助- 开源许可- 查看帮助- 关于⼯具栏常⽤⼯具集合标签栏⽂件标签显⽰⼯作区编辑区状态栏显⽰⽂件状态⽂本状态(新建/已修改)字符个数光标坐标功能实现本程序有两个窗体,分别为Form1和AboutBox1所有⽂件如下:对于Form1:需要引⼊的类库:using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.IO;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;窗体及空间声明代码:private System.Windows.Forms.MenuStrip menuStrip1;private System.Windows.Forms.ToolStripMenuItem ⽂件ToolStripMenuItem;private System.Windows.Forms.ToolStripMenuItem 新建ToolStripMenuItem;private System.Windows.Forms.ToolStripMenuItem 打开ToolStripMenuItem;private System.Windows.Forms.ToolStripMenuItem 保存ToolStripMenuItem;private System.Windows.Forms.ToolStripMenuItem 另存为ToolStripMenuItem;private System.Windows.Forms.ToolStripMenuItem 编辑ToolStripMenuItem;private System.Windows.Forms.ToolStripMenuItem 格式ToolStripMenuItem;private System.Windows.Forms.ToolStripMenuItem 退出ToolStripMenuItem;private System.Windows.Forms.ToolStripMenuItem 关于ToolStripMenuItem;private System.Windows.Forms.TextBox editBox1;private System.Windows.Forms.ToolStripMenuItem 撤销ToolStripMenuItem;private System.Windows.Forms.ToolStripMenuItem 剪切ToolStripMenuItem;private System.Windows.Forms.ToolStripMenuItem 复制ToolStripMenuItem;private System.Windows.Forms.ToolStripMenuItem 粘贴ToolStripMenuItem;private System.Windows.Forms.ToolStripMenuItem 删除ToolStripMenuItem;private System.Windows.Forms.ToolStripMenuItem 全选AToolStripMenuItem;private System.Windows.Forms.ToolStripMenuItem ⽇期DToolStripMenuItem;private System.Windows.Forms.ToolStripMenuItem 格式ToolStripMenuItem1;private System.Windows.Forms.ToolStripMenuItem 字体ToolStripMenuItem;private System.Windows.Forms.ToolStripMenuItem 查看VToolStripMenuItem;private System.Windows.Forms.ToolStripMenuItem 状态栏ToolStripMenuItem;private System.Windows.Forms.StatusStrip statusStrip1;private System.Windows.Forms.SaveFileDialog saveFileDialog1;private System.Windows.Forms.ToolStripSeparator toolStripMenuItem1;private System.Windows.Forms.ToolStripSeparator toolStripMenuItem3;private System.Windows.Forms.ToolStripSeparator toolStripMenuItem4;private System.Windows.Forms.ToolStripMenuItem 页⾯设置UToolStripMenuItem;private System.Drawing.Printing.PrintDocument printDocument1;private System.Windows.Forms.PageSetupDialog pageSetupDialog1;private System.Windows.Forms.ToolStripMenuItem 打印PToolStripMenuItem;private System.Windows.Forms.PrintDialog printDialog1;private System.Windows.Forms.ToolStripMenuItem 查看帮助HToolStripMenuItem;private System.Windows.Forms.ToolStripSeparator toolStripMenuItem5;private System.Windows.Forms.ToolStripMenuItem ⾃动换⾏ToolStripMenuItem;private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1;public System.Windows.Forms.Timer timer1;private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel2;private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel3;private System.Windows.Forms.ToolStripMenuItem 全屏模式ToolStripMenuItem;private System.Windows.Forms.ToolStrip toolStrip1;private System.Windows.Forms.ToolStripButton newButton;private System.Windows.Forms.ToolStripButton openButton;private System.Windows.Forms.ToolStripButton saveButton;private System.Windows.Forms.ToolStripButton saveAsButton;private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;private System.Windows.Forms.ToolStripButton cutButton;private System.Windows.Forms.ToolStripButton copyButton;private System.Windows.Forms.ToolStripButton pasteButton;private System.Windows.Forms.ToolStripButton deleteButton;private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;private System.Windows.Forms.ToolStripButton timeButton;private System.Windows.Forms.ToolStripButton fullButton;private System.Windows.Forms.ToolStripButton textButton;private System.Windows.Forms.ToolStripMenuItem ⼯具栏ToolStripMenuItem;private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel4;private System.Windows.Forms.ToolStripMenuItem 开源许可OToolStripMenuItem;private System.Windows.Forms.TabControl tabControl1;private System.Windows.Forms.TabPage tabPage1;private System.Windows.Forms.TabPage tabPage2;private System.Windows.Forms.TextBox editBox2;1窗体载⼊:private void Form1_Load(object sender, EventArgs e){this.editBox1.ScrollBars = ScrollBars.Both;this.editBox2.ScrollBars = ScrollBars.Both;this.Text = textFileName + " - " + programeName;//显⽰⽂件名this.timer1.Start();editBox1.Focus();}⾸先进⾏⼀些固定变量声明:private string textFileName = "⽆标题";private string programeName = "Icey";private string filePath = "";private string asFilePath = "";private string selecteText = "";private string helpUrl = "https:///icey";private string openSourceUrl = "https:///mayuko2012/icey";private string wrongMessage = "你好像遇到了错误...";private string fileFormat = "⽂本⽂件(*.txt)|*.txt|Icey⽂件(*.ice)|*.ice|C++⽂件(*.cpp)|*.cpp|C⽂件(*.c)|*.c|所有⽂件(*.*)|(*.*)"; private string tabFileName1 = "⽆标题1 - Icey";private string tabFileName2 = "⽆标题2 - Icey";Boolean saveFileStatus1 = false;Boolean textChanged1 = false;Boolean saveFileStatus2 = false;Boolean textChanged2 = false;private void saveFile()//保存{if (!textFileName.Equals("")){SaveFileDialog saveFile = new SaveFileDialog();saveFile.Filter = fileFormat;saveFile.FileName = "*.txt";if (saveFile.ShowDialog() == DialogResult.OK){filePath = saveFile.FileName;StreamWriter sw = new StreamWriter(filePath, false, Encoding.Default);sw.Write((editBox1.Focused) ? editBox1.Text : editBox2.Text);sw.Close();if (editBox1.Focused){tabFileName1 = saveFile.FileName + " - " + programeName;saveFileStatus1 = true;}else if (editBox2.Focused){tabFileName2 = saveFile.FileName + " - " + programeName;saveFileStatus2 = true;}}}toolStripStatusLabel4.Text = "已保存";}另存为采⽤函数形式:private void saveAsFile()//另存为{SaveFileDialog saveAsFile = new SaveFileDialog();saveAsFile.Filter = fileFormat;saveAsFile.FileName = "*.txt";if (saveAsFile.ShowDialog() == DialogResult.OK){asFilePath = saveAsFile.FileName;StreamWriter sw = new StreamWriter(asFilePath, false, Encoding.Default);sw.WriteLine((editBox1.Focused) ? editBox1.Text : editBox2.Text);sw.Close();FileInfo fileInfo = new FileInfo(saveAsFile.FileName);textFileName = ;}toolStripStatusLabel4.Text = "已保存";}新建函数:private void newFile()//新建{if (editBox1.Focused){if (editBox1.Text != String.Empty && saveFileStatus1 == false && textChanged1 == true)//如果⽂本框不为空{DialogResult result = MessageBox.Show("是否将窗⼝1已编辑⽂件保存到 " + textFileName, wrongMessage, MessageBoxButtons.YesNoCancel, rmation); if (result == DialogResult.Yes){saveFile();Application.Exit();}else if (result == DialogResult.No){editBox1.Text = "";}}elseeditBox1.Text = "";}else if (editBox2.Focused){if (editBox2.Text != String.Empty && saveFileStatus2 == false && textChanged2 == true)//如果⽂本框不为空{DialogResult result = MessageBox.Show("是否将窗⼝2已编辑⽂件保存到 " + textFileName, wrongMessage, MessageBoxButtons.YesNoCancel, rmation); if (result == DialogResult.Yes){saveFile();Application.Exit();}else if (result == DialogResult.No){editBox2.Text = "";}}elseeditBox2.Text = "";}}打开⽂件函数:private void openFile()//打开OpenFileDialog openFile = new OpenFileDialog();openFile.Filter = fileFormat;if (openFile.ShowDialog() == DialogResult.OK){StreamReader sr = new StreamReader(openFile.FileName, Encoding.Default);if (editBox1.Focused){editBox1.Text = sr.ReadToEnd();}else if(editBox2.Focused){editBox2.Text = sr.ReadToEnd();}sr.Close();FileInfo fileInfo = new FileInfo(openFile.FileName);if (editBox1.Focused){tabFileName1 = + " - " + programeName;saveFileStatus1 = true;}else if (editBox2.Focused){tabFileName2 = + " - " + programeName;saveFileStatus2 = true;}textFileName = ;}}全屏模式函数:private void fullScreen()//全屏{if (全屏模式ToolStripMenuItem.Checked == false){this.WindowState = FormWindowState.Maximized;全屏模式ToolStripMenuItem.Checked = true;this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;}else{this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;this.WindowState = FormWindowState.Normal;全屏模式ToolStripMenuItem.Checked = false;}}退出菜单命令:private void 退出ToolStripMenuItem_Click(object sender, EventArgs e){if (editBox1.Text != String.Empty || saveFileStatus1 == false && textChanged1 == true){this.tabPage1.Show();this.editBox1.Focus();DialogResult result = MessageBox.Show("是否将窗⼝1已编辑⽂件保存到 " + textFileName, wrongMessage, MessageBoxButtons.YesNoCancel, rmation); if (result == DialogResult.Yes){saveFile();Application.Exit();}else if (result == DialogResult.No){Application.Exit();}}else if (editBox2.Text != String.Empty || saveFileStatus2 == false && textChanged2 == true){this.tabPage2.Show();this.editBox2.Focus();DialogResult result = MessageBox.Show("是否将窗⼝2已编辑⽂件保存到 " + textFileName, wrongMessage, MessageBoxButtons.YesNoCancel, rmation); if (result == DialogResult.Yes){saveFile();Application.Exit();}else if (result == DialogResult.No){Application.Exit();}}elseApplication.Exit();}Bool变量,⽤于判断TextBox是否发⽣变化:private void textBox1_TextChanged(object sender, EventArgs e){textChanged2 = true;toolStripStatusLabel4.Text = "已修改";}private void editBox2_TextChanged(object sender, EventArgs e)textChanged2 = true;toolStripStatusLabel4.Text = "已修改";}新建菜单命令:private void 新建ToolStripMenuItem_Click(object sender, EventArgs e){newFile();}打开菜单命令:private void 打开ToolStripMenuItem_Click(object sender, EventArgs e){openFile();}字体菜单命令:private void 字体ToolStripMenuItem_Click(object sender, EventArgs e){FontDialog fontDialog = new FontDialog();if (fontDialog.ShowDialog() == DialogResult.OK){if (editBox1.Focused){editBox1.Font = fontDialog.Font;}elseeditBox2.Font = fontDialog.Font;}}退出动作(当⽤户点击窗体右上⾓退出按钮时执⾏此操作):private void Form1_FormClosing(object sender, FormClosingEventArgs e){if (editBox1.Text != String.Empty && e.CloseReason == erClosing || saveFileStatus1 == false && textChanged1 == true)//如果⽂本框不为空&&触发关闭按钮事件{this.tabPage1.Show();this.editBox1.Focus();DialogResult result = MessageBox.Show("是否将窗体1已编辑⽂件保存到 " + textFileName, wrongMessage, MessageBoxButtons.YesNoCancel, rmation);if (result == DialogResult.Yes){saveFile();e.Cancel = false;}else if (result == DialogResult.No){e.Cancel = false;}else if (result == DialogResult.Cancel){e.Cancel = true;}}else if (editBox2.Text != String.Empty && e.CloseReason == erClosing || saveFileStatus2 == false && textChanged2 == true)//如果⽂本框不为空&&触发关闭按钮事件 {this.tabPage2.Show();this.editBox2.Focus();DialogResult result = MessageBox.Show("是否将窗⼝2已编辑⽂件保存到 " + textFileName, wrongMessage, MessageBoxButtons.YesNoCancel, rmation);if (result == DialogResult.Yes){saveFile();e.Cancel = false;}else if (result == DialogResult.No){e.Cancel = false;}else if (result == DialogResult.Cancel){e.Cancel = true;}}elseApplication.Exit();}状态栏命令(状态栏是否显⽰):private void 状态栏ToolStripMenuItem_Click(object sender, EventArgs e){if (状态栏ToolStripMenuItem.Checked == true){状态栏ToolStripMenuItem.Checked = false;statusStrip1.Visible = false;}else{状态栏ToolStripMenuItem.Checked = true;statusStrip1.Visible = true;}编辑命令:private void 编辑ToolStripMenuItem_Click(object sender, EventArgs e) {if ((editBox1.SelectedText.Equals(""))){剪切ToolStripMenuItem.Enabled = false;复制ToolStripMenuItem.Enabled = false;删除ToolStripMenuItem.Enabled = false;}else{剪切ToolStripMenuItem.Enabled = true;复制ToolStripMenuItem.Enabled = true;删除ToolStripMenuItem.Enabled = true;}}全选命令:private void 全选AToolStripMenuItem_Click(object sender, EventArgs e) {if (editBox1.Focused){this.editBox1.SelectAll();}elsethis.editBox2.SelectAll();}剪切复制粘贴删除命令:private void 剪切ToolStripMenuItem_Click(object sender, EventArgs e) {if (editBox1.Focused){selecteText = editBox1.SelectedText;this.editBox1.Cut();}else{selecteText = editBox2.SelectedText;this.editBox2.Cut();}}private void 撤销ToolStripMenuItem_Click(object sender, EventArgs e) {if (editBox1.Focused){this.editBox1.Undo();}elsethis.editBox2.Undo();}private void 复制ToolStripMenuItem_Click(object sender, EventArgs e) {if (editBox1.Focused){this.editBox1.Copy();}elsethis.editBox2.Copy();}private void 粘贴ToolStripMenuItem_Click(object sender, EventArgs e) {if (editBox1.Focused){this.editBox1.Paste();}elsethis.editBox2.Paste();}private void 删除ToolStripMenuItem_Click(object sender, EventArgs e) {if (editBox1.Focused){this.editBox1.SelectedText = "";}elsethis.editBox2.SelectedText = "";}保存命令:private void 保存ToolStripMenuItem_Click(object sender, EventArgs e) {saveFile();}private void 另存为ToolStripMenuItem_Click(object sender, EventArgs e){saveAsFile();}时间戳命令:private void ⽇期DToolStripMenuItem_Click(object sender, EventArgs e){if (editBox1.Focused){editBox1.AppendText(System.DateTime.Now.ToString());}elseeditBox2.AppendText(System.DateTime.Now.ToString());}页⾯设置命令:private void 页⾯设置UToolStripMenuItem_Click(object sender, EventArgs e){pageSetupDialog1.Document = printDocument1;this.pageSetupDialog1.AllowMargins = true;this.pageSetupDialog1.AllowOrientation = true;this.pageSetupDialog1.AllowPaper = true;this.pageSetupDialog1.AllowPrinter = true;this.pageSetupDialog1.Document = this.printDocument1;pageSetupDialog1.ShowDialog();}打印命令:private void 打印PToolStripMenuItem_Click(object sender, EventArgs e){this.printDialog1.Document = this.printDocument1;this.printDialog1.PrinterSettings = this.pageSetupDialog1.PrinterSettings;if (this.printDialog1.ShowDialog() == DialogResult.OK){try{this.printDocument1.Print();}catch (Exception ex){MessageBox.Show(ex.Message, wrongMessage, MessageBoxButtons.OK, MessageBoxIcon.Error);}}}查看帮助关于命令:private void 查看帮助HToolStripMenuItem_Click(object sender, EventArgs e){System.Diagnostics.Process.Start(helpUrl);}private void 关于ToolStripMenuItem_Click(object sender, EventArgs e){AboutBox1 about = new AboutBox1();about.StartPosition = FormStartPosition.CenterScreen;about.Show();about.Owner = this;//timer1.Stop();}⾃动换⾏命令:private void ⾃动换⾏ToolStripMenuItem_Click(object sender, EventArgs e){if (⾃动换⾏ToolStripMenuItem.Checked == true){editBox1.WordWrap = false;editBox2.WordWrap = false;⾃动换⾏ToolStripMenuItem.Checked = false;}else{editBox1.WordWrap = true;editBox2.WordWrap = true;⾃动换⾏ToolStripMenuItem.Checked = true;}}计时器(100 ms刷新频率):private void timer1_Tick(object sender, EventArgs e){toolStripStatusLabel1.Text = (editBox1.Focused) ? editBox1.Text.Length.ToString() + " 个字符" : editBox2.Text.Length.ToString() + " 个字符";int totalline = (editBox1.Focused) ? editBox1.GetLineFromCharIndex(editBox1.Text.Length) + 1 : editBox2.GetLineFromCharIndex(editBox2.Text.Length) + 1;//得到总⾏数int index = (editBox1.Focused) ? editBox1.GetFirstCharIndexOfCurrentLine() : editBox2.GetFirstCharIndexOfCurrentLine();//得到当前⾏第⼀个字符的索引int line = (editBox1.Focused) ? editBox1.GetLineFromCharIndex(index) + 1 : editBox2.GetLineFromCharIndex(index) + 1;//得到当前⾏的⾏号int col = (editBox1.Focused) ? editBox1.SelectionStart - index + 1 : editBox2.SelectionStart - index + 1;//.SelectionStart得到光标所在位置的索引 - 当前⾏第⼀个字符的索引 = 光标所在的列数 toolStripStatusLabel2.Text = "第" + line + "⾏,第" + col + "列";cutButton.Enabled = false;copyButton.Enabled = false;deleteButton.Enabled = false;}else{cutButton.Enabled = true;copyButton.Enabled = true;deleteButton.Enabled = true;}if (editBox1.Focused){editBox1.Focus();this.Text = tabFileName1;}else{editBox2.Focus();this.Text = tabFileName2;}if (editBox2.Focused){editBox2.Focus();this.Text = tabFileName2;}else{editBox1.Focus();this.Text = tabFileName1;}}⼯具栏命令(⼯具栏是否显⽰):private void ⼯具栏ToolStripMenuItem_Click(object sender, EventArgs e){if (⼯具栏ToolStripMenuItem.Checked == false){toolStrip1.Visible = true;⼯具栏ToolStripMenuItem.Checked = true;}else if(⼯具栏ToolStripMenuItem.Checked == true){toolStrip1.Visible = false;⼯具栏ToolStripMenuItem.Checked = false;}}开源许可命令:private void 开源许可OToolStripMenuItem_Click(object sender, EventArgs e) {System.Diagnostics.Process.Start(openSourceUrl);}⼯具栏的各个按钮:private void newButton_Click(object sender, EventArgs e){newFile();}private void openButton_Click(object sender, EventArgs e){openFile();}private void saveButton_Click(object sender, EventArgs e){saveFile();}private void saveAsButton_Click(object sender, EventArgs e){saveAsFile();}private void cutButton_Click(object sender, EventArgs e){if (editBox1.Focused){selecteText = editBox1.SelectedText;this.editBox1.Cut();}else{selecteText = editBox2.SelectedText;this.editBox2.Cut();}}private void copyButton_Click(object sender, EventArgs e){if (editBox1.Focused)this.editBox1.Copy();}elsethis.editBox2.Copy();}private void pasteButton_Click(object sender, EventArgs e) {if (editBox1.Focused){this.editBox1.Paste();}elsethis.editBox2.Paste();}private void deleteButton_Click(object sender, EventArgs e) {if (editBox1.Focused){this.editBox1.SelectedText = "";}elsethis.editBox2.SelectedText = "";}private void timeButton_Click(object sender, EventArgs e) {if (editBox1.Focused){editBox1.AppendText(System.DateTime.Now.ToString()); }elseeditBox2.AppendText(System.DateTime.Now.ToString()); }private void textButton_Click(object sender, EventArgs e) {FontDialog fontDialog = new FontDialog();if (fontDialog.ShowDialog() == DialogResult.OK){if (editBox1.Focused){editBox1.Font = fontDialog.Font;}elseeditBox2.Font = fontDialog.Font;}}private void fullButton_Click(object sender, EventArgs e) {fullScreen();}标签栏:private void tabPage1_Click(object sender, EventArgs e){editBox1.Focus();this.Text = tabPage1.Text;if (textChanged1 == false){toolStripStatusLabel4.Text = "新建";}}private void tabPage2_Click(object sender, EventArgs e) {editBox2.Focus();this.Text = tabPage2.Text;if (textChanged2 == false){toolStripStatusLabel4.Text = "新建";}}对于AboutBox:using System;using System.Collections.Generic;using ponentModel;using System.Drawing;using System.Linq;using System.Reflection;using System.Threading.Tasks;using System.Windows.Forms;namespace Notepad{partial class AboutBox1 : Form{public AboutBox1(){this.Text = String.Format("关于 {0}", AssemblyTitle);belProductName.Text = AssemblyProduct;belVersion.Text = String.Format("版本 {0}", AssemblyVersion);belCopyright.Text = AssemblyCopyright;belCompanyName.Text = AssemblyCompany;this.textBoxDescription.Text = AssemblyDescription;}#region 程序集特性访问器public string AssemblyTitle{get{object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);if (attributes.Length > 0){AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];if (titleAttribute.Title != ""){return titleAttribute.Title;}}return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);}}public string AssemblyVersion{get{return Assembly.GetExecutingAssembly().GetName().Version.ToString();}}public string AssemblyDescription{get{object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false); if (attributes.Length == 0){return "";}return ((AssemblyDescriptionAttribute)attributes[0]).Description;}}public string AssemblyProduct{get{object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);if (attributes.Length == 0){return "";}return ((AssemblyProductAttribute)attributes[0]).Product;}}public string AssemblyCopyright{get{object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false); if (attributes.Length == 0){return "";}return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;}}public string AssemblyCompany{get{object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false); if (attributes.Length == 0){return "";}return ((AssemblyCompanyAttribute)attributes[0]).Company;}}#endregionprivate void AboutBox1_Load(object sender, EventArgs e){}private void okButton_Click(object sender, EventArgs e)}private void AboutBox1_FormClosing(object sender, FormClosingEventArgs e){Form1 frm1 = (Form1)this.Owner;frm1.timer1.Start();}}}以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。

java编程实现记事本(菜鸟级)

java编程实现记事本(菜鸟级)

java编程实现记事本(菜鸟级)import java.awt.BorderLayout;import java.awt.Container;import java.awt.event.KeyEvent;import javax.swing.JDesktopPane;import javax.swing.JFrame;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.JTextArea;import javax.swing.KeyStroke;public class china extends JFrame{public china(){super();setTitle("新建⽂本⽂档.txt-记事本");setBounds(100,200,450,450);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar menuBar=new JMenuBar();setJMenuBar(menuBar);setJMenuBar(menuBar);Container c=getContentPane();c.setLayout(new BorderLayout());JTextArea ta=new JTextArea();c.add(ta,BorderLayout.CENTER);JMenu a=new JMenu("⽂件");menuBar.add(a);JMenu s=new JMenu("编辑");menuBar.add(s);JMenu h=new JMenu("格式");menuBar.add(h);JMenu b=new JMenu("查看");menuBar.add(b);JMenu e=new JMenu("帮助");menuBar.add(e);JMenuBar d=new JMenuBar();JMenuItem mi_newf=new JMenuItem("新建(N)"); JMenuItem mi_open=new JMenuItem("打开(O)"); JMenuItem mi_save=new JMenuItem("保存(S)"); JMenuItem mi_lsave=new JMenuItem("另保存为(A)"); JMenuItem mi_yemian=new JMenuItem("页⾯设置(U)"); JMenuItem mi_dayin=new JMenuItem("打印(P)"); JMenuItem mi_quit=new JMenuItem("退出(Q)"); JMenuItemmi_chexiao=new JMenuItem("撤销(U)"); JMenuItem mi_jianqie=new JMenuItem("剪切(T)"); JMenuItem mi_copy=new JMenuItem("复制(C)"); JMenuItem mi_paste=new JMenuItem("粘贴(P)"); JMenuItem mi_delete=new JMenuItem("删除(D)"); JMenuItem mi_look=new JMenuItem("查找(L)"); JMenuItem mi_looknext=new JMenuItem("查找下⼀个(X)"); JMenuItemmi_tihuan=new JMenuItem("替换(R)"); JMenuItem mi_zhuandao=new JMenuItem("转到(G)"); JMenuItem mi_all=new JMenuItem("全选(A)"); JMenuItem mi_date=new JMenuItem("时间/⽇期(F5)"); JMenuItem mi_zidong=new JMenuItem("⾃动换⾏(W)"); JMenuItem mi_ziti=new JMenuItem("字体(T)"); JMenuItem mi_zhuangtai=new JMenuItem("状态栏(S)"); JMenuItem mi_team=new JMenuItem("帮助主题(H)"); JMenuItem mi_guanyu=new JMenuItem("关于记事本(A)");a.add(mi_newf);a.add(mi_open);a.add(mi_save);a.add(mi_lsave);a.addSeparator();a.add(mi_yemian);a.add(mi_dayin);a.addSeparator();a.add(mi_quit);s.add(mi_chexiao);s.addSeparator();s.add(mi_jianqie);s.add(mi_copy);s.add(mi_paste);s.add(mi_delete);s.addSeparator();s.add(mi_look);s.add(mi_tihuan);s.add(mi_zhuandao);s.addSeparator();s.add(mi_all);s.add(mi_date);h.add(mi_zidong);h.add(mi_ziti);b.add(mi_zhuangtai);e.add(mi_team);e.addSeparator();e.add(mi_guanyu);mi_newf.setMnemonic(KeyEvent.VK_N); mi_open.setMnemonic(KeyEvent.VK_O); mi_save.setMnemonic(KeyEvent.VK_S); mi_lsave.setMnemonic(KeyEvent.VK_A); mi_yemian.setMnemonic(KeyEvent.VK_U);mi_dayin.setMnemonic(KeyEvent.VK_P); mi_quit.setMnemonic(KeyEvent.VK_Q);mi_chexiao.setMnemonic(KeyEvent.VK_U); mi_jianqie.setMnemonic(KeyEvent.VK_T);mi_copy.setMnemonic(KeyEvent.VK_C);mi_paste.setMnemonic(KeyEvent.VK_P);mi_delete.setMnemonic(KeyEvent.VK_D);mi_look.setMnemonic(KeyEvent.VK_L);mi_looknext.setMnemonic(KeyEvent.VK_X);mi_tihuan.setMnemonic(KeyEvent.VK_R);mi_zhuandao.setMnemonic(KeyEvent.VK_G);mi_all.setMnemonic(KeyEvent.VK_A);mi_date.setMnemonic(KeyEvent.VK_F);mi_zidong.setMnemonic(KeyEvent.VK_W);mi_ziti.setMnemonic(KeyEvent.VK_T);mi_zhuangtai.setMnemonic(KeyEvent.VK_S);mi_team.setMnemonic(KeyEvent.VK_H);mi_guanyu.setMnemonic(KeyEvent.VK_A);mi_newf.setAccelerator(KeyStroke.getKeyStroke('N', java.awt.Event.SHIFT_MASK,false));mi_open.setAccelerator(KeyStroke.getKeyStroke('O', java.awt.Event.SHIFT_MASK,false));mi_save.setAccelerator(KeyStroke.getKeyStroke('S', java.awt.Event.SHIFT_MASK,false));mi_lsave.setAccelerator(KeyStroke.getKeyStroke('A', java.awt.Event.SHIFT_MASK,false));mi_yemian.setAccelerator(KeyStroke.getKeyStroke('U', java.awt.Event.SHIFT_MASK,false));mi_dayin.setAccelerator(KeyStroke.getKeyStroke('P', java.awt.Event.SHIFT_MASK,false));mi_quit.setAccelerator(KeyStroke.getKeyStroke('Q', java.awt.Event.SHIFT_MASK,false));mi_chexiao.setAccelerator(KeyStroke.getKeyStroke('U', java.awt.Event.SHIFT_MASK,false));mi_jianqie.setAccelerator(KeyStroke.getKeyStroke('T', java.awt.Event.SHIFT_MASK,false));mi_copy.setAccelerator(KeyStroke.getKeyStroke('C', java.awt.Event.SHIFT_MASK,false));mi_paste.setAccelerator(KeyStroke.getKeyStroke('P', java.awt.Event.SHIFT_MASK,false));mi_delete.setAccelerator(KeyStroke.getKeyStroke('D', java.awt.Event.SHIFT_MASK,false));mi_look.setAccelerator(KeyStroke.getKeyStroke('L', java.awt.Event.SHIFT_MASK,false));mi_looknext.setAccelerator(KeyStroke.getKeyStroke('X', java.awt.Event.SHIFT_MASK,false));mi_tihuan.setAccelerator(KeyStroke.getKeyStroke('R', java.awt.Event.SHIFT_MASK,false));mi_zhuandao.setAccelerator(KeyStroke.getKeyStroke('G', java.awt.Event.SHIFT_MASK,false)); mi_all.setAccelerator(KeyStroke.getKeyStroke('A', java.awt.Event.SHIFT_MASK,false));mi_date.setAccelerator(KeyStroke.getKeyStroke('F', java.awt.Event.SHIFT_MASK,false));mi_zidong.setAccelerator(KeyStroke.getKeyStroke('W', java.awt.Event.SHIFT_MASK,false)); mi_ziti.setAccelerator(KeyStroke.getKeyStroke('T', java.awt.Event.SHIFT_MASK,false));mi_zhuangtai.setAccelerator(KeyStroke.getKeyStroke('S', java.awt.Event.SHIFT_MASK,false)); mi_team.setAccelerator(KeyStroke.getKeyStroke('H', java.awt.Event.SHIFT_MASK,false));mi_guanyu.setAccelerator(KeyStroke.getKeyStroke('A', java.awt.Event.SHIFT_MASK,false)); setJMenuBar(menuBar);setVisible(true);}public static void main(String[]args){new china();}}。

记事本程序源代码汇总

记事本程序源代码汇总

记事本程序源代码汇总下面是一个简单的记事本程序的源代码:```#include <iostream>#include <fstream>#include <string>using namespace std;void showMencout << "**********************" << endl; cout << " 记事本程序 " << endl; cout << "**********************" << endl; cout << "请选择以下操作:" << endl;cout << "1. 新建记事本文件" << endl;cout << "2. 打开已有记事本文件" << endl; cout << "3. 查看记事本文件内容" << endl; cout << "4. 添加文本到记事本文件" << endl; cout << "5. 退出程序" << endl;cout << "**********************" << endl; void createFilstring filename;cout << "请输入新建记事本文件的文件名:";cin >> filename;//在当前目录创建一个新文件ofstream outFile(filename);outFile.close(;cout << "成功创建记事本文件:" << filename << endl; void openFilstring filename;cout << "请输入要打开的记事本文件的文件名:";cin >> filename;//尝试打开已存在的文件ifstream inFile(filename);if (!inFile)cout << "无法打开文件:" << filename << endl;} elsestring content;getline(inFile, content, '\0');cout << "记事本文件内容:" << endl;cout << content << endl;inFile.close(;}void viewFilstring filename;cout << "请输入要查看的记事本文件的文件名:"; cin >> filename;//尝试打开已存在的文件ifstream inFile(filename);if (!inFile)cout << "无法打开文件:" << filename << endl; } elsestring line;cout << "记事本文件内容:" << endl;while (getline(inFile, line))cout << line << endl;}inFile.close(;}void appendToFilstring filename;cout << "请输入要添加文本的记事本文件的文件名:";cin >> filename;//尝试打开已存在的文件ofstream outFile(filename, ios::app);if (!outFile)cout << "无法打开文件:" << filename << endl;} elsestring content;cout << "请输入要添加的文本内容(以#结束):" << endl; while (true)getline(cin, content);if (content == "#")break;}outFile << content << endl;}outFile.close(;cout << "成功添加文本到记事本文件:" << filename << endl; }int maiint choice;doshowMenu(;cout << "请输入您的选择:";cin >> choice;switch (choice)case 1:createFile(;break;case 2:openFile(;break;case 3:viewFile(;break;case 4:appendToFile(;break;case 5:cout << "感谢使用记事本程序,再见!" << endl;break;default:cout << "无效的选择,请重新输入!" << endl;}} while (choice != 5);return 0;```这个记事本程序通过命令行界面提供了以下操作:1.新建记事本文件:用户输入一个文件名后,在当前目录下创建一个新文件作为记事本。

冰墩墩记事本代码

冰墩墩记事本代码

import turtleturtle.title('Python(冰墩墩)') turtle.speed(40) # 可以自己调节速度# 左手turtle.penup()turtle.goto(177, 112)turtle.pencolor("lightgray") turtle.pensize(3)turtle.fillcolor("white")turtle.begin_fill()turtle.pendown()turtle.setheading(80)turtle.circle(-45, 200)turtle.circle(-300, 23)turtle.end_fill()# 左手内turtle.penup()turtle.goto(182, 95)turtle.pencolor("black")turtle.pensize(1)turtle.fillcolor("black")turtle.begin_fill()turtle.setheading(95) turtle.pendown()turtle.circle(-37, 160) turtle.circle(-20, 50) turtle.circle(-200, 30) turtle.end_fill()# 轮廓# 头顶turtle.penup()turtle.goto(-73, 230) turtle.pencolor("lightgray") turtle.pensize(3)turtle.fillcolor("white") turtle.begin_fill()turtle.pendown()turtle.setheading(20) turtle.circle(-250, 35)# 左耳turtle.setheading(50) turtle.circle(-42, 180)# 左侧turtle.setheading(-50)turtle.circle(-320, 45) # 左腿turtle.circle(120, 30) turtle.circle(200, 12) turtle.circle(-18, 85) turtle.circle(-180, 23) turtle.circle(-20, 110) turtle.circle(15, 115) turtle.circle(100, 12)# 右腿turtle.circle(15, 120) turtle.circle(-15, 110) turtle.circle(-150, 30) turtle.circle(-15, 70) turtle.circle(-150, 10) turtle.circle(200, 35) turtle.circle(-150, 20) # 右手turtle.setheading(-120) turtle.circle(50, 30) turtle.circle(-35, 200)# 右侧turtle.setheading(86) turtle.circle(-300, 26) # 右耳turtle.setheading(122) turtle.circle(-53, 160) turtle.end_fill()# 右耳内turtle.penup() turtle.goto(-130, 180) turtle.pencolor("black") turtle.pensize(1) turtle.fillcolor("black") turtle.begin_fill() turtle.pendown() turtle.setheading(120) turtle.circle(-28, 160) turtle.setheading(210) turtle.circle(150, 20) turtle.end_fill()# 左耳内turtle.penup() turtle.goto(90, 230) turtle.setheading(40) turtle.begin_fill() turtle.pendown() turtle.circle(-30, 170) turtle.setheading(125) turtle.circle(150, 23) turtle.end_fill()# 右手内turtle.penup() turtle.goto(-180, -55) turtle.fillcolor("black") turtle.begin_fill() turtle.setheading(-120) turtle.pendown() turtle.circle(50, 30) turtle.circle(-27, 200) turtle.circle(-300, 20) turtle.setheading(-90) turtle.circle(300, 14) turtle.end_fill()# 左腿内turtle.penup() turtle.goto(108, -168) turtle.fillcolor("black") turtle.begin_fill() turtle.pendown() turtle.setheading(-115) turtle.circle(110, 15) turtle.circle(200, 10) turtle.circle(-18, 80) turtle.circle(-180, 13) turtle.circle(-20, 90) turtle.circle(15, 60) turtle.setheading(42) turtle.circle(-200, 29) turtle.end_fill()# 右腿内turtle.penup() turtle.goto(-38, -210) turtle.fillcolor("black") turtle.begin_fill() turtle.pendown()turtle.setheading(-155) turtle.circle(15, 100) turtle.circle(-10, 110) turtle.circle(-100, 30) turtle.circle(-15, 65) turtle.circle(-100, 10) turtle.circle(200, 15) turtle.setheading(-14) turtle.circle(-200, 27) turtle.end_fill()# 右眼# 眼圈turtle.penup() turtle.goto(-64, 120) turtle.begin_fill() turtle.pendown() turtle.setheading(40) turtle.circle(-35, 152) turtle.circle(-100, 50) turtle.circle(-35, 130) turtle.circle(-100, 50) turtle.end_fill()# 眼珠turtle.penup()turtle.goto(-47, 55)turtle.fillcolor("white") turtle.begin_fill()turtle.pendown()turtle.setheading(0)turtle.circle(25, 360)turtle.end_fill()turtle.penup()turtle.goto(-45, 62)turtle.pencolor("darkslategray") turtle.fillcolor("darkslategray") turtle.begin_fill()turtle.pendown()turtle.setheading(0)turtle.circle(19, 360)turtle.end_fill()turtle.penup()turtle.goto(-45, 68)turtle.fillcolor("black") turtle.begin_fill()turtle.pendown() turtle.setheading(0) turtle.circle(10, 360) turtle.end_fill() turtle.penup() turtle.goto(-47, 86) turtle.pencolor("white") turtle.fillcolor("white") turtle.begin_fill() turtle.pendown() turtle.setheading(0) turtle.circle(5, 360) turtle.end_fill()# 左眼# 眼圈turtle.penup() turtle.goto(51, 82) turtle.fillcolor("black") turtle.begin_fill() turtle.pendown() turtle.setheading(120) turtle.circle(-32, 152)turtle.circle(-100, 55)turtle.circle(-25, 120)turtle.circle(-120, 45)turtle.end_fill()# 眼珠turtle.penup()turtle.goto(79, 60)turtle.fillcolor("white") turtle.begin_fill()turtle.pendown()turtle.setheading(0)turtle.circle(24, 360)turtle.end_fill()turtle.penup()turtle.goto(79, 64)turtle.pencolor("darkslategray") turtle.fillcolor("darkslategray") turtle.begin_fill()turtle.pendown()turtle.setheading(0)turtle.circle(19, 360)turtle.end_fill()turtle.penup() turtle.goto(79, 70) turtle.fillcolor("black") turtle.begin_fill() turtle.pendown() turtle.setheading(0) turtle.circle(10, 360) turtle.end_fill() turtle.penup() turtle.goto(79, 88) turtle.pencolor("white") turtle.fillcolor("white") turtle.begin_fill() turtle.pendown() turtle.setheading(0) turtle.circle(5, 360) turtle.end_fill()# 鼻子turtle.penup() turtle.goto(37, 80) turtle.fillcolor("black") turtle.begin_fill()turtle.pendown() turtle.circle(-8, 130) turtle.circle(-22, 100) turtle.circle(-8, 130) turtle.end_fill()# 嘴turtle.penup() turtle.goto(-15, 48) turtle.setheading(-36) turtle.begin_fill() turtle.pendown() turtle.circle(60, 70) turtle.setheading(-132) turtle.circle(-45, 100) turtle.end_fill()# 彩虹圈turtle.penup() turtle.goto(-135, 120) turtle.pensize(5) turtle.pencolor("cyan") turtle.pendown() turtle.setheading(60)turtle.circle(-165, 150) turtle.circle(-130, 78) turtle.circle(-250, 30) turtle.circle(-138, 105) turtle.penup()turtle.goto(-131, 116) turtle.pencolor("slateblue") turtle.pendown()turtle.setheading(60) turtle.circle(-160, 144) turtle.circle(-120, 78) turtle.circle(-242, 30) turtle.circle(-135, 105) turtle.penup()turtle.goto(-127, 112) turtle.pencolor("orangered") turtle.pendown()turtle.setheading(60) turtle.circle(-155, 136) turtle.circle(-116, 86) turtle.circle(-220, 30) turtle.circle(-134, 103)turtle.penup()turtle.goto(-123, 108) turtle.pencolor("gold") turtle.pendown()turtle.setheading(60) turtle.circle(-150, 136) turtle.circle(-104, 86) turtle.circle(-220, 30) turtle.circle(-126, 102) turtle.penup()turtle.goto(-120, 104) turtle.pencolor("greenyellow") turtle.pendown()turtle.setheading(60) turtle.circle(-145, 136) turtle.circle(-90, 83)turtle.circle(-220, 30) turtle.circle(-120, 100) turtle.penup()# 爱心turtle.penup()turtle.goto(220, 115)turtle.pencolor("brown") turtle.pensize(1) turtle.fillcolor("brown") turtle.begin_fill() turtle.pendown() turtle.setheading(36) turtle.circle(-8, 180) turtle.circle(-60, 24) turtle.setheading(110) turtle.circle(-60, 24) turtle.circle(-8, 180) turtle.end_fill()# 五环turtle.penup()turtle.goto(-5, -170) turtle.pendown() turtle.pencolor("blue") turtle.circle(6)turtle.penup()turtle.goto(10, -170) turtle.pendown() turtle.pencolor("black")turtle.circle(6)turtle.penup()turtle.goto(25, -170)turtle.pendown()turtle.pencolor("brown")turtle.circle(6)turtle.penup()turtle.goto(2, -175)turtle.pendown()turtle.pencolor("lightgoldenrod")turtle.circle(6)turtle.penup()turtle.goto(16, -175)turtle.pendown()turtle.pencolor("green")turtle.circle(6)turtle.penup()turtle.pencolor("black")turtle.goto(-16, -160)turtle.write("BEIJING 2022", font=('Arial', 10, 'bold italic')) turtle.hideturtle()turtle.done()。

记事本编程序

记事本编程序

看点:你知道吗?为什么现在脚本病毒如此猖獗?你知道吗?编写一个脚本病毒其实非常简单!你知道吗?根本不懂编程的你只要稍加操练也能编出不错的软件!Windows脚本就像魔法卷轴般神奇,编写起来也很容易。

或许这句话并没有凭据,但把玩几个小时,比如看完这期专题并且亲自演练一下,相信你会同意我的说法。

当然,有一点编程经验当然更好,因为你会发现很多知识都是相通的。

快来吧!编写你的第一个脚本打开"记事本",按照如图1所示输入(图1 你的第一个脚本程序),并把这个文件保存为HelloWorld.vbs,接着双击它,你就会看到一个跳出来的对话框,上面写着"Hello World!",点击"确定"按钮就可以结束这个脚本。

恭喜!你已经完成了第一个脚本程序!一、魔法的前言:什么是脚本1.什么是编程语言许多朋友一听到什么编程语言就头大,其实理解起来并不困难,说得通俗些,编程语言就是类似于汉语、英语的语言,只不过它们是用来和电脑沟通的语言,程序员就相当于你和电脑之间的翻译,他们会把你需要实现的功能用相应语言告诉电脑,让它来执行,如果某个功能会有非常多人用到,那么程序员就把它翻译成成一个文件,这就是程序。

因此,你只要掌握了编程语言的基本命令、规范、用法,那么就能轻松编出程序,当然,电脑在理解语言方面有些弱智,或者说是非常严谨,你不能说错一个单词或把语句顺序搞混,否则它就无法理解你的话,无法执行你的命令或做出完全相反的事情。

2.什么是Windows脚本语言首先,Windows脚本语言也是一种编程语言,也有自己专门的命令词汇、规范、用法,你只要按照自己的要求把命令写进去,那么Windows就会直接执行。

只不过相对于Java、C++等编程语言要简单得多,也就是即使以前根本没有编程经验的普通人也能很容易地在较短时间内学习并掌握。

同时,Windows脚本语言是完全免费的,不像一套Visual Basic或Delphi,动辄几千人民币,它不花一分钱。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

跟我学做记事本-编程实例用VB做一个记事本实在不很复杂,我们完全可以通过向导来很方便地做出来。

但本文只打算讨论用手动方法制作记事本,旨在向VB初学者展示:学VB原来是如此容易!通过阅读、研究本文并按本文所述进行尝试,初学者将学到很多东西,如怎样使用RichText 控件来打开和保存文件,怎样制作菜单、工具栏和状态栏以及如何对其编写代码等。

第一章让我们的记事本马上运行急于求成是初学者共有的心愿。

那好,请按如下三个步骤做,我们的愿望立即就可以实现!步骤一:绘制界面。

新建一个标准EXE工程,将其Caption属性改为“超级记事本”,点击Icon属性给它找个合适的Icon图标。

单击菜单“工程”-“部件”,在弹出的“部件”对话框里找到MicrosoftRichText Box 6.0和公共对话框Microsoft Common Dialog 6.0并选中它们,单击“确定”按钮。

这时左边的工具栏上出现了我们刚才新添的两个控件了。

在窗体上绘制RichTextBox和Commn Dialog,其中RichText Box的大小和位置可不用理睬,我们将在代码中处理它,当然,有必要把它的ScrollBar属性设为2-rtfVertical,这样在打开和编辑文件时垂直滚动条才可用。

步骤二:编辑菜单。

按Ctrl+E调出菜单编辑器,我们来做如下几个菜单:一.文件菜单:文件(第一层)mnuFile新建(第二层)mnuNew打开(第二层)mnuOpen保存(第二层)mnuSave- (第二层)mnuFileSep (分隔线)退出(第二层)mnuExit二.编辑菜单:编辑(第一层)mnuEdit复制(第二层)mnuCopy剪切(第二层)mnuCut粘贴(第二层)mnuPaste第二层)mnuEditSep (分隔线)全选(第二层)mnuSelecAll三.搜索菜单:搜索(第一层)mnuSearch查找(第二层)mnuFind查找下一个(第二层)mnuFindOn四.帮助菜单:帮助(第一层)mnuHelp使用说明(第二层)mnuUsage关于(第二层)mnuAbout(注:各菜单项的快捷键请自行设置)好了,其它的菜单项以后再根据需要添加。

现在进入:步骤三:编写代码。

'声明查找变量Dim sFind As String'声明文件类型Dim FileType, FiType As String'初始化程序Private Sub Form_Load()'设置程序启动时的大小Me.Height = 6000Me.Width = 9000End Sub'设置编辑框的位置和大小Private Sub Form_Resize()On Error Resume Next '出错处理RichTextBox1.Top=20RichTextBox1.Left=20RichTextBox1.Height = ScaleHeight-40 RichTextBox1.Width = ScaleWidth-40 End Sub'新建文件Private Sub mnuNew_Click()RichTextBox1.Text = "" '清空文本框FileName = "未命名"Me.Caption = FileNameEnd Sub'打开文件Private Sub mnuOpen_Click()CommonDialog1.Filter = "文本文档(*.txt)|*.txt|RTF文档(*.rtf)|*.rtf|所有文件(*.*)|*.*" CommonDialog1.ShowOpenRichTextBox1.Text = "" '清空文本框FileName = CommonDialog1.FileNameRichTextBox1.LoadFile FileNameMe.Caption = "超级记事本:" & FileNameEnd Sub'保存文件Private Sub mnuSave_Click()CommonDialog1.Filter = "文本文档(*.txt)|*.txt|RTF文档(*.rtf)|*.rtf|所有文件(*.*)|*.*" CommonDialog1.ShowSaveFileType = CommonDialog1.FileTitleFiType = LCase(Right(FileType, 3))FileName = CommonDialog1.FileNameSelect Case FiTypeCase "txt"RichTextBox1.SaveFile FileName, rtfText Case "rtf"RichTextBox1.SaveFile FileName, rtfRTF Case "*.*"RichTextBox1.SaveFile FileNameEnd SelectMe.Caption = "超级记事本:" & FileName End Sub'退出Private Sub mnuExit_Click()EndEnd Sub'复制Private Sub mnuCopy_Click() Clipboard.ClearClipboard.SetText RichTextBox1.SelText End Sub'剪切Private Sub mnuCut_Click() Clipboard.ClearClipboard.SetText RichTextBox1.SelText RichTextBox1.SelText = ""End Sub'全选Private Sub mnuSelectAll_Click()RichTextBox1.SelStart = 0RichTextBox1.SelLength = Len(RichTextBox1.Text) End Sub'粘贴Private Sub mnuPaste_Click()RichTextBox1.SelText = Clipboard.GetTextEnd Sub'查找Private Sub mnuFind_Click()sFind = InputBox("请输入要查找的字、词:", "查找内容", sFind)RichTextBox1.Find sFindEnd Sub'继续查找Private Sub mnuFindOn_Click()RichTextBox1.SelStart = RichTextBox1.SelStart + RichTextBox1.SelLength + 1RichTextBox1.Find sFind, , Len(RichTextBox1)End Sub'使用说明Private Sub mnuReadme_Click()On Error GoTo handlerRichTextBox1.LoadFile "Readme.txt", rtfText '请写好Readme.txt文件并存入程序所在文件夹中Me.Caption = "超级记事本:" & "使用说明"Exit Subhandler:MsgBox "使用说明文档可能已经被移除,请与作者联系。

",vbOKOnly, " 错误信息"End Sub'关于Private Sub mnuAbout_Click()MsgBox "超级记事本Ver1.0 版权所有(C) 2001 土人",vbOKOnly,"关于"End Sub'设置弹出式菜单(即在编辑框中单击鼠标右键时弹出的动态菜单)Private Sub RichTextBox1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)If Button = 2 ThenPopupMenu mnuEdit, vbPopupMenuLeftAlignElseExit SubEnd IfEnd Sub'防止在切换输入法时字体自变(感谢王必成先生提供此方案)Private Sub RichTextBox1_KeyUp(KeyCode As Integer, Shift As Integer) If KeyCode = vbKeySpace ThenRichTextBox1.SelFontName = CommonDialog1.FontNameEnd IfEnd Sub至此,我们的记事本可以编译使用了。

点击菜单“文件”-“生成XXX.EXE”,回到桌面运行我们的记事本看看,是不是颇有成就感?当然,这样的记事本还比较粗糙,我们还需要做些工作,请看下一章。

第二章美化程序界面多数字处理软件都有工具栏和状态栏。

工具栏和状态栏除了能美化我们的程序使其更具有专业性质外,还给用户带来操作上的便利。

现在我们就来做一做这两样东西。

一.工具栏(一)制作工具栏单击“工程”-“部件”,选中Microsoft Windows Common Control 6.0并确定。

这时,我们要用到的控件就出现在左边的工具栏上了。

要做工具栏,首先需要一个叫ImageList的控件来装载图像。

在程序界面上添加它,然后右键单击此控件,左键单击“属性”,弹出“属性页”对话框的“图像”,再单击“插入图片”就可以一次性装载图片了(如不满意,以后还可以添加)。

图片可在C:MicrosoftVisual StudioCommonGraphicsBitmapsTlBr_W95下选择(这里假设你的VB安装在C盘下)。

注意了:在插入图片时给每一张图片注明关键字,以便在引用图片时不至于混乱。

如插入“新建”的图片,我们在“关键字”栏注明“New”。

图片有了,接下来在程序界面添加工具栏(ToolBar)。

添加后工具栏就出现在菜单下面,右键单击它,选择“属性”,在弹出的“属性页”对话框中的“通用”项作些设置,主要如下两项:1.“图像列表”:选择ImageList12.“样式”:根据喜爱选择1-trbStandard或者2-trbFlat继续点击“属性页”的“按钮”选项,插入若干按钮。

相关文档
最新文档