记事本代码
我用java编写的记事本代码,分享给大家
![我用java编写的记事本代码,分享给大家](https://img.taocdn.com/s3/m/04eda13c580216fc700afd76.png)
backcolor.add(white); backcolor.addSeparator();
backcolor.add(pink); backcolor.addSeparator();
backcolor.add(morecolor);
JMenuItem red=new JMenuItem("红色");//","橙","黄","","青","蓝","紫","黑","灰","白","粉红"
JMenuItem green=new JMenuItem("绿色");
JMenuItem yellow=new JMenuItem("黄色");
clear.setFont(a); clear.setForeground(Color.MAGENTA);
paste.setFont(a); paste.setForeground(Color.MAGENTA);
cut.setFont(a); cut.setForeground(Color.MAGENTA);
JMenuItem black=new JMenuItem("黑色");
JMenuItem gray=new JMenuItem("灰色");
JMenuItem white=new JMenuItem("白色");
JMenuItem pink=new JMenuItem("粉红");
记事本(代码)
![记事本(代码)](https://img.taocdn.com/s3/m/90f8a61b0740be1e640e9a16.png)
char t; //选择是否继续输入
flag:
printf("请输入第%d个学生信息\n",a+1);
printf("学号:");
scanf("%d",>[a].xuehao);
printf("姓名:");
scanf("%s",>[a].name);
for(int k=i;k<a;k++)
if(gt[i].xuehao>gt[k].xuehao)
{
gts=gt[i];
gt[i]=gt[k];
gt[k]=gts;
}
{
for(l=0;l<a;l++)
{
gt[l]=gt[l+1];
}
}
}
if(x==2)
{
printf("请输入该学生的姓名\n");
scanf("%s",&q);
for (i=0;i<a;i++)
{
int l; //用于for循环
int i; //用于表示删除编号
int x; //选择
char q[10]; //被删除的姓名
int cx; //被删除的学号
printf("1.按学号删除\n");
char q[10]; //被修改的姓名
int cx; //被修改的学号
printf("1.按学号修改\n");
printf("2.按姓名修改\n");
记事本源代码
![记事本源代码](https://img.taocdn.com/s3/m/f376e92eae45b307e87101f69e3143323968f57f.png)
记事本源代码先上效果图。
这个记事本操作简便,功能强⼤,在记事本的基础上添加了将内容发送短信和发送邮件的功能。
这个应⽤也已经功过了微软的认证。
115⽹盘⾥⾯的是最新的。
QQ:29992379下载地址:Memo.xap实体类1: public class Note2: {3: public string NoteGuid { get; set; }4: public string NoteContent { get; set; }5: public string NoteTime { get; set; }6: }在独⽴存储中⽣成存储结构。
1: if (!IsolatedStorageSettings.ApplicationSettings.Contains("Notes"))2: {3: List<Note> notes = new List<Note>();4: IsolatedStorageSettings.ApplicationSettings["Notes"] = notes as List<Note>;5: IsolatedStorageSettings.ApplicationSettings.Save();6:7: }绑定⽂章的列表,并按编号倒排序。
1: public partial class MainPage : PhoneApplicationPage2: {3: // 构造函数4: public MainPage()5: {6: InitializeComponent();7: BingData();8: }9: List<Note> notes = new List<Note>();10: private void BingData()11: {12: notes = IsolatedStorageSettings.ApplicationSettings["Notes"] as List<Note>;13:14: var descInfo = from i in notes orderby i.NoteTime descending select i;//linq对⽂章列表的排序15:16: MainListBox.ItemsSource = descInfo;17: }18:19: private void ApplicationBarIconButton_Click(object sender, EventArgs e)20: {21: NavigationService.Navigate(new Uri("/Add.xaml", UriKind.RelativeOrAbsolute));22: }23:24: protected override void OnBackKeyPress(ponentModel.CancelEventArgs e)25: {26: e.Cancel = true;27: App.Quit();28: base.OnBackKeyPress(e);29: }30:31: private void ApplicationBarIconButton_Click_1(object sender, EventArgs e)32: {33: NavigationService.Navigate(new Uri("/About.xaml", UriKind.RelativeOrAbsolute));34: }35:36: private void StackPanel_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)37: {38: string noteguid = ((TextBlock)(((StackPanel)sender).Children.First())).Tag.ToString();39: NavigationService.Navigate(new Uri("/DetailsPage.xaml?noteguid=" + noteguid, UriKind.Relative));40: }41: }⽂章显⽰的页⾯以及⼀系列功能1: public partial class DetailsPage : PhoneApplicationPage2: {3: // 构造函数4: public DetailsPage()5: {6: InitializeComponent();7: }8: string noteguid;9: protected override void OnNavigatedTo(NavigationEventArgs e)10: {11: BingData();12: noteguid = NavigationContext.QueryString["noteguid"].ToString();13: foreach (var item in notes)14: {15: if (item.NoteGuid==noteguid)16: {17: ContentText.Text = item.NoteContent;18: TimeText.Text = item.NoteTime;19: return;20: }21: }22: }23:24: List<Note> notes = new List<Note>();25: private void BingData()26: {27: notes = IsolatedStorageSettings.ApplicationSettings["Notes"] as List<Note>;28: }29:30: private void Edit_Click(object sender, EventArgs e)31: {32: NavigationService.Navigate(new Uri("/Edit.xaml?noteguid=" + noteguid.ToString(), UriKind.RelativeOrAbsolute)); 33: }34:35: protected override void OnBackKeyPress(ponentModel.CancelEventArgs e)36: {37: e.Cancel = true;38: NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.RelativeOrAbsolute));39: base.OnBackKeyPress(e);40: }41:42: private void Del_Click(object sender, EventArgs e)43: {44: for (int i = 0; i < notes.Count; i++)45: {46: if (notes[i].NoteGuid==noteguid)47: {48: notes.RemoveAt(i);49: }50: }51: IsolatedStorageSettings.ApplicationSettings["Notes"] = notes as List<Note>;52: IsolatedStorageSettings.ApplicationSettings.Save();53: NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.RelativeOrAbsolute));54: }55:56: private void Email_Click(object sender, EventArgs e)57: {58: EmailComposeTask email = new EmailComposeTask();59: email.Body = ContentText.Text.ToString();60: email.Show();61: }62:63: private void Message_Click(object sender, EventArgs e)64: {65: SmsComposeTask sms = new SmsComposeTask();66: sms.Body = ContentText.Text.ToString();67: sms.Show();68: }69: }⽂章的编辑页⾯代码1: public partial class Edit : PhoneApplicationPage2: {3: public Edit()4: {5: InitializeComponent();6: }7:8: private void ApplicationBarIconButton_Click(object sender, EventArgs e)9: {10: foreach (var item in notes)11: {12: if (item.NoteGuid == noteguid)13: {14: item.NoteContent = ContentText.Text;15: item.NoteTime=TimeText.Text;16: }17: }18:19: IsolatedStorageSettings.ApplicationSettings["Notes"] = notes as List<Note>;20: IsolatedStorageSettings.ApplicationSettings.Save();21: NavigationService.Navigate(new Uri("/DetailsPage.xaml?noteguid=" + noteguid.ToString(), UriKind.RelativeOrAbsolute)); 22: }23: string noteguid;24: protected override void OnNavigatedTo(NavigationEventArgs e)25: {26: BingData();27: noteguid = NavigationContext.QueryString["noteguid"].ToString();28: foreach (var item in notes)29: {30: if (item.NoteGuid==noteguid)31: {32: ContentText.Text = item.NoteContent;33: TimeText.Text = item.NoteTime;34: return;35: }36: }37: }38:39: List<Note> notes = new List<Note>();40: private void BingData()41: {42: notes = IsolatedStorageSettings.ApplicationSettings["Notes"] as List<Note>;43: }44: }。
纯C++代码写的记事本
![纯C++代码写的记事本](https://img.taocdn.com/s3/m/c2014ba97cd184254b3535b8.png)
#include "windows.h"#include "wyyapi.h"#include "inttypes.h"#include <string>#include "stdio.h"LRESULT CALLBACK MainWndProc(HWND,UINT,WPARAM,LPARAM);HMENU wyymenu=NULL;int i=0;BOOL CreateTopMenu(){wyymenu=CreateMenu();HMENU wyypopup=CreateMenu();HMENU wangpopup=CreateMenu();AppendMenu(wyypopup,MF_STRING,IDM_OPEN,"&打开");AppendMenu(wyypopup,MF_STRING,IDM_EXIT,"&退出");AppendMenu(wangpopup,MF_STRING,IDM_NEW,"&刷新");AppendMenu(wangpopup,MF_STRING,IDM_SAVE,"&保存");AppendMenu(wyymenu,MF_POPUP,(intptr_t)wyypopup,"&王云勇");AppendMenu(wyymenu,MF_POPUP,(intptr_t)wangpopup,"&王云");return true;}int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow){char wclassname[]="wyy";WNDCLASSEX wc;wc.cbSize=sizeof(WNDCLASSEX);wc.style=CS_HREDRAW|CS_VREDRAW|CS_NOCLOSE;wc.lpfnWndProc=MainWndProc;wc.cbClsExtra=0;wc.cbWndExtra=0;wc.hInstance=hInstance;wc.hIcon=LoadIcon(hInstance,(LPSTR)IDI_MAIN);wc.hCursor=LoadCursor(NULL,IDC_ARROW);wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);wc.lpszMenuName=NULL;wc.lpszClassName=wclassname;wc.hIconSm=LoadIcon(hInstance,(LPSTR)IDI_MAIN);RegisterClassEx(&wc);CreateTopMenu();HWND hwnd=CreateWindowEx(WS_EX_LEFT,wclassname,"王云勇首富",WS_CAPTION,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,wyymenu,hInstance,NULL);if(hwnd==NULL){MessageBox(NULL,"窗口出错","error",MB_OK);return -1;}ShowWindow(hwnd,nCmdShow);UpdateWindow(hwnd);MSG msg;while(GetMessage(&msg,NULL,0,0)){TranslateMessage(&msg);DispatchMessage(&msg);}return msg.wParam;}LRESULT CALLBACK MainWndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam){FILE *wyywy;static int i=0;HDC hdc;PAINTSTRUCT ps;static std::string str;static char *sf;static wchar_t *sfwyy;OPENFILENAME ofn;static char szFile[256];static char szFileTitle[256];memset(&ofn,0,sizeof(ofn));ofn.lStructSize=sizeof(ofn);ofn.hwndOwner=hwnd;ofn.lpstrFilter="保存的文件(*.txt)\0*.txt\0\0";ofn.nFilterIndex=1;ofn.lpstrFile=szFile;ofn.nMaxFile=sizeof(szFile);ofn.lpstrFileTitle=szFileTitle;ofn.nMaxFileTitle=sizeof(szFileTitle);ofn.Flags=OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST|OFN_EXPLORER;switch(message){case WM_COMMAND:switch(LOWORD(wParam))MessageBox(hwnd,TEXT("王云勇"),TEXT("首富"),MB_OK); break;case IDM_EXIT:exit(0);break;case IDM_NEW:{str.clear();i=i+8;InvalidateRect(hwnd,NULL,1);}break;case IDM_SAVE:{if(GetSaveFileName(&ofn)){sf=ofn.lpstrFile;strcat(sf,".txt");size_t len=strlen(sf)+1;size_t con=0;sfwyy=(wchar_t*)malloc(len*sizeof(wchar_t));mbstowcs_s(&con,sfwyy,len,sf,_TRUNCATE);if((wyywy=_wfopen(sfwyy,L"wt+"))==NULL){MessageBox(hwnd,TEXT("出错"),TEXT("首富"),MB_OK); MessageBox(hwnd,TEXT("返回"),TEXT("首富"),MB_OK); break;}_wsetlocale(0,L"chs");if(fwprintf(wyywy,L"%s",str)>0){MessageBox(hwnd,TEXT("保存成功"),TEXT("首富"),MB_OK);} if(fclose(wyywy)==0){MessageBox(hwnd,TEXT("王云勇成功"),TEXT("首富"),MB_OK);} }}default:break;}break;case WM_PAINT:{hdc=BeginPaint(hwnd,&ps);if(i==0){TextOut(hdc,0,0,str.c_str(),str.length());}EndPaint(hwnd,&ps);}break;{i=0;str=str+char(wParam);InvalidateRect(hwnd,NULL,0);return 0;}case WM_DESTROY:PostQuitMessage(0);return 0;}return DefWindowProc(hwnd,message,wParam,lParam); }。
Java记事本源代码(完整)
![Java记事本源代码(完整)](https://img.taocdn.com/s3/m/24b314f10242a8956bece4a2.png)
/*** 作品:记事本* 作者:**** 功能:简单的文字编辑*/import java.awt.*;import java.awt.event.*;import java.io.*;import javax.swing.*;import javax.swing.event.ChangeEvent;import javax.swing.event.ChangeListener;class NotePad extends JFrame{private JMenuBar menuBar;private JMenu fielMenu,editMenu,formMenu,aboutMenu;private JMenuItemnewMenuItem,openMenuItem,saveMenuItem,exitMenuItem;private JMenuItemcutMenuItem,copyMenuItem,pasteMenuItem,foundItem,replaceItem,s electAll;private JMenuItem font,about;private JTextArea textArea;private JFrame foundFrame,replaceFrame;private JCheckBoxMenuItem wrapline;private JTextField textField1=new JTextField(15);private JTextField textField2=new JTextField(15);private JButton startButton,replaceButton,reallButton;int start=0;String value;File file=null;JFileChooser fileChooser=new JFileChooser();boolean wrap=false;public NotePad(){//创建文本域textArea=new JTextArea();add(new JScrollPane(textArea),BorderLayout.CENTER);//创建文件菜单及文件菜单项fielMenu=new JMenu("文件");fielMenu.setFont(new Font("微软雅黑",0,15));newMenuItem=new JMenuItem("新建",newImageIcon("icons\\new24.gif"));newMenuItem.setFont(new Font("微软雅黑",Font.BOLD,13));newMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent. VK_N,InputEvent.CTRL_MASK));newMenuItem.addActionListener(listener);openMenuItem=new JMenuItem("打开",newImageIcon("icons\\open24.gif"));openMenuItem.setFont(new Font("微软雅黑",Font.BOLD,13));openMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent .VK_O,InputEvent.CTRL_MASK));openMenuItem.addActionListener(listener);saveMenuItem=new JMenuItem("保存",newImageIcon("icons\\save.gif"));saveMenuItem.setFont(new Font("微软雅黑",Font.BOLD,13));saveMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent .VK_S,InputEvent.CTRL_MASK));saveMenuItem.addActionListener(listener);exitMenuItem=new JMenuItem("退出",newImageIcon("icons\\exit24.gif"));exitMenuItem.setFont(new Font("微软雅黑",Font.BOLD,13));exitMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent .VK_E,InputEvent.CTRL_MASK));exitMenuItem.addActionListener(listener);//创建编辑菜单及菜单项editMenu=new JMenu("编辑");editMenu.setFont(new Font("微软雅黑",0,15));cutMenuItem=new JMenuItem("剪切",newImageIcon("icons\\cut24.gif"));cutMenuItem.setFont(new Font("微软雅黑",Font.BOLD,13));cutMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent. VK_X,InputEvent.CTRL_MASK));cutMenuItem.addActionListener(listener);copyMenuItem=new JMenuItem("复制",newImageIcon("icons\\copy24.gif"));copyMenuItem.setFont(new Font("微软雅黑",Font.BOLD,13));copyMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent .VK_C,InputEvent.CTRL_MASK));copyMenuItem.addActionListener(listener);pasteMenuItem=new JMenuItem("粘贴",newImageIcon("icons\\paste24.gif"));pasteMenuItem.setFont(new Font("微软雅黑",Font.BOLD,13));pasteMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEven t.VK_V,InputEvent.CTRL_MASK));pasteMenuItem.addActionListener(listener);foundItem=new JMenuItem("查找");foundItem.setFont(new Font("微软雅黑",Font.BOLD,13));foundItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK _F,InputEvent.CTRL_MASK));foundItem.addActionListener(listener);replaceItem=new JMenuItem("替换");replaceItem.setFont(new Font("微软雅黑",Font.BOLD,13));replaceItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent. VK_R,InputEvent.CTRL_MASK));replaceItem.addActionListener(listener);selectAll=new JMenuItem("全选");selectAll.setFont(new Font("微软雅黑",Font.BOLD,13));selectAll.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK _A,InputEvent.CTRL_MASK));selectAll.addActionListener(listener);//创建格式菜单及菜单项formMenu=new JMenu("格式");formMenu.setFont(new Font("微软雅黑",0,15));wrapline=new JCheckBoxMenuItem("自动换行");wrapline.setFont(new Font("微软雅黑",Font.BOLD,13));wrapline.addActionListener(listener);wrapline.addChangeListener(new ChangeListener() {public void stateChanged(ChangeEvent e) {if(wrapline.isSelected()){textArea.setLineWrap(true);}elsetextArea.setLineWrap(false);}});font=new JMenuItem("字体");font.setFont(new Font("微软雅黑",Font.BOLD,13)); font.addActionListener(listener);//创建关于菜单aboutMenu=new JMenu("关于");aboutMenu.setFont(new Font("微软雅黑",0,15)); about=new JMenuItem("记事本……");about.setFont(new Font("微软雅黑",Font.BOLD,13)); about.addActionListener(listener);//添加文件菜单项fielMenu.add(newMenuItem);fielMenu.add(openMenuItem);fielMenu.add(saveMenuItem);fielMenu.addSeparator();fielMenu.add(exitMenuItem);//添加编辑菜单项editMenu.add(cutMenuItem);editMenu.add(copyMenuItem);editMenu.add(pasteMenuItem);editMenu.add(foundItem);editMenu.add(replaceItem);editMenu.addSeparator();editMenu.add(selectAll);//添加格式菜单项formMenu.add(wrapline);formMenu.add(font);//添加关于菜单项aboutMenu.add(about);//添加菜单menuBar=new JMenuBar();menuBar.add(fielMenu);menuBar.add(editMenu);menuBar.add(formMenu);menuBar.add(aboutMenu);setJMenuBar(menuBar);//创建两个框架,用作查找和替换foundFrame=new JFrame();replaceFrame=new JFrame();//创建两个文本框textField1=new JTextField(15);textField2=new JTextField(15);startButton=new JButton("开始");startButton.addActionListener(listener);replaceButton=new JButton("替换为");replaceButton.addActionListener(listener);reallButton=new JButton("全部替换");reallButton.addActionListener(listener);}//创建菜单项事件监听器ActionListener listener=new ActionListener() {public void actionPerformed(ActionEvent e) {String name=e.getActionCommand();if(e.getSource() instanceof JMenuItem){if("新建".equals(name)){textArea.setText("");file=null;}if("打开".equals(name)){if(file!=null){fileChooser.setSelectedFile(file);}intreturnVal=fileChooser.showOpenDialog(NotePad.this);if(returnVal==JFileChooser.APPROVE_OPTION){file=fileChooser.getSelectedFile();}try{FileReader reader=new FileReader(file);int len=(int)file.length();char[] array=new char[len];reader.read(array,0,len);reader.close();textArea.setText(new String(array));}catch(Exception e_open){e_open.printStackTrace();}}}if("保存".equals(name)){if(file!=null){fileChooser.setSelectedFile(file);}intreturnVal=fileChooser.showSaveDialog(NotePad.this);if(returnVal==JFileChooser.APPROVE_OPTION){file=fileChooser.getSelectedFile();}try{FileWriter writer=new FileWriter(file);writer.write(textArea.getText());writer.close();}catch (Exception e_save) {e_save.getStackTrace();}}if("退出".equals(name)){System.exit(0);}if("剪切".equals(name)){textArea.cut();}if("复制".equals(name)){textArea.copy();}if("粘贴".equals(name)){textArea.paste();}if("查找".equals(name)){value=textArea.getText();foundFrame.add(textField1,BorderLayout.CENTER);foundFrame.add(startButton,BorderLayout.SOUTH);foundFrame.setLocation(300,300);foundFrame.setTitle("查找");foundFrame.pack();foundFrame.setVisible(true);foundFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE );}if("替换".equals(name)){value=textArea.getText();JLabel label1=new JLabel("查找内容:");JLabel label2=new JLabel("替换为:");JPanel panel1=new JPanel();panel1.setLayout(new GridLayout(2,2));JPanel panel2=new JPanel();panel2.setLayout(new GridLayout(1,3));replaceFrame.add(panel1,BorderLayout.NORTH);replaceFrame.add(panel2,BorderLayout.CENTER);panel1.add(label1);panel1.add(textField1);panel1.add(label2);panel1.add(textField2);panel2.add(startButton);panel2.add(replaceButton);panel2.add(reallButton);replaceFrame.setTitle("替换");replaceFrame.setLocation(300,300);replaceFrame.pack();replaceFrame.setVisible(true);replaceFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLO SE);}if("开始".equals(name)||"下一个".equals(name)){String temp=textField1.getText();int s=value.indexOf(temp,start);if(value.indexOf(temp,start)!=-1){textArea.setSelectionStart(s);textArea.setSelectionEnd(s+temp.length());textArea.setSelectedTextColor(Color.GREEN);start=s+1;startButton.setText("下一个");}else {JOptionPane.showMessageDialog(foundFrame, "查找完毕!", "提示", 0,new ImageIcon("icons\\search.gif"));foundFrame.dispose();}}if("替换为".equals(name)){String temp=textField1.getText();int s=value.indexOf(temp,start);if(value.indexOf(temp,start)!=-1){textArea.setSelectionStart(s);textArea.setSelectionEnd(s+temp.length());textArea.setSelectedTextColor(Color.GREEN);start=s+1;textArea.replaceSelection(textField2.getText());}else {JOptionPane.showMessageDialog(foundFrame, "查找完毕!", "提示", 0,new ImageIcon("icons\\search.gif"));foundFrame.dispose();}}if("全部替换".equals(name)){String temp=textArea.getText();temp=temp.replaceAll(textField1.getText(),textField2.getTex t());textArea.setText(temp);}if("全选".equals(name)){textArea.selectAll();}if("字体".equals(name)){FontDialog fontDialog=newFontDialog(NotePad.this);fontDialog.setVisible(true);if(textArea.getFont()!=fontDialog.getFont()){textArea.setFont(fontDialog.getFont());}}if("记事本……".equals(name)){AboutDialog aboutDialog=newAboutDialog(NotePad.this);aboutDialog.setVisible(true);}}};//创建字体设置对话面板,并添加相应事件监听器class FontDialog extends JDialog implements ItemListener, ActionListener, WindowListener{public JCheckBox Bold=new JCheckBox("Bold",false);public JCheckBox Italic=new JCheckBox("Italic",false);public List Size,Name;public int FontName;public int FontStyle;public int FontSize;public JButton OK=new JButton("OK");public JButton Cancel=new JButton("Cancel");public JTextArea Text=new JTextArea("字体预览文本域\n0123456789\nAaBbCcXxYyZz");public FontDialog(JFrame owner) {super(owner,"字体设置",true);GraphicsEnvironmentg=GraphicsEnvironment.getLocalGraphicsEnvironment();String name[]=g.getAvailableFontFamilyNames();Name=new List();Size=new List();FontName=0;FontStyle=0;FontSize=8;int i=0;Name.add("Default Value");for(i=0;i<name.length;i++)Name.add(name[i]);for(i=8;i<257;i++)Size.add(String.valueOf(i));this.setLayout(null);this.setBounds(250,200,480, 306);this.setResizable(false);OK.setFocusable(false);Cancel.setFocusable(false);Bold.setFocusable(false);Italic.setFocusable(false);Name.setFocusable(false);Size.setFocusable(false);Name.setBounds(10, 10, 212, 259);this.add(Name);Bold.setBounds(314, 10, 64, 22);this.add(Bold);Italic.setBounds(388, 10, 64, 22);this.add(Italic);Size.setBounds(232, 10, 64, 259);this.add(Size);Text.setBounds(306, 40, 157, 157);this.add(Text);OK.setBounds(306, 243, 74, 26);this.add(OK);Cancel.setBounds(390, 243, 74, 26);this.add(Cancel);Name.select(FontName);Size.select(FontSize);Text.setFont(getFont());Name.addItemListener(this);Size.addItemListener(this);Bold.addItemListener(this);Italic.addItemListener(this);OK.addActionListener(this);Cancel.addActionListener(this);this.addWindowListener(this);}public void itemStateChanged(ItemEvent e) {Text.setFont(getFont());}public void actionPerformed(ActionEvent e) {if(e.getSource()==OK){FontName=Name.getSelectedIndex();FontStyle=getStyle();FontSize=Size.getSelectedIndex();this.setVisible(false);}else cancel();}public void windowClosing(WindowEvent e) {cancel();}public Font getFont(){if(Name.getSelectedIndex()==0) return new Font("新宋体",getStyle(),Size.getSelectedIndex()+8);else return newFont(Name.getSelectedItem(),getStyle(),Size.getSelectedIndex() +8);}public void cancel(){Name.select(FontName);Size.select(FontSize);setStyle();Text.setFont(getFont());this.setVisible(false);}public void setStyle(){if(FontStyle==0 || FontStyle==2)Bold.setSelected(false);else Bold.setSelected(true);if(FontStyle==0 || FontStyle==1)Italic.setSelected(false);else Italic.setSelected(true);}public int getStyle(){int bold=0,italic=0;if(Bold.isSelected()) bold=1;if(Italic.isSelected()) italic=1;return bold+italic*2;}public void windowActivated(WindowEvent arg0) {}public void windowClosed(WindowEvent arg0) {}public void windowDeactivated(WindowEvent arg0) {}public void windowDeiconified(WindowEvent arg0) {}public void windowIconified(WindowEvent arg0) {}public void windowOpened(WindowEvent arg0) {} }//创建关于对话框class AboutDialog extends JDialog implements ActionListener{ public JButton OK,Icon;public JLabel Name,Version,Author,Java;public JPanel Panel;AboutDialog(JFrame owner) {super(owner,"关于",true);OK=new JButton("OK");Icon=new JButton(new ImageIcon("icons\\edit.gif"));Name=new JLabel("Notepad");Version=new JLabel("Version 1.0");Java=new JLabel("JRE Version 6.0");Author=new JLabel("Copyright (c) 11-5-2012 By Jianmin Chen");Panel=new JPanel();Color c=new Color(0,95,191);Name.setForeground(c);Version.setForeground(c);Java.setForeground(c);Author.setForeground(c);Panel.setBackground(Color.white);OK.setFocusable(false);this.setBounds(250,200,280, 180);this.setResizable(false);this.setLayout(null);Panel.setLayout(null);OK.addActionListener(this);Icon.setFocusable(false);Icon.setBorderPainted(false);Author.setFont(new Font(null,Font.PLAIN,11));Panel.add(Icon);Panel.add(Name);Panel.add(Version);Panel.add(Author);Panel.add(Java);this.add(Panel);this.add(OK);Panel.setBounds(0, 0, 280, 100);OK.setBounds(180, 114, 72, 26);Name.setBounds(80, 10, 160, 20);Version.setBounds(80, 27, 160, 20);Author.setBounds(15, 70, 250, 20);Java.setBounds(80, 44, 160, 20);Icon.setBounds(16, 14, 48, 48);}public void actionPerformed(ActionEvent e) { this.setVisible(false);}}}//创建记事本public class ChenJianmin {public static void main(String[] args){EventQueue.invokeLater(new Runnable() {public void run() {NotePad notePad=new NotePad();notePad.setTitle("记事本");notePad.setVisible(true);notePad.setBounds(100,100,800,600);notePad.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}});}}。
记事本代码
![记事本代码](https://img.taocdn.com/s3/m/d3625c68960590c69fc37620.png)
记事本代码#include<iostream.h>#include<string.h>#include<ctype.h> //为了以下使用isdigit(string)函数作铺垫typedef struct node{char a[100]; //每行100字符node * next; //关于此处next的作用还不清楚,但不可去掉}node;class notepad{public:notepad(){i=1;line=0;}~notepad(){}void operator_interface();void input();void ct_input();void delete1();void copy();void paste();void open();void save();char * find();void print();char store[100]; //储存需复制内容private:char * ptr_array[100]; //指针数组,记录100行行指针int linelen[100]; //最大100行int line; //当前总行数char d[30]; //记录操作数据int k,l; //记录当前查找行ilint i; //文档录入初始标记};void notepad::operator_interface(){cout<<"********************************************************"<<en dl;cout<<"***0.继续录入文档"<<endl;cout<<"***1.输入文档内容"<<endl;cout<<"***2.删除某些内容"<<endl;cout<<"***3.复制某些内容"<<endl;cout<<"***4.粘贴某些内容"<<endl;cout<<"***5.打开文档内容"<<endl;cout<<"***6.是否保存文档"<<endl;cout<<"***7.获取操作帮助"<<endl;cout<<"***8.我要结束操作"<<endl;cout<<"********************************************************"<<en dl;}void notepad::input(){-99"<<endl; cout<<"输入总行数,格式:01char e[10];cin>>e;char *lin=e;if(*(lin+2)=='\0'&&isdigit(*lin)&&isdigit(*(lin+1))){line=(*lin-'0')*10+(*(lin+1)-'0');if(line!=0){cout<<"请输入各行内容"<<endl;while(i<=line){cout<<"第"<<i<<"行 ";node *p=new node;cin>>p->a;ptr_array[i]=p->a;linelen[i]=strlen(p->a);i++;}}else cout<<"你输入的行数有误"<<endl;}else cout<<"你输入的行数有误"<<endl; }void notepad::ct_input(){if(line!=0){int i=line+1;cout<<"输入要录入的总行数,格式:01-99"<<endl;char e[10];cin>>e;char *lin=e;if(*(lin+2)=='\0'&&isdigit(*lin)&&isdigit(*(lin+1))){ line=line+(*lin-'0')*10+(*(lin+1)-'0');if(line!=0){cout<<"请输入各行内容"<<endl;while(i<=line){cout<<"第"<<i<<"行 ";node *p=new node;cin>>p->a;ptr_array[i]=p->a;linelen[i]=strlen(p->a);i++;}}else cout<<"你输入的行数有误"<<endl;}else cout<<"你输入的行数有误"<<endl;}else cout<<"当前文档并无内容,请先输入1录入文档"<<endl; }void notepad::print(){cout<<endl<<endl;int j=1;cout<<"当前文档内容为:"<<endl;while(j<=line){cout<<"第"<<j<<"行 ";char *q=ptr_array[j];while(*q!='\0'){cout<<*q;q++;}cout<<endl;j++;}cout<<endl;}char * notepad::find(){ //暂未解决跨行查找问题k=1;cin>>d;l=strlen(d);char *n=d;int c=1;char *m=ptr_array[k];while(k<=line){if(*m=='\0'){k=k+1;if(k<=line)m=ptr_array[k];}if(*m!='\0'&&*m!=*n)m++;while(*n!='\0'&&*m!='\0'&&*m==*n){ m=m+1;n=n+1;c=c+1;}if(*n=='\0'){return m-c+1;}else {n=d;c=1;}}return NULL;}void notepad::delete1(){char * dp1;char * dp2;cout<<"请输入要删除的文本前几位字符,注意区分"<<endl;dp1=find();int l1=k;cout<<"请输入要删除的文本末几位字符,注意区分"<<endl;dp2=find();int l2=k;if(dp1==NULL||dp2==NULL||l1>l2)cout<<"输入错误"<<endl;else{dp2=dp2+l;if(l1==l2){while(*dp2!='\0'){*dp1=*dp2;dp1++;dp2++;}*dp1='\0';linelen[l1]=strlen(ptr_array[l1]);}else {if(l1+1<l2){for(intt1=l1+1,t2=l2;t2<=line;t1++,t2++)ptr_array[t1]=ptr_array[t2]; line=line-l2+l1+1;l2=l1+1;}*dp1='\0';char *dp21=ptr_array[l2];while(*(dp2-1)!='\0'){*dp21=*dp2;dp21++;dp2++;}linelen[l1]=strlen(ptr_array[l1]);linelen[l2]=strlen(ptr_array[l2]);}if(linelen[l1]==0){for(int v=l1;v<=line;v++)ptr_array[v]=ptr_array[v+1]; line--;}if(linelen[l2]==0){for(int v=l2;v<=line;v++)ptr_array[v]=ptr_array[v+1]; line--;}}}void notepad::copy(){char * cp1;char * cp2;cout<<"请输入要复制的文本前几位字符,注意区分"<<endl; cp1=find();int l1=k;cout<<"请输入要复制的文本末几位字符,注意区分"<<endl; cp2=find();int l2=k;char *pt=store;if(cp1!=NULL&&cp2!=NULL&&l1<=l2){cp2=cp2+l;while(cp1!=cp2){if(*cp1=='\0'){l1++;cp1=ptr_array[l1];}else {*pt=*cp1;pt++;cp1++;}}*pt='\0';}else cout<<"输入错误"<<endl; }void notepad::paste(){cout<<"请输入要粘贴位置的前几位字符(在首字符后粘贴)"<<endl; char *pat=find();if(pat!=NULL){int choice2;cout<<"请选择要粘贴内容:1/从内存中0/我自己输入"<<endl; cin>>choice2;if(!choice2)cin>>store;char *ppt=store;for(char *pat1=pat;*(pat1+1)!='\0';pat1++); //定位至末尾int pl=strlen(store);*(pat1+pl+1)='\0';while(pat1!=pat){ //移位*(pat1+pl)=*pat1;pat1--;}pat++;for(int u=1;u<=pl;u++){*pat=*ppt;ppt++;pat++;}linelen[k]=linelen[k]+pl;}else cout<<"输入错误"<<endl;}void notepad::open(){print();}void notepad::save(){cout<<"是否保存文件,1/是0/否"<<endl;char g[10];int choice1;cin>>g;char *choi=g;if(*(choi+1)=='\0'&&isdigit(*choi)){ choice1=*choi-'0';if(choice1==1)cout<<"文件已保存"<<endl; else if(choice1==0){for(int w=1;w<=line;w++){ //相当于析构函数的作用ptr_array[w]=NULL;linelen[w]=0;}line=0;}else cout<<"输入错误"<<endl;}else cout<<"输入错误"<<endl; }void main(){cout<<"欢迎使用本程序,您可以在要输入文档内容时通过切换输入法实现输入汉字,byhk"<<endl;notepad b;b.operator_interface();char f[10];int choice;cin>>f;char *choic=f;if(*(choic+1)=='\0'&&isdigit(*choic)){ //错误输入处理机制choice=*choic-'0';}else choice=9;while(choice!=8){switch(choice){case 0:b.ct_input();break;case 1:b.input();break;case 2:b.delete1();b.print();break;case 3:{b.copy();cout<<endl;char *p_t=b.store;int fzcd=strlen(b.store);cout<<"你所要复制的内容长度为"<<endl<<fzcd<<endl; cout<<"你所要复制的内容为"<<endl;while(*p_t!='\0'){cout<<*p_t;p_t++;}cout<<endl;}break;case 4:b.paste();b.print();break;case 5:b.open();break;case 6:b.save();break;case 7:b.operator_interface();break;case 8:break;default:break;}if(choice==9||(choice>=0&&choice<=7)){ //输入错误时的操作及输入正确时 //的继续操作判断if(choice==9)cout<<"你输入的操作有误,请重新输入,输入 7 获取操作帮助"<<endl;else cout<<"继续你的操作,输入 7 获取操作帮助"<<endl;cin>>f;choic=f;if(*(choic+1)=='\0'&&isdigit(*choic)) //错误输入处理机制choice=*choic-'0';else choice=9;}}cout<<"感谢您的使用"<<endl; }。
记事本程序源代码汇总
![记事本程序源代码汇总](https://img.taocdn.com/s3/m/8986f4085f0e7cd1842536b3.png)
import java.awt.event.*;import java.awt.*;import java.io.*;import ng.String;class jsb implements ActionListener{Dialog bb;String strt;int i;FileDialog fd;File file;public Frame f;public TextArea p1;public MenuBar menubar;public Menu menu1,menu2,menu3;public MenuItem item1,item2,item3,item4,item5,item6,item7,item8,item9,item10; jsb(String s{ i=0;f=new Frame(s;p1=new TextArea("";f.setSize(500,500;f.setBackground(Color.white;f.setVisible(true;menubar=new MenuBar(;menu1=new Menu("文件";menu2=new Menu("编辑";menu3=new Menu("帮助";item1=new MenuItem("新建";item2=new MenuItem("打开";item3=new MenuItem("保存";item4=new MenuItem("另存为";item5=new MenuItem("退出";item6=new MenuItem("全选";item7=new MenuItem("复制";item8=new MenuItem("剪切";item9=new MenuItem("粘贴";item10=new MenuItem("关于";f.addWindowListener(new WindowAdapter({public void windowClosing(WindowEvent e {f.setVisible(false;System.exit(0;}};menu1.add(item1;menu1.add(item2;menu1.add(item3;menu1.add(item4;menu1.add(item5;menu2.add(item6;menu2.add(item7;menu2.add(item8;menu2.add(item9;menu3.add(item10;menubar.add(menu1;menubar.add(menu2;menubar.add(menu3;f.setMenuBar(menubar;item1.addActionListener(this;item2.addActionListener(this;item3.addActionListener(this;item4.addActionListener(this;item5.addActionListener(this;item6.addActionListener(this;item7.addActionListener(this;item8.addActionListener(this;item9.addActionListener(this;item10.addActionListener(this;f.setLayout(new GridLayout(1,1;f.add(p1;f.pack(;}public void actionPerformed(ActionEvent e { String ss;ss=p1.getText(.trim(;if (e.getSource(==item5{if (i==0 &&(ss.length(!=0{bc(;}else{System.exit(0;}}if (e.getSource(==item1{if (i==0&&(ss.length(!=0{bc(;}else{p1.setText("";i=0;f.setTitle("文件对话框"; } }if (e.getSource(==item2{fd=new FileDialog(f,"打开文件",0;fd.setVisible(true;try{file=new File(fd.getDirectory(,fd.getFile(;f.setTitle(fd.getFile(+"文件对话框"; FileReader fr=new FileReader(file; BufferedReader br=new BufferedReader(fr; String line = null;String view = "";while((line=br.readLine(!=null{view += line+"\n";}p1.setText(view;br.close(;fr.close(;}catch(IOException expIn{}}if (e.getSource(==item3{if (i==0{bc(;}else{try{file=new File(fd.getDirectory(,fd.getFile(;f.setTitle(fd.getFile(+"--记事本";FileWriter fw=new FileWriter(file; BufferedWriter bw=new BufferedWriter(fw; String s =p1.getText(;s = s.replaceAll("\n","\r\n";bw.write(s;bw.flush(;bw.close(;fw.close(;i=1;}catch(IOException expOut{i=0;}}}if (e.getSource(==item4{bc(;}if (e.getSource(==item10{bb=new Dialog(f,"关于";Label l1=new Label("本记事本的完成感谢老师和同学的帮助!!"; bb.add(l1; bb.setSize(250,150;bb.setBackground(Color.white;bb.show(;bb.addWindowListener(new WindowAdapter({public void windowClosing(WindowEvent e{bb.setVisible(false;bb.dispose(;}};}if (e.getSource(==item6{p1.setSelectionStart(0;p1.setSelectionEnd(p1.getText(.length(; }if (e.getSource(==item7{try{String str=p1.getSelectedText(;if(str.length(!=0{strt=str;}}catch(Exception ex{}}if (e.getSource(==item8{try{String str=p1.getSelectedText(;if(str.length(!=0{p1.replaceRange("",p1.getSelectionStart(,p1.getSelectionEnd(; } }catch(Exception ex{}}if (e.getSource(==item9{if(strt.length(>0{p1.insert(strt,p1.getCaretPosition(;}}}public void bc({fd=new FileDialog(f,"保存文件",1;fd.setVisible(true;try{file=new File(fd.getDirectory(,fd.getFile(;f.setTitle(fd.getFile(+"--记事本"; FileWriter fw=new FileWriter(file; BufferedWriter bw=new BufferedWriter(fw; String s =p1.getText(;s = s.replaceAll("\n","\r\n";bw.write(s;bw.flush(;bw.close(;fw.close(;i=1;}catch(IOException expOut{}} } public class EX0101 { public static void main(String args[] {jsb dd=new jsb("我的记事本";} }。
使用Windows自带的记事本编写简单代码
![使用Windows自带的记事本编写简单代码](https://img.taocdn.com/s3/m/7ed8e7e4c67da26925c52cc58bd63186bceb922a.png)
使用Windows自带的记事本编写简单代码在如今数字化的时代,编程不再是专业程序员的专属技能,普通人也可以通过简单的工具和基础的知识来体验编程的乐趣。
Windows 自带的记事本就是这样一个容易上手的工具,它虽然看似简单,但却能帮助我们编写一些简单的代码。
首先,让我们来了解一下记事本。
记事本是 Windows 操作系统中一个基本的文本编辑工具,它没有复杂的功能和花哨的界面,只有纯粹的文字编辑区域。
但这恰恰为我们编写代码提供了一个干净、简洁的环境。
当我们决定使用记事本编写代码时,第一步就是打开它。
在Windows 系统中,您可以通过点击“开始”菜单,然后在搜索框中输入“记事本”来找到并打开它。
或者,您也可以按下快捷键“Windows +R”,在弹出的“运行”对话框中输入“notepad”并回车。
接下来,让我们从一个简单的 HTML 代码开始入手。
HTML(超文本标记语言)是用于创建网页的基础语言。
以下是一个简单的 HTML代码示例,用于创建一个包含标题和段落的网页:```html<!DOCTYPE html><html><head><title>我的第一个网页</title></head><body><h1>这是一个标题</h1><p>这是一个段落。
</p></body></html>```在记事本中输入上述代码后,点击“文件”菜单,选择“另存为”。
在“文件名”框中,输入“my_first_webpagehtml”(注意,一定要加上“html”扩展名,否则浏览器无法正确识别它为 HTML 文件),然后选择保存类型为“所有文件”,最后选择一个您想要保存的位置,点击“保存”。
保存完成后,找到您保存的文件,双击它,它应该会在您的默认浏览器中打开,显示出您刚刚编写的网页内容,包含一个标题和一个段落。
除了 HTML,我们还可以使用记事本编写 Python 代码。
JAVA--简单记事本源代码
![JAVA--简单记事本源代码](https://img.taocdn.com/s3/m/59dab440777f5acfa1c7aa00b52acfc789eb9f8a.png)
JAVA--简单记事本源代码import javax.swing.JFrame;import javax.swing.JTextArea;import java.awt.*;import java.awt.event.*;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.FileReader;import java.io.FileWriter;import javax.swing.*;import javax.swing.plaf.FileChooserUI;public class notepad extends JFrame implements ActionListener{//定义所需要的组件JTextArea jta=null;JMenuBar jmb=null;JMenu jm=null;JMenuItem jmi1=null;JMenuItem jmi2=null;public static void main(String[]args){new notepad();}public notepad(){//把组件添加到窗体上jta=new JTextArea();jmb=new JMenuBar();this.add(jta);this.setJMenuBar(jmb);//设置窗体属性this.setTitle("简易记事本");this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setSize(400, 300);this.setVisible(true);//把菜单添加进菜单条jm=new JMenu("⽂件");jm.setMnemonic('f');jmb.add(jm);//把⼦菜单加⼊⾄菜单jmi1=new JMenuItem("打开");jmi2=new JMenuItem("保存");jmi1.setActionCommand("open");jmi2.setActionCommand("save");jm.add(jmi1);jm.add(jmi2);//为两个字菜单注册事件监听jmi1.addActionListener(this);jmi2.addActionListener(this);}public void actionPerformed(ActionEvent e){//对点击了打开进⾏处理if(e.getActionCommand().equals("open")){//创建⼀个⽂件选择组件JFileChooser jfc1=new JFileChooser();//设置⽂件选择器的名字jfc1.setDialogTitle("请选择⽂件....");//设置⽂件选择组件的类型(打开类型)jfc1.showOpenDialog(null);//显⽰该组件jfc1.setVisible(true);//获取选择⽂件的绝对路径String s;s=jfc1.getSelectedFile().getAbsolutePath();//将该⽂件显⽰到记事本上BufferedReader br=null;FileReader fr=null;try{//创建⼀个带缓冲的⽂件读取对象fr=new FileReader(s);br=new BufferedReader(fr);String text="";String m=null;//循环读取⽂件while((m=br.readLine())!=null){text+=m+"\r\n";}//将读取的结果打印到记事本上⾯this.jta.setText(text);}catch(Exception e1){e1.printStackTrace();}finally{//关掉打开的⽂件try{br.close();fr.close();}catch(Exception e2){e2.printStackTrace();}}}else if(e.getActionCommand().equals("save")){//创建⼀个⽂件选择组件JFileChooser jfc=new JFileChooser();//设置⽂件选择的名称jfc.setDialogTitle("另存为");//设置⽂件选择组件的类型(保存类型)jfc.showSaveDialog(null);//显⽰该组件jfc.setVisible(true);//获取选择⽂件的绝对路径String filename;filename=jfc.getSelectedFile().getAbsolutePath(); //将记事本内的⽂本保存⾄该路径BufferedWriter bw=null;FileWriter fw=null;try{//创建⽂件输出⽂件fw=new FileWriter(filename);bw=new BufferedWriter(fw);//获取⽂本String outtext="";outtext=this.jta.getText();//输出⽂本fw.write(outtext);}catch(Exception e2){e2.printStackTrace();}finally{//关闭打开的输出⽂件try{bw.close();fw.close();}catch(Exception e3){e3.printStackTrace();}}}}}。
记事本源代码
![记事本源代码](https://img.taocdn.com/s3/m/a84b3d1bfad6195f312ba6c1.png)
import java.awt.*;import java.awt.event.*;import java.io.*;import java.awt.datatransfer.*;class MyMenuBar extends MenuBar{public MyMenuBar(Frame parent){parent.setMenuBar(this);}public void addMenus(String [] menus){for(int i=0;i<menus.length;i++)add(new Menu(menus[i]));}public void addMenuItems(int menuNumber,String[] items){for(int i=0;i<items.length;i++){if(items[i]!=null)getMenu(menuNumber).add(new MenuItem(items[i]));else getMenu(menuNumber).addSeparator();}}public void addActionListener(ActionListener al){for(int i=0;i<getMenuCount();i++)for(int j=0;j<getMenu(i).getItemCount();j++)getMenu(i).getItem(j).addActionListener(al);}}class MyFile{private FileDialog fDlg;public MyFile(Frame parent){fDlg=new FileDialog(parent,"",FileDialog.LOAD);}private String getPath(){return fDlg.getDirectory()+"\\"+fDlg.getFile();}public String getData() throws IOException{fDlg.setTitle("打开");fDlg.setMode(FileDialog.LOAD);fDlg.setV isible(true);BufferedReader br=new BufferedReader(new FileReader(getPath()));StringBuffer sb=new StringBuffer();String aline;while((aline=br.readLine())!=null)sb.append(aline+'\n');br.close();return sb.toString();}public void setData(String data) throws IOException{fDlg.setTitle("保存");fDlg.setMode(FileDialog.SA VE);fDlg.setV isible(true);BufferedWriter bw=new BufferedWriter(new FileWriter(getPath()));bw.write(data);bw.close();}}class MyClipboard{private Clipboard cb;public MyClipboard(){cb=Toolkit.getDefaultToolkit().getSystemClipboard();}public void setData(String data){cb.setContents(new StringSelection(data),null);}public String getData(){Transferable content=cb.getContents(null);try{return (String) content.getTransferData(DataFlavor.stringFlavor);//DataFlavor.stringFlavor会将剪贴板中的字符串转换成Unicode码形式的String 对象。
记事本源代码
![记事本源代码](https://img.taocdn.com/s3/m/093166cd0c22590102029d45.png)
//记事本源代码package jishiben;import java.awt.*;import javax.swing.*;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;import java.awt.event.*;import java.io.*;import java.util.Calendar;import jishiben.FWindow.StyleDialog;public class FristWindow {public static void main(String[] args) {// TODO Auto-generated method stubnew FWindow("记事本");}}class FWindow extends JFrame implements ActionListener,WindowListener,ItemListener { public static Frame frame;JMenuBar menuBar;JPopupMenu menu;//用户在菜单栏上选择项时显示的菜单JMenu menu1,menu2,menu3,menu4,menu5;JMenuItemitem1,item2,item3,item4,item5,item21,item22,item23,item24,item25,item26,item27,item31,item3 2,item41,item51,item52;JMenuItem itemCopy,itemCut,itemPaste;JTextArea text;//显示纯文本的多行区域JScrollPane scrollPane;JComboBox listFont,listFSize;int save_status=0,status=0,huanhang_count=0;FWindow(String s){//窗口的监听addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent event)//关闭窗口的事件{if(save_status==0){//JOptionPane弹出要求用户提供值或向其发出通知的标准对话框//showConfirmDialog询问一个确认问题int check=JOptionPane.showConfirmDialog(null,"文件的文字已经改变,想保存文件吗?","警告",JOptionPane.YES_NO_CANCEL_OPTION);if(check==0){saveFile(status);}if (check==1) {System.exit(0);}if (check==2) {dispose();}}}});//位置setTitle("记事本");setSize(700,400);setLocation(120, 120);menuBar=new JMenuBar();setJMenuBar(menuBar);text=new JTextArea(30,40);text.setLineWrap(true);//滚动条scrollPane=new JScrollPane(text);//文本框的滚动条add(scrollPane);scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWA YS);scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);menu=new JPopupMenu();menu1=new JMenu("文件");menu1.addActionListener(this);//监听文件菜单menu2=new JMenu("编辑");menu3=new JMenu("格式");menu4=new JMenu("查看");menu5=new JMenu("帮助");menuBar.add(menu1);menuBar.add(menu2);menuBar.add(menu3);menuBar.add(menu4);menuBar.add(menu5);//文件菜单下菜单项的创建并监听item1=new JMenuItem("新建");item1.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubif (e.getSource()==item1) {text.setText("");this.setTitle("无标题- 记事本");}}private void setTitle(String string){// TODO Auto-generated method stub}});//文件菜单下菜单项的打开并监听item2=new JMenuItem("打开");item2.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubif (e.getSource()==item2) {File fl;JFileChooser jfc1=new JFileChooser("F:/");//选择打开文件的位置int num1=jfc1.showOpenDialog(null);if (num1==JFileChooser.APPROVE_OPTION) {try {fl=jfc1.getSelectedFile();this.setTitle(fl.getName());FileReader fr=new FileReader(fl);BufferedReader br=new BufferedReader(fr);String str;while((str=br.readLine())!=null){text.setText(str);}fr.close();br.close();} catch (FileNotFoundException e1) {// TODO: handle exceptione1.printStackTrace();}catch (IOException e2) {// TODO: handle exceptione2.printStackTrace();}}}}//p12方法private void setTitle(String name){}});//文件菜单下菜单项的保存并监听item3=new JMenuItem("保存");item3.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubif (e.getSource()==item3) {File f2=null;JFileChooser jfc2=new JFileChooser();int num2=jfc2.showSaveDialog(null);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(text.getText());bw.close();fw.close();} catch (IOException e2) {// TODO: handle exceptione2.printStackTrace();}}}}private void setTitle(String name){}});//另存为、退出//===================================另存为有问题===============================================//item4=new JMenuItem("另存为...");item4.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stub/*if (e.getActionCommand().equals(" 另存为")) {Frame f=new Frame(" 保存");FileDialog fd=new FileDialog(f," 文件另存为",FileDialog.SA VE);fd.setVisible(true);try {String savepath=fd.getDirectory();String savename=fd.getFile();if (savename!=null) {PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter(savepath+savename)));pw.write(text.getText(),0,text.getText().length());pw.flush();}} catch (Exception easve) {// TODO: handle exception}}*/if (e.getSource()==item4) {File f3=null;JFileChooser jfc3=new JFileChooser();int num3=jfc3.showSaveDialog(null);if(num3==JFileChooser.APPROVE_OPTION){f3=jfc3.getSelectedFile();this.setTitle(f3.getName());try {FileWriter fw=new FileWriter(f3);BufferedWriter bw=new BufferedWriter(fw);bw.write(text.getText());bw.close();fw.close();} catch (IOException e2) {// TODO: handle exceptione2.printStackTrace();}}}}private void setTitle(String name){}});item5=new JMenuItem("退出");//文件菜单下菜单项的退出并监听item5.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubif (e.getSource()==item5) {int a=JOptionPane.showConfirmDialog(null,"文件已被改变,是否保存?","提示",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(null);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(text.getText());bw.close();fw.close();} catch (IOException e2) {// TODO: handle exceptione2.printStackTrace();}this.dispose();}}}}private void setTitle(String name){}private void dispose(){}});//KeyStroke 仅能对应于按下或释放某个特定的键//返回KeyStroke 的实例,指定该键在按下或释放时是否视为已激活//CTRL_MASK Ctrl 键修饰符常量。
记事本的程序设计及代码示例
![记事本的程序设计及代码示例](https://img.taocdn.com/s3/m/be22252d7f21af45b307e87101f69e314332fafb.png)
记事本的程序设计及代码示例记事本是一种常见的应用程序,用于记录和编辑文本内容。
在本文中,我们将探讨记事本的程序设计,并给出一个基于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库创建了一个简易的记事本应用程序。
记事本程序源代码汇总
![记事本程序源代码汇总](https://img.taocdn.com/s3/m/1ef9764f6d85ec3a87c24028915f804d2a16875a.png)
记事本程序源代码汇总下面是一个简单的记事本程序的源代码:```#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.新建记事本文件:用户输入一个文件名后,在当前目录下创建一个新文件作为记事本。
用C#语言实现记事本(代码)
![用C#语言实现记事本(代码)](https://img.taocdn.com/s3/m/9d075794d4d8d15abe234e1c.png)
一记事本本章介绍如何使用Visual C# 2013设计一个Windows应用程序——记事本,通过本章的学习,可以进一步掌握MenuStrip(菜单)、ToolStrip(工具栏)、RichTextBox(高级文本框)和StatusStrip(状态栏控件)等控件的使用,以及如何使用CommonDialog(公共对话框)实现对文本的存取、格式设置等操作。
(说明:所有代码必须在英文状态下使用!)1.1 记事本简介记事本是一种常用的软件,在微软的Windows中,自带了一个记事本软件,Windows 7下的记事本软件如图1所示。
图1 Windows自带的记事本本章介绍的记事本,实现了Windows自带的记事本的部分功能外,并且还可以任意更改字体的字体类型、大小和颜色,并在状态栏中显示时间。
为了方便用户的操作,还在程序的窗体上放置了一个工具栏。
本章介绍的记事本程序具有文件的新建、打开、保存功能;文字的复制、粘贴、删除功能;字体类型、格式的设置功能;查看日期时间等功能,并且用户可以根据需要显示或者隐藏工具栏和状态栏。
接下来将详细的介绍记事本程序的设计与实现的步骤和方法。
1.2 记事本界面设计新建一个Windows窗体应用程序,并命名为“Notepad”。
本节介绍记事本程序的界面设计以及界面上各控件的属性设置。
1.打开VS2013 单击文件→新建→项目2.选择模版→Visual C# →windows→windows窗体应用程序在下面的名称写Notepad出现界面如图所示3 更改窗体名称单击窗体,→右下角属性→text 修改为“记事本”如图所示控件类型控件名称属性设置结果Form Form1 Name frmNotepadText 记事本StartPosition(起始位置)CenterScreen(中央屏幕)Size 600, 450 Anchor (抛锚,使固定)(1)界面设计新建好“Notepad”项目后,定位到记事本程序的窗体设计器窗口,然后依次在窗体上放置以下控件(各1个):(1)M enuStrip(菜单控件)。
java记事本源代码
![java记事本源代码](https://img.taocdn.com/s3/m/f9d32a01de80d4d8d15a4f83.png)
JMenuItem m13=new JMenuItem("另保存为 ");
m13.addActionListener(this);
JMenuItem m14=new JMenuItem("退出 ");
m14.addActionListener(this);
{
myfr fr=new myfr("JAVA记事本");
fr.setSize(560,395);
}
}
///////////////////////////myfr主窗体类//////////////////////////////////////
class myfr extends JFrame implements ActionListener
JTextArea txt1; //主输入文本区
File newfiles;
JPopupMenu popm; //弹出菜单声明
//JMenu m1,m2,m3,m4,m5,m6; //各菜单项
JMenu m1, m2, m3;
JMenuItem m26,m271,m34,p_copy,p_cut,p_paste,p_del;
replb.addActionListener(this);
mainpane=(JPanel)this.getContentPane();
mainpane.setLayout(new BorderLayout());
txt1=new JTextArea("",13,61);
m21.setAccelerator(keycopy);
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
}
//另存为:
private void MenuItem10_Click(object sender, EventArgs e)
{
try
{
saveFileDialog1.Title = "另存为";
stsavename = "";
this.Text = "新建-记事本";
textBox1.Modified = false;
}
}
//打开文件
StreamReader sr = new StreamReader(openFileDialog1.FileName, Encoding.Default);
stsavename = openFileDialog1.FileName;
stsavename = "";
this.Text = "新建-记事本";
break;
case DialogResult.No:
}
}
//处理异常事件
catch (Exception error)
{
MessageBox.Show(error.Message.ToString());
private void MenuItem8_Click(object sender, EventArgs e)
{
try//捕获异常事件
{
//如果当前文本内容被修改,则提示保存
if (textBox1.Modified == true)
this.Text = Path.GetFileNameWithoutExtension(stsavename) + "-记事本";
textBox1.Text = sr.ReadToEnd();
sr.Close();
//新建文本
private void MenuItem7_Click(object sender, EventArgs e)
{
//如果当前文本内容处于修改状态,则提示保存
if (textBox1.Modified == true)
{
DialogResult re = MessageBox.Show("文件" + Text + "的内容已改变,需要保存吗?", "保存文件", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
{
this.MenuItem9_Click(sender, e);
}
}
openFileDialog1.Title = "打开";
sw.Write(textBox1);
textBox1.Modified = false;
stsavename = saveFileDialog1.FileName;
}
}
//保存文件
private void MenuItem9_Click(object sender, EventArgs e)
{
//捕获异常事件
try
using System.IO;
using System.Runtime.InteropServices;
//引用类的申明
namespace WindowsApplication1//名称空间的申明
{
public partial class MainForm : Form//主窗口
if (re == DialogResult.Cancel)
{
return;
}
if (re == DialogResult.OK)
saveFileDialog1.FileName = "*.txt";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
StreamWriter sw = new StreamWriter(saveFileDialog1.FileName);
{
//提示保存对话框
DialogResult re = MessageBox.Show("文件" + this.Text + "的内容已经改变,是否需要保存?", "保存文件", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
textBox1.Modified = false;
}
}
//处理异常事件
catch (Exception er)
{
MessageBox.Show(er.Message.ToString());
case DialogResult.Cancel:
break;
}
}
else
{
textBox1.Clear();
openFileDialog1.FileName = "";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
//打开选定路径上的文件 Nhomakorabea if (stsavename == "")
{
saveFileDialog1.Title = "保存";
saveFileDialog1.FileName = "*.txt";
sw.Close();
textBox1.Modified = false;
this.Text = Path.GetFileNameWithoutExtension(saveFileDialog1.FileName) + "-记事本";
using (StreamWriter sw = new StreamWriter(saveFileDialog1.FileName))
{
sw.Write(textBox1);
switch (re)
{
case DialogResult.Yes:
this.MenuItem9_Click(sender, e);
textBox1.Clear();
}
}
}
else
{
textBox1.SaveFile(stsavename, RichTextBoxStreamType.PlainText);
using System;
using System.Collections.Generic;
using ponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
textBox1.Clear();
stsavename = "";
this.Text = "新建-记事本";
break;
sw.Close();
this.Text = Path.GetFileNameWithoutExtension(saveFileDialog1.FileName) + "-记事本";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
//保存的实现
stsavename = saveFileDialog1.FileName;
{
public MainForm()
{
InitializeComponent();
}
//
//人机交互是通过操作人员对事件的操作来实现的,以下为事件的实现代码
//