记事本代码

合集下载

我用java编写的记事本代码,分享给大家

我用java编写的记事本代码,分享给大家
backcolor.add(gray); backcolor.addSeparator();
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("粉红");

记事本代码

记事本代码
HINSTANCE hPrevInstance,//第二个参数hPrevInstance表示当前实例的前一个实例的句柄。
PSTR szCmdLine, int iCmdShow )//第三个参数lpCmdLine是一个以空终止的字符串,指定传递给应用程序的命令行参数?
{
static TCHAR szAppName[] = TEXT( "demo" ) ;
return 0 ;
case WM_SIZE:
GetClientRect(hwnd, &rect) ;
MoveWindow( hwndChild[ID_EDITBOX], 0, 0, rect.right, rect.bottom-50, TRUE ) ;//调整文本编辑区
MoveWindow( hwndChild[ID_TXTPATH], 100, rect.bottom-31, 400, 20, TRUE ) ;//调整文本路径输入框
TextOut( hdc, 800, rect.bottom-30, szLineNum, lstrlen(szLineNum) ) ;
EndPaint( hwnd, &ps ) ;
return 0 ;
case WM_COMMAND:
wmId=LOWORD(wParam);
wmEvent=HIWORD(wParam);
return -1 ;
}
else{
fwrite(content, lstrlen(content), sizeof(char), fSvae);
MessageBox(NULL, TEXT("保存成功!"), TEXT("成功"), MB_OK | MB_ICONINFORMATION) ;

c语言的记事本源代码

c语言的记事本源代码
case 4: i=0;
if((fp=fopen("tongxunlu.txt","a+"))==NULL)
{ printf(" 无法打开文件~~~\n");
}
while(!feof(fp))
{ i++;
p2=p1;
p1=(link *)malloc(LEN);
printf("Thank your use\n");
else
if(identify=='n'||identify=='N')
exit(0);
else
printf(" 请输入(Y/N):");
{ printf(" 无法打开文件~~~\n");
exit(0);
} //打开文件,并将文件中内容复制到链表中,若文件中无记录,则链表头指针为空
char identify;
// char fullname[10];
link *head,*p,*p1,*p2,*p3;
int choose;
char absorb;
int i;
head=NULL;
welcome();
head=NULL;
p2->next=NULL;
fclose(fp);
if(head==NULL)
p1=p2=(link *)malloc(LEN);
fread(p1,LEN,1,fp);
head=p1;
#include<stdio.h>
#include<stdlib.h>

记事本代码

记事本代码
}
}
//另存为:
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) + "-记事本";

C语言记事本代码

C语言记事本代码

C语言记事本代码#include<stdio.h>#include<malloc.h>#include<string.h>#include<stdlib.h>#include<ctype.h>#define NULL 0#define MAX 100typedef struct lnode{char date[MAX]; //存放数据struct lnode * prior ; //前驱struct lnode * next ; //后继int number ; //记录一个节点的字符数~如果是头节点就记录他的节点个数int quese ; //记录节点在链表中的位置}lnodetype;lnodetype * l ; //设置两个全局变量,分别是头节点指针和尾节点指针lnodetype * end ;//**********这个函数是用来初始化的**********//int iniatelist (lnodetype ** l , lnodetype ** end){(*l) = (lnodetype *)malloc (sizeof (lnodetype) ) ;if ( (*l) == NULL ){printf ("没有只够的内存空间~程序即将退出~");return 0 ;}(*l)->prior =(*l)->next = NULL ; //这是双链表(*l)->number = (*l)->quese = 0;(*end) = (*l) ;printf ("程序初始化完毕~");return 0;}//**********这个函数是用来建立节点,并且插入元素的**********// int link(lnodetype ** l, lnodetype ** end){lnodetype *s ;s = (lnodetype *)malloc ( sizeof (lnodetype) ) ;if ( s == NULL ){printf ("内存空间不够,程序即将退出~") ;return 0 ;}(*end)->next = s ;s->prior = (*end) ;(*end) = (*end)->next ;(*l)->number++ ; //增加一个节点,头节点的number就加1s->quese = (*l)->number ; //这个是记录节点在链表中的位置printf ("%d行", s->quese ) ; //这个是节点在整个链表中的位置gets(s->date) ;s -> number = strlen(s->date) ;return 0 ;}//**********这个是打印链表的函数**********//int prin (lnodetype ** l, lnodetype ** end){lnodetype * p ;int i ;int j = 0;int couter = (*l)->number ;p = (*l)->next ;for (i=0; i < couter; i++){printf ( "%d行" , i+1 ) ;j = 0;while ( ( p->date[j]>='a' && p->date[j]<='z') || (p->date[j]>='A' && p->date[j]<='z') ||p->date[j]>='0' && p->date[j]<='9'){printf ( "%c" , p->date[j] ) ;j++ ;}printf ("n") ;p = p->next ;}return 0 ;}//*********这个查找和编辑相应行的函数**********//int search (lnodetype ** l, lnodetype ** end ){int number ;scanf ("%d" , &number) ;int i ;lnodetype * p ;p = (*l)->next ;for ( i=0; i<number-1; i++ )p = p->next ;printf ("%d行" , number ) ;gets (p->date) ;return 0 ;}//**********这个是在文本文件里搜索字符串的函数**********// int searchstr(lnodetype ** l , lnodetype ** end){char ptr[100] ;int arrycouter ;int mystrcmp( char *, char * , int ) ;printf ( "ok!现在输入你查找的字符串~" ) ;scanf ( "%s" , ptr ) ;arrycouter = strlen (ptr) ;lnodetype * s ;s = (*l)->next ;char * p ;int i = 1 ;int couter = 0 ;int number = (*l)->number ;p = (char *)s->date ;while ( i && number ){// i=1是,证明没有找到,向第二个节点继续寻找while ( i && ( ( (*p >= 'a') && (*p <= 'z') ) ||( (*p >= 'A') && (*p <= 'Z') ) ) ){i = mystrcmp ( p , ptr , arrycouter );if ( i == 1 ){printf ("字符串已经在第%d行,第%d个字符开始,",s->quese, couter+1 );i = 0 ;}else{p++ ;couter++;i = 1 ;}}s = s->next ;p = (char *)s->date ;number -- ;}if ( i == 1 )printf ("字符串在本文档中不存在~");return 0 ;}//**********(1)这个函数是用来实现退出不保存功能的**********// int exitunsave(lnodetype ** l, lnodetype ** end){lnodetype * s ;while( (*l) != (*end) ){ //如果不保存的话,最好是把节点的空间都释放,节省空间s = (*end) ;(*end) = (*end)->prior ;free( s ) ;}return 0 ;}//**********(2)这个函数是用来实现退出但保存功能的**********// int quitandsave( lnodetype ** l , lnodetype ** end ){FILE * fp ;char ch ;char filename[20] ;lnodetype * p;int i ;int j ;int couter = (*l)->number ;p = (*l)->next ;printf ("请输入文件名:") ;scanf ("%s" , filename ) ;if ( (fp = fopen( filename , "w" )) == NULL ){printf ("文件不能打开~n");return 0 ;}for ( i=0; i<couter; i++ ){ //有几个节点就进行多少次的存贮ch = p->date[0] ;j = 1 ;while (ch != '\0'){fputc (ch , fp) ;ch = p->date[j] ;j++ ;}p = p->next ;fputc ( '#' , fp ) ; //注意在每个节点的后面加上结束的符号}fputc ( '@' , fp ) ; //整个文件关闭的标志fclose ( fp ) ; //注意关闭文件,return 0 ;}//**********由于库函数比较字符串提供的功能不满足要求,故自己写了一个**********/int mystrcmp( char * p ,char * sour ,int number ){while ( number && (*p) == (*sour) &&( ( (*p >= 'a') && (*p <= 'z') ) || ( (*p >= 'A')&& (*p <= 'Z') ) )){p++ ;sour++ ;number-- ;}if ( number == 0 )return 1 ;elsereturn 0 ;}//**********这个函数是用来实现统计字符串功能的**********//int coutword(lnodetype ** l , lnodetype ** end){ //考虑到只统计一行的单词没有意义,故统计整个文本int yes = 1 ; //这个是进入单词的标志int no = 0 ; //在单词外面的时候的标志int i , j ,inaword ,count = 0 ;inaword = no ;lnodetype * s = (*l)->next ;for (j=0; j<(*l)->number; j++){for ( i=0; (s->date[i]>='a' && s->date[i]<='z') || (s->date[i]>='A' && s->date[i]<='z') ||(s->date[i]>='0' && s->date[i]<='9' ) ||(s->date[i]==' '); i++ ){if ( s->date[i] == ' ' )inaword = no ;elseif ( inaword == no ){inaword = yes ;count++ ; //计算单词}}s = s->next ;inaword = 0 ; //注意这里,把标志置为0了~}printf ( "n文本一共有 %d 行" , (*l)->number ) ;printf ("n此文本一共有 %d 个单词!" , count ) ;return count ;}//**********这个函数是用来实现计算文本行数功能的**********// int linecouter(lnodetype ** l , lnodetype ** end ){int couter ;couter = (*l)->number ;return couter ;}//**********这个函数是整和一上所有功能的菜单函数**********// int editmenu(lnodetype ** l , lnodetype ** end ){char choice ;char * p = "cls" ;int i = 1 ; //这两个变量是用来控制循环的int j= 1 ;system (p) ;prin (&(*l) , &(*end)) ;while (j){printf ("*********************************** e: 编辑相应行*************************************n") ;printf ("*********************************** s: 搜索字符串*************************************n") ;printf ("*********************************** t: 统计单词个数***********************************n") ;printf ("*********************************** q: 退出编辑***************************************n") ;scanf("%c",&choice);scanf("%c" , &choice) ; //,,,,莫名其妙的问题,非要两个请求输入语句才肯停下来~switch (choice){case 'e' : {i = 1 ;while (i){search( &(*l) , &(*end) );system (p) ;prin( &(*l) , &(*end) ) ;printf ("n1 继续编辑 0 结束编辑n") ;scanf ("%d" , &i) ;}}break;case 's' : {i = 1 ;while (i){searchstr( &(*l) , &(*end) );getchar();getchar();system (p) ;prin( &(*l) , &(*end) ) ;printf ("n1 继续搜索 0 结束搜索n") ; scanf ("%d" , &i) ;}}break;case 't' : {coutword ( &(*l) , &(*end) ) ;getchar() ;}break;default : return 0 ;}system (p) ;prin( &(*l) , &(*end) ) ;printf ("n1 回到编辑菜单 0 结束编辑n") ; scanf ("%d" , &j) ;if (j == 1)system (p) ;elsereturn 0 ;}return 0 ;}//**********实现第一个模块:新建空白文档**********// int newtext( lnodetype ** l ,lnodetype ** end ) {printf ( "新文本文件:n" ) ;int i = 1 ;char judstr[MAX] ;lnodetype * temp ;char jud ;char * p = "cls" ;while ( 1 ){link( &(*l) , &(*end) ) ;jud = (*end)->date[0] ;if ( jud == '5' ){ //输入‘5’结束一切temp = (*end) ;(*end) = (*end)->prior ;free (temp) ;while (1){printf ( "******************************* out :退出不保存****************************n") ;printf ( "******************************* edit :编辑信息*****************************n") ;printf ( "******************************* quit :退出而不存盘**************************n") ;printf ( "******************************* qas :退出且存盘****************************n") ;printf ( "******************************* con :继续输入~*****************************n") ;gets(judstr) ;if ( !strcmp(judstr , "out") ){exitunsave( &(*l) , &(*end) ) ;return 0 ;}elseif ( !strcmp(judstr , "qas") ){quitandsave( &(*l) , &(*end) ) ;return 0 ;}elseif ( !strcmp(judstr , "edit") ){editmenu (l , end) ;return 0;}system (p) ;}return 0 ;}}return 0 ;}//**********这个是装入文件的函数**********// int loadtaxt( char * filename ){FILE * fp ;lnodetype * l ;char ch ;int i = 0 ;char * p = "cls" ;char judstr[MAX] ;lnodetype * head ;lnodetype * end ;iniatelist ( &head , &end) ;l = end = head ;if ( (fp = fopen( filename, "r+")) == NULL ){ printf ("文件不能打开~n") ;return 0 ;}ch = fgetc ( fp ) ;while ( ch != '@' ){lnodetype *s ;s = (lnodetype *)malloc ( sizeof (lnodetype) ) ; if ( s == NULL ){printf ("内存空间不够,程序即将退出~") ;return 0 ;}end->next = s ;s->prior = end ;end = end->next ;l->number++ ;s->quese = l->number ;printf ("%d行", s->quese ) ;while ( ch != '#'){s->date[i] = ch ;ch = fgetc (fp) ;i++ ;}i = 0;while ( (end->date[i]>='a' && end->date[i]<='z') ||(end->date[i]>='A' && end->date[i]<='z') ||(end->date[i]>='0' && end->date[i]<='9' ) ||(end->date[i]==' ') ){printf ( "%c" , end->date[i] ) ;i++ ;}end->date[i] = '\0' ; //注意在节点的最好加上这个,以让退出保存功能函数知道此节点已结束printf ( "n" ) ;i = 0;ch = fgetc ( fp ) ;}fclose (fp) ;printf ("n文件成功装入~n") ;while (1){printf ( "******************************* out :退出不保存****************************n") ;printf ( "******************************* edit :编辑信息*****************************n") ;printf ( "******************************* qas :退出且存盘****************************n") ;printf ( "******************************* con :继续输入~*****************************n") ;scanf("%s",judstr);if ( !strcmp(judstr , "out") ){exitunsave( &l , &end ) ;return 0 ;}elseif ( !strcmp(judstr , "qas") ){quitandsave( &l , &end ) ;return 0 ;}elseif ( !strcmp(judstr , "edit") ){editmenu (&l , &end) ;return 0 ;}system (p) ;}return 0 ;}//**********主函数**********// void main ( void ){//iniatelist (&l , &end) ;//newtext(&l , &end) ;char filename[MAX] ;scanf ( "%s" , filename ) ; loadtaxt( filename ) ;}很不容易做的程序~~~通过编译。

记事本源代码

记事本源代码

记事本源代码先上效果图。

这个记事本操作简便,功能强⼤,在记事本的基础上添加了将内容发送短信和发送邮件的功能。

这个应⽤也已经功过了微软的认证。

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: }。

记事本程序源代码汇总

记事本程序源代码汇总

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("我的记事本";} }。

安卓记事本程序源代码(Android Notepad program source code)

安卓记事本程序源代码(Android Notepad program source code)

安卓记事本程序源代码(Android Notepad program sourcecode)1、MainActivity01.package cn.dccssq;02。

03.import android.app.listactivity;04.import android.content.intent;05.import android.database.cursor;06.import android.os.bundle;07.import android.util.log;08.import android.view.menu;09.import android.view.menuitem;10.import android.view.view;11.import android.widget.listadapter;12.import android.widget.listview;13.import android.widget.simplecursoradapter;14。

15.public类主流延伸和ListActivity很{16。

17。

私有静态最后insert_id = menu.first;18。

19。

私有静态最后delete_id = menu.first + 1;20。

21。

私有静态最后activity_create = 0;22。

23。

私有静态最后activity_edit = 1;24。

25。

私人diarydbadapter diarydb;26。

27。

私人光标光标;28。

/ * *的时候调用首次创建。

* /29。

@Override30。

public void onCreate(Bundle savedinstancestate){31。

超级onCreate(savedinstancestate);32。

setContentView(yout。

主);33。

34。

diarydb =新diarydbadapter(本);35。

Java记事本源代码(完整)

Java记事本源代码(完整)

/*** 作品:记事本* 作者:**** 功能:简单的文字编辑*/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);}});}}。

记事本代码

记事本代码
Dim s As String = InputBox("请输入要查找的文本", Me.Text, "", Me.rtbNote.Location.X + Me.rtbNote.Width / 2, Me.rtbNote.Location.Y + Height / 2)
Dim i As Integer = Me.rtbNote.Find(s)
Public Class FrmNoteBook
Private Const DEFAULTFILE As String = "NewFile"
Private currentFile As String = ""
Private bChanged As Boolean = False
End If
Me.bChanged = False
End Sub
Private Sub saveAs()
Dim dlg As New SaveFileDialog
dlg.Title = "另存为"
dlg.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*"
Me.rtbNote .Paste
End Sub
'处理剪切
Private Sub miCut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles miCut.Click
Else
Me.rtbNote.WordWrap = False
End If

简单记事本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程序设计有所帮助。

Java完整简单记事本源代码

Java完整简单记事本源代码

Java完整简单记事本源代码版权所有请勿抄袭AboutDialog.javapackage notepad;import java.awt.Color;import java.awt.Font;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;public class AboutDialog implements ActionListener{public JDialog Dialog;public JButton OK,Icon;public JLabel Name,Version,Author,Java;public JPanel Panel;AboutDialog(JFrame notepad, int x, int y) {Dialog=new JDialog(notepad,"About Notepad...",true);OK=new JButton("OK");Icon=new JButton(new ImageIcon("Notepad.jpg"));Name=new JLabel("Notepad");Version=new JLabel("Version 1.0");Java=new JLabel("JRE Version 6.0");Author=new JLabel("Copyright (c) 2011 Sky. No rights reserved.");Panel=new JPanel();Color c=new Color(0,95,191);Name.setForeground(c);Version.setForeground(c);Java.setForeground(c);Panel.setBackground(Color.WHITE);OK.setFocusable(false);Dialog.setSize(280, 180);Dialog.setLocation(x, y);Dialog.setResizable(false);Dialog.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);Dialog.add(Panel);Dialog.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) { Dialog.setVisible(false);}}ColorDialog.javapackage notepad;import java.awt.Color;import ponent;import java.awt.Font;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.KeyEvent;import java.awt.event.KeyListener;import java.awt.event.WindowEvent;import java.awt.event.WindowListener;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JTextArea;import javax.swing.JTextField;public class ColorDialog implements ActionListener, WindowListener{ public JDialog Dialog;public JLabel NFL,NBL,SFL,SBL;public JTextArea Normal,Selected;public JButton NFB,NBB,SFB,SBB,OK,Cancel,Reset;public Color NFC,NBC,SFC,SBC;public ColorChooser Chooser;public ColorDialog(JFrame notepad, int x, int y){NFC=new Color(0,0,0);NBC=new Color(249,249,251);SFC=new Color(0,0,0);SBC=new Color(191,207,223);Dialog=new JDialog(notepad,"Color...",true);NFL=new JLabel("Normal Foreground:");NBL=new JLabel("Normal Background:");SFL=new JLabel("Selected Foreground:");SBL=new JLabel("Selected Background:");Normal=new JTextArea("\n Normal 正常");Selected=new JTextArea("\n Selected 选中 ");NFB=new JButton("");NBB=new JButton("");SFB=new JButton("");SBB=new JButton("");OK=new JButton("OK");Cancel=new JButton("Cancel");Reset=new JButton("Reset");Chooser=new ColorChooser(Dialog, x+65, y-15);Normal.setEditable(false);Normal.setFocusable(false);Normal.setFont(new Font("新宋体", 0, 16)); Normal.setForeground(NFC);Normal.setBackground(NBC); Selected.setEditable(false);Selected.setFocusable(false); Selected.setFont(Normal.getFont()); Selected.setForeground(SFC); Selected.setBackground(SBC);NFB.setBackground(NFC);NBB.setBackground(NBC);SFB.setBackground(SFC);SBB.setBackground(SBC);Dialog.setLayout(null);Dialog.setLocation(x, y);Dialog.setSize(410, 220);Dialog.setResizable(false);Reset.setFocusable(false);OK.setFocusable(false);Cancel.setFocusable(false);Dialog.add(Normal);Dialog.add(Selected);Dialog.add(NFL);Dialog.add(NBL);Dialog.add(SFL);Dialog.add(SBL);Dialog.add(SBB);Dialog.add(SFB);Dialog.add(NBB);Dialog.add(NFB);Dialog.add(OK);Dialog.add(Cancel);Dialog.add(Reset);SBB.setBounds(144, 100, 60, 22);SFB.setBounds(144, 70, 60, 22);NBB.setBounds(144, 40, 60, 22);NFB.setBounds(144, 10, 60, 22);NFL.setBounds(10, 10, 130, 22);NBL.setBounds(10, 40, 130, 22);SFL.setBounds(10, 70, 130, 22);SBL.setBounds(10, 100, 130, 22);Normal.setBounds(220, 10, 174, 56);Selected.setBounds(220, 66, 174, 56);Reset.setBounds(10, 160, 74, 24);OK.setBounds(236, 160, 74, 24);Cancel.setBounds(320, 160, 74, 24);Dialog.setDefaultCloseOperation(JFrame.DO_NOTHING_ON _CLOSE);Dialog.addWindowListener(this);NFB.addActionListener(this);NBB.addActionListener(this);SFB.addActionListener(this);SBB.addActionListener(this);Reset.addActionListener(this);OK.addActionListener(this);Cancel.addActionListener(this);}public void setTextAreaColor(){Normal.setForeground(NFB.getBackground());Normal.setBackground(NBB.getBackground());Selected.setForeground(SFB.getBackground());Selected.setBackground(SBB.getBackground()); }public void cancel(){Normal.setForeground(NFC);Normal.setBackground(NBC);Selected.setForeground(SFC);Selected.setBackground(SBC);NFB.setBackground(NFC);NBB.setBackground(NBC);SFB.setBackground(SFC);SBB.setBackground(SBC);Dialog.setVisible(false);}public void actionPerformed(ActionEvent e) { Object obj=e.getSource();if(obj==Reset){NFB.setBackground(new Color(0,0,0)); NBB.setBackground(new Color(249,249,251)); SFB.setBackground(new Color(0,0,0));SBB.setBackground(new Color(191,207,223)); setTextAreaColor();}else if(obj==OK){NFC=NFB.getBackground();NBC=NBB.getBackground();SFC=SFB.getBackground();SBC=SBB.getBackground();Dialog.setVisible(false);}else if(obj==Cancel)cancel();else{Chooser.init(((Component) obj).getBackground());Chooser.Dialog.setVisible(true);((Component)obj).setBackground(Chooser.New.getBackground());setTextAreaColor();}}public void windowClosing(WindowEvent e) {cancel();}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 ColorChooser implements ActionListener,WindowListener,KeyListener{ JDialog Dialog;JButton Choice[][],Old,New,OK,Cancel;JPanel Panel;JTextField R,G,B;JLabel OldLabel,NewLabel,RL,GL,BL;ColorChooser(JDialog color,int x, int y){Dialog=new JDialog(color,true);Choice=new JButton[8][8];Panel=new JPanel();Old=new JButton("");New=new JButton("");OldLabel=new JLabel("Old:");NewLabel=new JLabel("New:");RL=new JLabel("R:");GL=new JLabel("G:");BL=new JLabel("B:");R=new JTextField("");G=new JTextField("");B=new JTextField("");OK=new JButton("OK");Cancel=new JButton("Cancel");Panel.setLayout(new GridLayout(8,8,0,0));int i=0,j=0;Color c;Choice[0][7]=newJButton("");Choice[0][7].setBackground(new Color(255,255,255));Choice[1][7]=newJButton("");Choice[1][7].setBackground(new Color(255,223,191));Choice[2][7]=newJButton("");Choice[2][7].setBackground(new Color(255,207,207));Choice[3][7]=newJButton("");Choice[3][7].setBackground(new Color(223,191,255));Choice[4][7]=newJButton("");Choice[4][7].setBackground(new Color(207,207,255));Choice[5][7]=newJButton("");Choice[5][7].setBackground(new Color(191,223,255));Choice[6][7]=newJButton("");Choice[6][7].setBackground(new Color(207,255,207));Choice[7][7]=newJButton("");Choice[7][7].setBackground(new Color(223,255,191));for(i=0;i<8;i++){c=Choice[i][7].getBackground();for(j=0;j<8;j++){if(j!=7){Choice[i][j]=new JButton("");Choice[i][j].setBackground(newColor(c.getRed()*(j+1)/8,c.getGreen()*(j+1)/8,c.getBlue()*(j +1)/8));}Choice[i][j].setFocusable(false);Choice[i][j].addActionListener(this);Panel.add(Choice[i][j]);}}Dialog.setSize(280,250);Dialog.setLayout(null);Dialog.setLocation(x, y);Dialog.setResizable(false);Dialog.add(Panel);Panel.setBounds(10, 10, 160, 160);Dialog.add(Old);Dialog.add(OldLabel);Old.setEnabled(false);Old.setBorderPainted(false);Old.setBounds(214, 10, 44, 22);OldLabel.setBounds(180, 10, 44, 22);Dialog.add(New);Dialog.add(NewLabel);New.setEnabled(false);New.setBorderPainted(false);New.setBounds(214, 32, 44, 22); NewLabel.setBounds(180, 32, 44, 22); Dialog.add(R);Dialog.add(G);Dialog.add(B);R.setBounds(214, 97, 44, 22);G.setBounds(214, 123, 44, 22);B.setBounds(214, 149, 44, 22); Dialog.add(RL);Dialog.add(GL);Dialog.add(BL);RL.setBounds(196, 97, 16, 22);GL.setBounds(196, 123, 16, 22);BL.setBounds(196, 149, 16, 22); Dialog.add(OK);Dialog.add(Cancel);OK.setFocusable(false);Cancel.setFocusable(false);OK.setBounds(106, 190, 74, 24); Cancel.setBounds(190, 190, 74, 24); OK.addActionListener(this); Cancel.addActionListener(this);G.addKeyListener(this);R.addKeyListener(this);B.addKeyListener(this);}public void setText(Color c){R.setText(String.valueOf(c.getRed()));G.setText(String.valueOf(c.getGreen()));B.setText(String.valueOf(c.getBlue()));}public void init(Color c){New.setBackground(c);Old.setBackground(c);setText(c);}public void actionPerformed(ActionEvent e) { Object obj=e.getSource();if(obj==OK) Dialog.setVisible(false);else if(obj==Cancel){New.setBackground(Old.getBackground());Dialog.setVisible(false);}else{New.setBackground(((Component) obj).getBackground());setText(New.getBackground());}}public void windowClosing(WindowEvent e) {New.setBackground(Old.getBackground());Dialog.setVisible(false);}public void keyReleased(KeyEvent e) {try{int r,g,b;if(R.getText().length()==0) r=0;else r=Integer.valueOf(R.getText());if(G.getText().length()==0) g=0;else g=Integer.valueOf(G.getT ext());if(B.getText().length()==0) b=0;else b=Integer.valueOf(B.getText());New.setBackground(new Color(r,g,b));}catch(NumberFormatExceptionnfe){setText(New.getBackground());}catch(IllegalArgumentExceptioniae){setText(New.getBackground());} }public void keyPressed(KeyEvent e) {}public void keyTyped(KeyEvent e) {}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) {}}EnsureDialog.javapackage notepad;import java.awt.BorderLayout;import java.awt.Color;import java.awt.FlowLayout;import java.awt.Font;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.WindowEvent;import java.awt.event.WindowListener;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;public class EnsureDialog implements WindowListener, ActionListener{ public int YES,NO,CANCEL,Status;public JDialog Ensure;public JButton Yes,No,Cancel;public JLabel Question;public JPanel ButtonPanel,TextPanel;EnsureDialog(JFrame notepad, int x, int y) {YES=0;NO=1;CANCEL=2;Status=CANCEL;Ensure=new JDialog(notepad,true);/** 这里的模式标志true的作用是使对话框处于notepad的上端,并且当对话框显示时进程处于停滞状态,* 直到对话框不再显示为止。

记事本代码

记事本代码
二.编辑菜单:
编辑(第一层) mnuEdit
复制(第二层) mnuCopy
剪切(第二层) mnuCut
粘贴(第二层) mnuPaste
- (第二层) mnuEditSep (分隔线)
全选(第二层) mnuSelecAll
三.搜索菜单:
搜索(第一层) mnuSearch
查找(第二层) mnuFind
End Sub
'使用说明
Private Sub mnuReadme_Click()
On Error GoTo handler
RichTextBox1.LoadFile "Readme.txt", rtfText '请写好Readme.txt文件并存入程序所在文件夹中
Me.Caption = "超级记事本:" & "使用说明"
End Sub
'粘贴
Private Sub mnuPaste_Click()
RichTextBox1.SelText = Clipboard.GetText
End Sub
'查找
Private Sub mnuFind_Click()
sFind = InputBox("请输入要查找的字、词:", "查找内容", sFind)
End Sub
'设置弹出式菜单(即在编辑框中单击鼠标右键时弹出的动态菜单)
Private Sub RichTextBox1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

记事本程序源代码汇总

记事本程序源代码汇总

记事本程序源代码汇总下面是一个简单的记事本程序的源代码:```#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)
GetConsoleScreenBufferInfo(hOut,&bInfo);
COORD coord = bInfo.dwCursorPosition; //将显存中光标信息赋予coord
*x = coord.X;
*y = coord.Y;
}
{
printf("%c",__strInput[__curStrInput]);
__curStrInput++;
}
else if(__cInput == 27) //EXC退出
{
__curStrInput = 0;
__nLastCur = 0; //字符位数标志
while(1)
{
wherexy(&x,&y); //获得当前光标位置
__cInput = getch();
if(__cInput > 47 && __cInput < 58 && __nLastCur < M && (__cInput != 48 | | __curStrInput != 0))
}
void gotoxy(int x,int y)
{
COORD coord; //windows.h中描述点的结构体
coord.X = x;
coord.Y = y;
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); //获得标准输出设备句柄
gotoxy(x + 1,y);
}
else
{
lse if(__cInput == 13) //回车处理

用C#语言实现记事本(代码)

用C#语言实现记事本(代码)

一记事本本章介绍如何使用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(菜单控件)。

记事本代码

记事本代码

package com.sgf.notepad;import android.app.ListActivity;import android.content.Intent;import android.database.Cursor;import android.os.Bundle;import android.util.Log;import android.view.ContextMenu;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.view.ContextMenu.ContextMenuInfo;import android.widget.AdapterView;import android.widget.ListView;import android.widget.SimpleCursorAdapter;/*** @author mapeijie*/public class DummyNote extends ListActivity {private int mNoteNumber = 1;protected static final int MENU_INSERT = Menu.FIRST;protected static final int MENU_DELETE = Menu.FIRST+1;protected static final int MENU_MODIFY = Menu.FIRST+1;private static final int ACTIVITY_EDIT = 0x1001;private NotesDbAdapter dbHelper;private Cursor cursor;/*** 应用的入口程序*/@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(yout.main);getListView().setEmptyView(findViewById(R.id.empty));registerForContextMenu(getListView());setAdapter();}/*** 获取要显示数据源*/private void setAdapter() {dbHelper = new NotesDbAdapter(this);dbHelper.open();fillData();}/*** 填充数据*/private void fillData() {cursor = dbHelper.getall();startManagingCursor(cursor);String[] from = new String[]{"note"};int[] to = new int[]{android.R.id.text1};SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,yout.simple_list_item_1,cursor,from,to);setListAdapter(adapter);}/*** 长按HOME 键显示两个菜单添加备忘删除备忘*/@Overridepublic boolean onCreateOptionsMenu(Menu menu) {menu.add(0,MENU_INSERT,0,R.string.addNote);menu.add(0,MENU_DELETE,0,R.string.delNote);return super.onCreateOptionsMenu(menu);}/*** 对HOME键产生的菜单的选中事件*/@Overridepublic boolean onOptionsItemSelected(MenuItem item) {switch(item.getItemId()) {case MENU_INSERT:String noteName = "Note " + mNoteNumber++;dbHelper.create(noteName);fillData();case MENU_DELETE:dbHelper.delete(getListView().getSelectedItemId());fillData();}return super.onOptionsItemSelected(item);}/*** 当选中ListView 中的一个View 时的动作* 在这里作为编辑备忘的入口*/@Overrideprotected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id);Intent intent = new Intent(this, NoteEdit.class);intent.putExtra(NotesDbAdapter.KEY_ROWID, id);startActivityForResult(intent, ACTIVITY_EDIT);}/*** startActivityForResult() 和onActivityResult() 相伴而生* 前者启动并进入另外一个activity 后者处理从另外一个activity 回来的事件*/@Overrideprotected void onActivityResult(int requestCode, int resultCode,Intent intent) {super.onActivityResult(requestCode, resultCode, intent);fillData();System.out.println("DummyNote Activity ---------------- onActivityResult");}/*** 创建长按菜单点击一个菜单1秒钟不松开即可创建一个右键菜单*/@Overridepublic void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {menu.add(0, MENU_DELETE, 0, "删除日志");menu.setHeaderTitle("要怎么处理这个项目!!!");super.onCreateContextMenu(menu, v, menuInfo);}/*** 长按菜单的选中事件*/@Overridepublic boolean onContextItemSelected(MenuItem item) {AdapterView.AdapterContextMenuInfo info;info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();switch (item.getItemId()) {case MENU_DELETE :Log.d("MENU", "item"+info.id) ;dbHelper.delete(info.id) ;fillData() ;break ;}return super.onContextItemSelected(item);}}package com.sgf.notepad;import android.app.Activity;import android.database.Cursor;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.EditText;/*** @author mapeijie*/public class NoteEdit extends Activity {private NotesDbAdapter dbHelper;private EditText field_note;private Button button_confirm;private Long rowId;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);dbHelper = new NotesDbAdapter(this);dbHelper.open();setContentView(yout.note_edit);//编辑的时候使用另一个UIfindViews();showAndUpdateNote(savedInstanceState);}private void findViews() {field_note = (EditText) findViewById(R.id.note);button_confirm = (Button) findViewById(R.id.confirm);}/*** 编辑修改备忘并且保存* @param savedInstanceState*/private void showAndUpdateNote(Bundle savedInstanceState) {if (rowId == null) {Bundle extras = getIntent().getExtras();rowId = extras != null ? extras.getLong(NotesDbAdapter.KEY_ROWID) : null;}showNote();button_confirm.setOnClickListener(new View.OnClickListener() {public void onClick(View view) {dbHelper.update(rowId, field_note.getText().toString());setResult(RESULT_OK);finish();}});}/*** 填充要编辑的备忘*/private void showNote() {if (rowId != null) {Cursor note = dbHelper.get(rowId);startManagingCursor(note);field_note.setText(note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_NOTE)));}}}package com.sgf.notepad;import java.util.Date;import android.content.ContentValues;import android.content.Context;import android.database.Cursor;import android.database.SQLException;import android.database.sqlite.SQLiteDatabase;import android.database.sqlite.SQLiteOpenHelper;/*** 数据库操作接口* @author mapeijie*/public class NotesDbAdapter {private static final String DA TABASE_NAME = "notes.db";private static final int DA TABASE_VERSION = 1;private static final String DA TABASE_TABLE = "notes";public static final String KEY_ROWID = "_id";public static final String KEY_NOTE = "note";public static final String KEY_CREATED = "created";private Context context = null;private DatabaseHelper dbHelper;private SQLiteDatabase db;String[] strCols = new String[] { KEY_ROWID, KEY_NOTE, KEY_CREATED };private static final String DA TABASE_CREATE ="create table "+DA TABASE_TABLE+"("+ "_id INTEGER PRIMARY KEY,"+ "note TEXT,"+ "created INTEGER,"+ "modified INTEGER"+ ");";public NotesDbAdapter(Context ctx) {this.context = ctx;}public NotesDbAdapter open() throws SQLException {dbHelper = new DatabaseHelper(context);db = dbHelper.getWritableDatabase();return this;}public void close() {dbHelper.close();}// add an entrypublic long create(String Note) {Date now = new Date();ContentValues args = new ContentValues();args.put(KEY_NOTE, Note);args.put(KEY_CREATED, now.getTime());return db.insert(DATABASE_TABLE, null, args);}// remove an entrypublic boolean delete(long rowId) {return db.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) > 0;}// query single entrypublic Cursor get(long rowId) throws SQLException {Cursor mCursor = db.query(true, DATABASE_TABLE, new String[] {KEY_ROWID, KEY_NOTE, KEY_CREATED }, KEY_ROWID + "=" + rowId,null, null, null, null, null);if (mCursor != null) {mCursor.moveToFirst();}return mCursor;}// get all entriespublic Cursor getall() {return db.query(DATABASE_TABLE, new String[] { KEY_ROWID, KEY_NOTE,KEY_CREATED }, null, null, null, null, null);}// updatepublic boolean update(long rowId, String note) {ContentValues args = new ContentValues();args.put(KEY_NOTE, note);return db.update(DA TABASE_TABLE, args, KEY_ROWID + "=" + rowId, null) > 0;}//初始化数据库连接时做一些动作private static class DatabaseHelper extends SQLiteOpenHelper {public DatabaseHelper(Context context) {super(context, DATABASE_NAME, null,DA TABASE_VERSION);}//Called when the database is created for the first time.@Overridepublic void onCreate(SQLiteDatabase db) {db.execSQL(DATABASE_CREATE);}//Called when the database needs to be upgraded.@Overridepublic void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {db.execSQL("DROP TABLE IF EXISTS " +DA TABASE_TABLE);onCreate(db);}//Close any open database object.@Overridepublic synchronized void close() {super.close();}//Create and/or open a database.@Overridepublic synchronized SQLiteDatabase getReadableDatabase() {return super.getReadableDatabase();}//Create and/or open a database that will be used for reading and writing.@Overridepublic synchronized SQLiteDatabase getWritableDatabase() {return super.getWritableDatabase();}//Called when the database has been opened.@Overridepublic void onOpen(SQLiteDatabase db) {super.onOpen(db);}}}。

java记事本源代码

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

记事本代码import java.awt.BorderLayout;import java.awt.Container;import java.awt.Font;import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.InputEvent; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;import javax.swing.BorderFactory; import javax.swing.JFileChooser; import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.JOptionPane; import javax.swing.JPopupMenu; import javax.swing.JScrollPane;import javax.swing.JTextArea;import javax.swing.KeyStroke;import javax.swing.ScrollPaneConstants; import javax.swing.SwingConstants;public class Notepad extends JFrame { private JMenuItem menuOpen;private JMenuItem menuSave;private JMenuItem menuSaveAs;private JMenuItem menuClose;private JMenu editMenu;private JMenuItem menuCut;private JMenuItem menuCopy;private JMenuItem menuPaste;private JMenuItem menuAbout;private JTextArea textArea;private JLabel stateBar;private JFileChooser fileChooser;private JPopupMenu popUpMenu;public Notepad() {super("新建文本文件");setUpUIComponent();super.setSize(360, 640);setUpEventListener();setVisible(true);}private void setUpUIComponent() {setSize(360, 640);// 菜单栏JMenuBar menuBar = new JMenuBar();// 设置「文件」菜单JMenu fileMenu = new JMenu("文件");menuOpen = new JMenuItem("打开");// 快捷键设置menuOpen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,InputEvent.CTRL_MASK));menuSave = new JMenuItem("保存");menuSave.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,InputEvent.CTRL_MASK));menuSaveAs = new JMenuItem("另存为");menuClose = new JMenuItem("关闭");menuClose.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q,InputEvent.CTRL_MASK));fileMenu.add(menuOpen);fileMenu.addSeparator(); // 分隔线fileMenu.add(menuSave);fileMenu.add(menuSaveAs);fileMenu.addSeparator(); // 分隔线fileMenu.add(menuClose);// 设置「编辑」菜单JMenu editMenu = new JMenu("编辑");menuCut = new JMenuItem("剪切");menuCut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,InputEvent.CTRL_MASK)); menuCopy = new JMenuItem("复制");menuCopy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,InputEvent.CTRL_MASK)); menuPaste = new JMenuItem("粘贴");menuPaste.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,InputEvent.CTRL_MASK)); editMenu.add(menuCut);editMenu.add(menuCopy);editMenu.add(menuPaste);// 设置「关于」菜单JMenu aboutMenu = new JMenu("关于");menuAbout = new JMenuItem("关于JNotePad");aboutMenu.add(menuAbout);menuBar.add(fileMenu);menuBar.add(editMenu);menuBar.add(aboutMenu);setJMenuBar(menuBar);// 文字编辑区域textArea = new JTextArea();textArea.setFont(new Font("宋体", Font.PLAIN, 16)); textArea.setLineWrap(true);JScrollPane panel = new JScrollPane(textArea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);Container contentPane = getContentPane();contentPane.add(panel, BorderLayout.CENTER);// 状态栏stateBar = new JLabel("未修改");stateBar.setHorizontalAlignment(SwingConstants.LEFT);stateBar.setBorder(BorderFactory.createEtchedBorder());contentPane.add(stateBar, BorderLayout.SOUTH);popUpMenu = editMenu.getPopupMenu();fileChooser = new JFileChooser();}private void setUpEventListener() {// 按下窗口关闭钮事件处理addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) {closeFile();}});// 菜单- 打开menuOpen.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {openFile();}});// 菜单- 保存menuSave.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {saveFile();}});// 菜单- 另存为menuSaveAs.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {saveFileAs();}});// 菜单- 关闭文件menuClose.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {closeFile();}});// 菜单- 剪切menuCut.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {cut();}});// 菜单- 复制menuCopy.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {copy();}});// 菜单- 粘贴menuPaste.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {paste();}});// 菜单- 关于menuAbout.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {// 显示对话框JOptionPane.showOptionDialog(null,"程序名称:\n JNotePad \n" +"程序设计:\n \n" +"简介:\n 一个简单的文字编辑器\n" +" 学校:南京大学金陵学院\n" +" 专业:13届通信工程\n" +" 姓名:蒋昊天\n" +" 学号:2013020400023\n\n" +" ","关于JNotePad",JOptionPane.DEFAULT_OPTION,RMA TION_MESSAGE,null, null, null);}});// 编辑区键盘事件textArea.addKeyListener(new KeyAdapter() {public void keyTyped(KeyEvent e) {processTextArea();}});// 编辑区鼠标事件textArea.addMouseListener(new MouseAdapter() {public void mouseReleased(MouseEvent e) {if(e.getButton() == MouseEvent.BUTTON3)popUpMenu.show(editMenu, e.getX(), e.getY());}public void mouseClicked(MouseEvent e) {if(e.getButton() == MouseEvent.BUTTON1)popUpMenu.setVisible(false);}});}private void openFile() {if(isCurrentFileSaved()) { // 文件是否为保存状态open(); // 打开}else {// 显示对话框int option = JOptionPane.showConfirmDialog(null, "文件已修改,是否保存?","保存文件?", JOptionPane.YES_NO_OPTION,JOptionPane.W ARNING_MESSAGE, null);switch(option) {// 确认文件保存case JOptionPane.YES_OPTION:saveFile(); // 保存文件break;// 放弃文件保存case JOptionPane.NO_OPTION:open();break;}}}private boolean isCurrentFileSaved() {if(stateBar.getText().equals("未修改")) {return false;}else {return true;}}private void open() {// fileChooser 是JFileChooser 的实例// 显示文件选取的对话框int option = fileChooser.showDialog(null, null);// 使用者按下确认键if(option == JFileChooser.APPROVE_OPTION) {try {// 开启选取的文件BufferedReader buf =new BufferedReader(new FileReader(fileChooser.getSelectedFile()));// 设定文件标题setTitle(fileChooser.getSelectedFile().toString());// 清除前一次文件textArea.setText("");// 设定状态栏stateBar.setText("未修改");// 取得系统相依的换行字符String lineSeparator = System.getProperty("line.separator");// 读取文件并附加至文字编辑区String text;while((text = buf.readLine()) != null) {textArea.append(text);textArea.append(lineSeparator);}buf.close();}catch(IOException e) {JOptionPane.showMessageDialog(null, e.toString(),"开启文件失败", JOptionPane.ERROR_MESSAGE);}}}private void saveFile() {// 从标题栏取得文件名称File file = new File(getTitle());// 若指定的文件不存在if(!file.exists()) {// 执行另存为saveFileAs();}else {try {// 开启指定的文件BufferedWriter buf =new BufferedWriter(new FileWriter(file));// 将文字编辑区的文字写入文件buf.write(textArea.getText());buf.close();// 设定状态栏为未修改stateBar.setText("未修改");}catch(IOException e) {JOptionPane.showMessageDialog(null, e.toString(),"写入文件失败", JOptionPane.ERROR_MESSAGE);}}}private void saveFileAs() {// 显示文件对话框int option = fileChooser.showSaveDialog(null);// 如果确认选取文件if(option == JFileChooser.APPROVE_OPTION) {// 取得选择的文件File file = fileChooser.getSelectedFile();// 在标题栏上设定文件名称setTitle(file.toString());try {// 建立文件file.createNewFile();// 进行文件保存saveFile();}catch(IOException e) {JOptionPane.showMessageDialog(null, e.toString(),"无法建立新文件", JOptionPane.ERROR_MESSAGE);}}}private void closeFile() {// 是否已保存文件if(isCurrentFileSaved()) {// 释放窗口资源,而后关闭程序dispose();}else {int option = JOptionPane.showConfirmDialog(null, "文件已修改,是否保存?","保存文件?", JOptionPane.YES_NO_OPTION,JOptionPane.W ARNING_MESSAGE, null);switch(option) {case JOptionPane.YES_OPTION:saveFile();break;case JOptionPane.NO_OPTION:dispose();}}}private void cut() {textArea.cut();stateBar.setText("已修改");popUpMenu.setVisible(false);}private void copy() {textArea.copy();popUpMenu.setVisible(false);}private void paste() {textArea.paste();stateBar.setText("已修改");popUpMenu.setVisible(false);}private void processTextArea() {stateBar.setText("已修改");}public static void main(String[] args) {new Notepad();}}。

相关文档
最新文档