From 6280d51cc702f142749759898715e2ddb52b48bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E6=83=B9?= <1327251308@qq.com> Date: Wed, 8 Jun 2022 16:07:33 +0800 Subject: [PATCH 01/17] =?UTF-8?q?=E6=88=91=E6=98=AF=E4=BF=A1=E7=AE=A11?= =?UTF-8?q?=E7=8F=AD27=E5=8F=B7=E7=BF=9F=E6=B1=9D=E8=92=BD=EF=BC=8C?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=8A=9F=E8=83=BD=E5=9F=BA=E6=9C=AC=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=EF=BC=8C=E8=AF=B7=E8=80=81=E5=B8=88=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E8=AF=84=E9=98=85=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/java2022spring/notebook.java | 374 +++++++++++++++++++++++++++++++ 1 file changed, 374 insertions(+) create mode 100644 src/java2022spring/notebook.java diff --git a/src/java2022spring/notebook.java b/src/java2022spring/notebook.java new file mode 100644 index 0000000..b8e8baa --- /dev/null +++ b/src/java2022spring/notebook.java @@ -0,0 +1,374 @@ +package java2022spring; +import java.awt.Color; + +import java.awt.Container; +import java.awt.FileDialog; +import java.awt.FlowLayout; +import java.awt.Menu; +import java.awt.MenuBar; +import java.awt.MenuItem; +import java.awt.MenuShortcut; +import java.awt.TextArea; +import java.awt.Toolkit; +import java.awt.Window; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.StringSelection; +import java.awt.datatransfer.Transferable; +import java.awt.datatransfer.UnsupportedFlavorException; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; +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.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.swing.JDialog; +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.JTextArea; +import javax.swing.JToolBar; +import javax.swing.UIManager; +import javax.swing.event.CaretEvent; +import javax.swing.event.CaretListener; +import javax.swing.event.UndoableEditEvent; +import javax.swing.event.UndoableEditListener; +import javax.swing.undo.CannotRedoException; +import javax.swing.undo.CannotUndoException; +import javax.swing.undo.UndoManager; +public class notebook { + private JTextArea textArea; + String filePath = ""; + Toolkit toolKit = Toolkit.getDefaultToolkit(); + Clipboard clipboard = toolKit.getSystemClipboard(); + protected UndoManager undoManager = new UndoManager(); + int linenum = 1; + int columnnum = 1; + int length = 0; + public notebook(){ + //创建记事本窗口 + final JFrame layout=new JFrame("记事本"); + layout.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);//待修改 + //layout.setBounds(100,100,500,500); + layout.setLocation(20, 30); + layout.setSize(600, 600); + layout.setResizable(true); + //创建添加文本框 + textArea=new JTextArea("",50,50); + layout.add(textArea); + textArea.setVisible(true); + textArea.requestFocusInWindow(); + //创建菜单栏 + JMenuBar menu=new JMenuBar(); + //layout.setJMenuBar(menu); + //菜单栏添加内容 + JMenu file=new JMenu("文件"); + JMenu edit=new JMenu("编辑"); + JMenu format=new JMenu("格式"); + JMenu view=new JMenu("查看"); + JMenu help=new JMenu("帮助"); + menu.add(file); + menu.add(edit); + menu.add(format); + menu.add(view); + menu.add(help); + layout.setJMenuBar(menu); + //创建菜单项 + JMenuItem newitem=new JMenuItem("新建"); + JMenuItem openitem=new JMenuItem("打开"); + JMenuItem saveitem=new JMenuItem("保存"); + JMenuItem osaveitem=new JMenuItem("另存为"); + JMenuItem closeitem=new JMenuItem("退出"); + JMenuItem back=new JMenuItem("撤消"); + JMenuItem ctrlx=new JMenuItem("剪切"); + JMenuItem ctrlc=new JMenuItem("复制"); + JMenuItem ctrlv=new JMenuItem("粘贴"); + JMenuItem delete=new JMenuItem("删除"); + JMenuItem wordwrap=new JMenuItem("自动换行"); + JMenuItem status=new JMenuItem("状态栏"); + JMenuItem helpitem=new JMenuItem("查看帮助"); + JMenuItem about=new JMenuItem("关于记事本"); + //添加菜单条 + file.add(newitem); + file.add(openitem); + file.add(saveitem); + file.add(osaveitem); + file.add(closeitem); + edit.add(back); + edit.add(ctrlx); + edit.add(ctrlc); + edit.add(ctrlv); + edit.add(delete); + format.add(wordwrap); + view.add(status); + help.add(helpitem); + help.add(about); + layout.setVisible(true); //使所有菜单条可见 + //利用监听器实现功能 + //文件菜单栏 + //实现新建功能 + newitem.addActionListener(new ActionListener(){ + @Override + public void actionPerformed(ActionEvent e) { + String con = textArea.getText(); + if(!con.equals("")){//文本域里文本不为空 + int result = JOptionPane.showConfirmDialog(null, ("是否要保存?"),("保存文件"),JOptionPane.YES_NO_CANCEL_OPTION); + //弹出是否保存弹窗 + if(result == JOptionPane.NO_OPTION){//不保存 + textArea.setText(""); + } + + else if(result == JOptionPane.CANCEL_OPTION){//取消新建 + } + + else if(result == JOptionPane.YES_OPTION){//选择保存 + JFileChooser jfc = new JFileChooser();//用于选择保存路径的文件名 + int bcf = jfc.showSaveDialog(layout); + if(bcf == JFileChooser.APPROVE_OPTION){ + try { + //保存文件 + BufferedWriter bfw = new BufferedWriter( + new FileWriter(new File(jfc.getSelectedFile().getAbsolutePath()+".txt"))); + filePath = jfc.getSelectedFile().getAbsolutePath()+".txt";//获取文件保存的路径 + bfw.write(con);//向文件写出数据 + bfw.flush(); + bfw.close();//关闭输出流 + } catch (IOException ex) { + Logger.getLogger(notebook.class.getName()).log(Level.SEVERE, null, ex); + } + new notebook();//新建文本文件 + } + } + } + else { + JOptionPane.showMessageDialog(null, ("已经是空白文档,无需新建"),("警告!"),JOptionPane.INFORMATION_MESSAGE); + + } + } + + }); + //打开文件夹功能 + openitem.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + FileDialog dialog = new FileDialog(new JFrame(),"打开",FileDialog.LOAD); + dialog.setVisible(true); + filePath = dialog.getDirectory() + dialog.getFile(); + System.out.println(filePath); + File file = new File(filePath); + BufferedReader br = null; + StringBuilder sb = new StringBuilder(); + try{ + br = new BufferedReader (new FileReader(file)); + String str = null; + while ((str = br.readLine()) != null){ + sb.append(str).append("\n"); + } + textArea.setText(sb.toString()); + } + catch(FileNotFoundException e1){ + e1.printStackTrace(); + } + catch(IOException e1){ + e1.printStackTrace(); + } + finally{ + if(br != null){ + try{ + br.close(); + } + catch(IOException e1){ + e1.printStackTrace(); + } + } + } + } + }); + //保存功能实现 + saveitem.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + FileDialog dialog = new FileDialog(new JFrame(),"保存",FileDialog.SAVE); + dialog.setVisible(true); + filePath = dialog.getDirectory() + dialog.getFile(); + if(filePath.equals("")){//没有路径时,就另存为 + JFileChooser jfc = new JFileChooser();//用于选择保存路径的文件名 + int bcf = jfc.showSaveDialog(layout);//弹出保存窗口 + if(bcf == JFileChooser.APPROVE_OPTION){ + try {//保存文件 + BufferedWriter bfw = new BufferedWriter( + new FileWriter(new File(jfc.getSelectedFile().getAbsolutePath()+".txt"))); + filePath = jfc.getSelectedFile().getAbsolutePath(); + bfw.write(textArea.getText());//向文件写出数据 + bfw.flush(); + bfw.close();//关闭输出流 + } catch (IOException ex) { + Logger.getLogger(notebook.class.getName()).log(Level.SEVERE, null, ex); + } + } + } + else{//路径不为空时,保存在原来的路径下 + try { + BufferedWriter bfw = new BufferedWriter( + new FileWriter( + new File(filePath))); + bfw.write(textArea.getText()); + bfw.flush(); + bfw.close(); + } catch (IOException ex) { + Logger.getLogger(notebook.class.getName()).log(Level.SEVERE, null, ex); + } + } + } + }); + //另存为功能实现 + osaveitem.addActionListener(new ActionListener(){ + @Override + public void actionPerformed(ActionEvent e) { + JFileChooser jfc = new JFileChooser(); + int bcf = jfc.showSaveDialog(layout); + if(bcf == JFileChooser.APPROVE_OPTION){ + try { //保存文件 + BufferedWriter bfw = new BufferedWriter( + new FileWriter(new File(jfc.getSelectedFile().getAbsolutePath()+".txt"))); + filePath = jfc.getSelectedFile().getAbsolutePath(); + bfw.write(textArea.getText()); + bfw.flush(); + bfw.close(); + } catch (IOException ex) { + Logger.getLogger(notebook.class.getName()).log(Level.SEVERE, null, ex); + } + } + } + }); + //退出功能实现 + closeitem.addActionListener(new ActionListener(){ + @Override + public void actionPerformed(ActionEvent e) { + Object[] options = { "是", "否" }; + int option = JOptionPane.showOptionDialog(null, "您确定要退出吗?","请检查是否保存!",JOptionPane.OK_CANCEL_OPTION,JOptionPane.WARNING_MESSAGE, + null,options, options[0]); + if(option == JOptionPane.OK_OPTION){ + System.exit(0); + } + } + }); + //点×关闭 + layout.addWindowListener(new WindowAdapter(){ + @Override + public void windowClosing(WindowEvent e){ + int option = JOptionPane.showConfirmDialog(null, "您确定关闭吗?","请检查是否保存!",JOptionPane.OK_CANCEL_OPTION,JOptionPane.WARNING_MESSAGE); + if(option == JOptionPane.OK_OPTION){ + ((Window) e.getComponent()).dispose(); + System.exit(0); + } + } + }); + //编辑 + //撤销功能 + textArea.getDocument().addUndoableEditListener(undoManager); + back.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if(undoManager.canUndo()) + undoManager.undo(); + else + JOptionPane.showMessageDialog(back, "空白文本,无法撤销"); + } + }); + + //剪切功能 + ctrlx.addActionListener(new ActionListener(){ + @Override + public void actionPerformed(ActionEvent e) { + String text = textArea.getSelectedText(); + StringSelection selection = new StringSelection(text); + clipboard.setContents(selection, null); + if(text.length() == 0){ + return; + } + else{ + textArea.replaceRange("", textArea.getSelectionStart(),textArea.getSelectionEnd()); + } + } + }); + //复制功能 + ctrlc.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String text = textArea.getSelectedText(); + StringSelection selection = new StringSelection(text); + clipboard.setContents(selection, null); + } + }); + //粘贴功能 + ctrlv.addActionListener(new ActionListener(){ + @Override + public void actionPerformed(ActionEvent e) { + Transferable contents = clipboard.getContents(this); + String str =null; + try {str = (String) contents.getTransferData(DataFlavor.stringFlavor); + } + catch (UnsupportedFlavorException e1) { e1.printStackTrace(); + } + catch (IOException e1) {e1.printStackTrace(); + } + if (str == null) + return; + try {textArea.replaceRange(str,textArea.getSelectionStart(),textArea.getSelectionEnd()); + } + catch (Exception e1) {e1.printStackTrace(); + } + } + }); + //删除功能 + delete.addActionListener(new ActionListener(){ + @Override + public void actionPerformed(ActionEvent e) { + textArea.replaceRange("",textArea.getSelectionStart(),textArea.getSelectionEnd()); + } + }); + //自动换行功能 + wordwrap.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + textArea.setLineWrap(true); + } + }); + //查看菜单栏 + //状态栏功能 + //统计字数功能 + + + //帮助菜单栏 + //帮助功能 + helpitem.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e){ + JOptionPane.showMessageDialog(layout,"若没有自动换行,\n请手动点击自动换行功能\n", + filePath, JOptionPane.INFORMATION_MESSAGE); + } + }); + //关于记事本功能 + about.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent e){ + JOptionPane.showMessageDialog(layout,"本记事本功能较为简陋,谢谢使用!\n"+"作者信息:\n姓名:翟汝蒽\n"+"班级:信息管理与信息系统一班\n" + +"学号:202125710127\n"+"邮箱:1327251308@qq.com",filePath, JOptionPane.INFORMATION_MESSAGE); + } + }); + } + public static void main(String []args) { + new notebook(); + } +} -- Gitee From 76cdc9ae4e71c41031a28b39e86974ecff4af625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E6=83=B9?= <1327251308@qq.com> Date: Wed, 8 Jun 2022 16:21:16 +0800 Subject: [PATCH 02/17] =?UTF-8?q?=E6=88=91=E6=98=AF=E4=BF=A1=E7=AE=A11?= =?UTF-8?q?=E7=8F=AD27=E5=8F=B7=E7=BF=9F=E6=B1=9D=E8=92=BD=EF=BC=8C?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=9F=BA=E6=9C=AC=E5=AE=8C=E6=88=90=EF=BC=8C?= =?UTF-8?q?=E8=AF=B7=E8=80=81=E5=B8=88=E6=A3=80=E6=9F=A5=E8=AF=84=E9=98=85?= =?UTF-8?q?=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/java2022spring/notebook.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/java2022spring/notebook.java b/src/java2022spring/notebook.java index b8e8baa..3efd9b7 100644 --- a/src/java2022spring/notebook.java +++ b/src/java2022spring/notebook.java @@ -55,9 +55,6 @@ public class notebook { Toolkit toolKit = Toolkit.getDefaultToolkit(); Clipboard clipboard = toolKit.getSystemClipboard(); protected UndoManager undoManager = new UndoManager(); - int linenum = 1; - int columnnum = 1; - int length = 0; public notebook(){ //创建记事本窗口 final JFrame layout=new JFrame("记事本"); -- Gitee From dda88b24381d2fcc30589b461a2ac26abbfb7f60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E6=83=B9?= <1327251308@qq.com> Date: Wed, 8 Jun 2022 16:29:40 +0800 Subject: [PATCH 03/17] =?UTF-8?q?=E6=88=91=E6=98=AF=E4=BF=A1=E7=AE=A11?= =?UTF-8?q?=E7=8F=AD27=E5=8F=B7=E7=BF=9F=E6=B1=9D=E8=92=BD=EF=BC=8C?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=8A=9F=E8=83=BD=E5=9F=BA=E6=9C=AC=E5=AE=8C?= =?UTF-8?q?=E6=88=90=EF=BC=8C=E8=AF=B7=E8=80=81=E5=B8=88=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E8=AF=84=E9=98=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/java2022spring/notebook.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/java2022spring/notebook.java b/src/java2022spring/notebook.java index 3efd9b7..59cbfcf 100644 --- a/src/java2022spring/notebook.java +++ b/src/java2022spring/notebook.java @@ -348,7 +348,6 @@ public class notebook { //状态栏功能 //统计字数功能 - //帮助菜单栏 //帮助功能 helpitem.addActionListener(new ActionListener(){ -- Gitee From c285f3b9b93268a440d1b64a9231df6868486546 Mon Sep 17 00:00:00 2001 From: Date: Wed, 8 Jun 2022 16:31:25 +0800 Subject: [PATCH 04/17] =?UTF-8?q?=E6=88=91=E6=98=AF=E4=BF=A1=E7=AE=A11?= =?UTF-8?q?=E7=8F=AD27=E5=8F=B7=E7=BF=9F=E6=B1=9D=E8=92=BD=EF=BC=8C?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=8A=9F=E8=83=BD=E5=9F=BA=E6=9C=AC=E5=AE=8C?= =?UTF-8?q?=E6=88=90=EF=BC=8C=E8=AF=B7=E8=80=81=E5=B8=88=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E8=AF=84=E9=98=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/java2022spring/notebook.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/java2022spring/notebook.java b/src/java2022spring/notebook.java index 59cbfcf..0a1965a 100644 --- a/src/java2022spring/notebook.java +++ b/src/java2022spring/notebook.java @@ -345,8 +345,9 @@ public class notebook { } }); //查看菜单栏 - //状态栏功能 - //统计字数功能 + //状态栏功能-统计字数 + + //帮助菜单栏 //帮助功能 -- Gitee From 35c481d4261380f30dfce88d50ff5bbb1fb86085 Mon Sep 17 00:00:00 2001 From: Date: Wed, 8 Jun 2022 16:35:49 +0800 Subject: [PATCH 05/17] =?UTF-8?q?=E6=88=91=E6=98=AF=E4=BF=A1=E7=AE=A11?= =?UTF-8?q?=E7=8F=AD27=E5=8F=B7=E7=BF=9F=E6=B1=9D=E8=92=BD=EF=BC=8C?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=8A=9F=E8=83=BD=E5=9F=BA=E6=9C=AC=E5=AE=8C?= =?UTF-8?q?=E6=88=90=EF=BC=8C=E8=AF=B7=E8=80=81=E5=B8=88=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E8=AF=84=E9=98=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/java2022spring/notebook.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/java2022spring/notebook.java b/src/java2022spring/notebook.java index 0a1965a..c066015 100644 --- a/src/java2022spring/notebook.java +++ b/src/java2022spring/notebook.java @@ -345,7 +345,7 @@ public class notebook { } }); //查看菜单栏 - //状态栏功能-统计字数 + //状态栏-统计字数 -- Gitee From 344e7969af7d04079163154a5b9c5017ee2701c2 Mon Sep 17 00:00:00 2001 From: Date: Wed, 8 Jun 2022 17:27:03 +0800 Subject: [PATCH 06/17] =?UTF-8?q?=E6=88=91=E6=98=AF=E4=BF=A1=E7=AE=A11?= =?UTF-8?q?=E7=8F=AD27=E5=8F=B7=E7=BF=9F=E6=B1=9D=E8=92=BD=EF=BC=8C?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=8A=9F=E8=83=BD=E5=9F=BA=E6=9C=AC=E5=AE=8C?= =?UTF-8?q?=E6=88=90=EF=BC=8C=E8=AF=B7=E8=80=81=E5=B8=88=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E8=AF=84=E9=98=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/java2022spring/notebook.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/java2022spring/notebook.java b/src/java2022spring/notebook.java index c066015..db812fc 100644 --- a/src/java2022spring/notebook.java +++ b/src/java2022spring/notebook.java @@ -58,8 +58,7 @@ public class notebook { public notebook(){ //创建记事本窗口 final JFrame layout=new JFrame("记事本"); - layout.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);//待修改 - //layout.setBounds(100,100,500,500); + layout.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); layout.setLocation(20, 30); layout.setSize(600, 600); layout.setResizable(true); -- Gitee From bf0aa149d4aca7607190a7da91cb4d2ed137e338 Mon Sep 17 00:00:00 2001 From: Date: Wed, 8 Jun 2022 17:35:44 +0800 Subject: [PATCH 07/17] =?UTF-8?q?=E6=88=91=E6=98=AF=E4=BF=A1=E7=AE=A11?= =?UTF-8?q?=E7=8F=AD27=E5=8F=B7=E7=BF=9F=E6=B1=9D=E8=92=BD=EF=BC=8C?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=8A=9F=E8=83=BD=E5=9F=BA=E6=9C=AC=E5=AE=8C?= =?UTF-8?q?=E6=88=90=EF=BC=8C=E8=AF=B7=E8=80=81=E5=B8=88=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E8=AF=84=E9=98=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/java2022spring/notebook.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/java2022spring/notebook.java b/src/java2022spring/notebook.java index db812fc..ec3e816 100644 --- a/src/java2022spring/notebook.java +++ b/src/java2022spring/notebook.java @@ -351,6 +351,7 @@ public class notebook { //帮助菜单栏 //帮助功能 helpitem.addActionListener(new ActionListener(){ + @Override public void actionPerformed(ActionEvent e){ JOptionPane.showMessageDialog(layout,"若没有自动换行,\n请手动点击自动换行功能\n", filePath, JOptionPane.INFORMATION_MESSAGE); -- Gitee From a2a62d814b5e760fa87e54104f2287a48fbd254c Mon Sep 17 00:00:00 2001 From: Date: Wed, 8 Jun 2022 17:36:50 +0800 Subject: [PATCH 08/17] =?UTF-8?q?=E6=88=91=E6=98=AF=E4=BF=A1=E7=AE=A11?= =?UTF-8?q?=E7=8F=AD27=E5=8F=B7=E7=BF=9F=E6=B1=9D=E8=92=BD=EF=BC=8C?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=8A=9F=E8=83=BD=E5=9F=BA=E6=9C=AC=E5=AE=8C?= =?UTF-8?q?=E6=88=90=EF=BC=8C=E8=AF=B7=E8=80=81=E5=B8=88=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E8=AF=84=E9=98=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/java2022spring/notebook.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/java2022spring/notebook.java b/src/java2022spring/notebook.java index ec3e816..727eff0 100644 --- a/src/java2022spring/notebook.java +++ b/src/java2022spring/notebook.java @@ -344,7 +344,7 @@ public class notebook { } }); //查看菜单栏 - //状态栏-统计字数 + //状态栏-统计字数功能 -- Gitee From 268dbfa827f3287c0d4d0535cf727a386b5ecaa2 Mon Sep 17 00:00:00 2001 From: D6DCD8D7 <1327251308@qq.com> Date: Wed, 8 Jun 2022 18:46:15 +0800 Subject: [PATCH 09/17] 111 --- src/java2022spring/notebook.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/java2022spring/notebook.java b/src/java2022spring/notebook.java index 727eff0..53b3d4f 100644 --- a/src/java2022spring/notebook.java +++ b/src/java2022spring/notebook.java @@ -344,7 +344,12 @@ public class notebook { } }); //查看菜单栏 - //状态栏-统计字数功能 + //状态栏-统计字数功能 + status.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + + } + }); -- Gitee From 6b2ffcd66040532fe97f421479d1486265fe0b63 Mon Sep 17 00:00:00 2001 From: D6DCD8D7 <1327251308@qq.com> Date: Wed, 8 Jun 2022 19:04:46 +0800 Subject: [PATCH 10/17] =?UTF-8?q?=E6=88=91=E6=98=AF=E4=BF=A1=E7=AE=A11?= =?UTF-8?q?=E7=8F=AD27=E5=8F=B7=E7=BF=9F=E6=B1=9D=E8=92=BD=EF=BC=8C?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=8A=9F=E8=83=BD=E5=9F=BA=E6=9C=AC=E5=AE=8C?= =?UTF-8?q?=E6=88=90=EF=BC=8C=E8=AF=B7=E8=80=81=E5=B8=88=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E8=AF=84=E9=98=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/java2022spring/notebook.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/java2022spring/notebook.java b/src/java2022spring/notebook.java index 53b3d4f..29dc090 100644 --- a/src/java2022spring/notebook.java +++ b/src/java2022spring/notebook.java @@ -347,7 +347,6 @@ public class notebook { //状态栏-统计字数功能 status.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - } }); -- Gitee From 099b4075dfa6fa6928a2db8d07a08e0ceb5bc9f3 Mon Sep 17 00:00:00 2001 From: D6DCD8D7 <1327251308@qq.com> Date: Wed, 8 Jun 2022 19:53:38 +0800 Subject: [PATCH 11/17] 111 --- src/java2022spring/notebook.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/java2022spring/notebook.java b/src/java2022spring/notebook.java index 29dc090..fa12907 100644 --- a/src/java2022spring/notebook.java +++ b/src/java2022spring/notebook.java @@ -347,6 +347,7 @@ public class notebook { //状态栏-统计字数功能 status.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { + int total; } }); -- Gitee From ce2ddadbcc333e086ca8b115e07fe224fd0e968c Mon Sep 17 00:00:00 2001 From: zva <1327251308@qq.com> Date: Wed, 8 Jun 2022 19:59:51 +0800 Subject: [PATCH 12/17] 111 --- src/java2022spring/notebook.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/java2022spring/notebook.java b/src/java2022spring/notebook.java index fa12907..29dc090 100644 --- a/src/java2022spring/notebook.java +++ b/src/java2022spring/notebook.java @@ -347,7 +347,6 @@ public class notebook { //状态栏-统计字数功能 status.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - int total; } }); -- Gitee From da85cd1e95d2928a37bd6fdc1fd2e2ccd6931c76 Mon Sep 17 00:00:00 2001 From: zva <1327251308@qq.com> Date: Wed, 8 Jun 2022 20:46:19 +0800 Subject: [PATCH 13/17] 777 --- src/java2022spring/notebook.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/java2022spring/notebook.java b/src/java2022spring/notebook.java index 29dc090..f151912 100644 --- a/src/java2022spring/notebook.java +++ b/src/java2022spring/notebook.java @@ -112,7 +112,7 @@ public class notebook { view.add(status); help.add(helpitem); help.add(about); - layout.setVisible(true); //使所有菜单条可见 + layout.setVisible(true);//使所有菜单条可见 //利用监听器实现功能 //文件菜单栏 //实现新建功能 -- Gitee From fe6cc69de0490d92246344df0b47d3e19e919193 Mon Sep 17 00:00:00 2001 From: zva <1327251308@qq.com> Date: Wed, 8 Jun 2022 23:44:27 +0800 Subject: [PATCH 14/17] 111 --- src/java2022spring/notebook.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/java2022spring/notebook.java b/src/java2022spring/notebook.java index f151912..db59129 100644 --- a/src/java2022spring/notebook.java +++ b/src/java2022spring/notebook.java @@ -150,7 +150,8 @@ public class notebook { } } else { - JOptionPane.showMessageDialog(null, ("已经是空白文档,无需新建"),("警告!"),JOptionPane.INFORMATION_MESSAGE); + JOptionPane.showMessageDialog(null, ("已经是空白文档,无需新建"),("警告!") + ,JOptionPane.INFORMATION_MESSAGE); } } -- Gitee From 71d70ed4bec6068cf43ad833c6010174b723b575 Mon Sep 17 00:00:00 2001 From: zva <1327251308@qq.com> Date: Wed, 8 Jun 2022 23:48:01 +0800 Subject: [PATCH 15/17] 1111 --- src/java2022spring/notebook.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/java2022spring/notebook.java b/src/java2022spring/notebook.java index db59129..d0377a5 100644 --- a/src/java2022spring/notebook.java +++ b/src/java2022spring/notebook.java @@ -256,7 +256,8 @@ public class notebook { @Override public void actionPerformed(ActionEvent e) { Object[] options = { "是", "否" }; - int option = JOptionPane.showOptionDialog(null, "您确定要退出吗?","请检查是否保存!",JOptionPane.OK_CANCEL_OPTION,JOptionPane.WARNING_MESSAGE, + int option = JOptionPane.showOptionDialog(null, "您确定要退出吗?","请检查是否保存!", + JOptionPane.OK_CANCEL_OPTION,JOptionPane.WARNING_MESSAGE, null,options, options[0]); if(option == JOptionPane.OK_OPTION){ System.exit(0); -- Gitee From 06318e1d27e88453528746c2469a1370fd98843f Mon Sep 17 00:00:00 2001 From: zva <1327251308@qq.com> Date: Thu, 9 Jun 2022 13:40:39 +0800 Subject: [PATCH 16/17] =?UTF-8?q?=E5=B7=B2=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/java2022spring/notebook.java | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/java2022spring/notebook.java b/src/java2022spring/notebook.java index d0377a5..8e1bf6f 100644 --- a/src/java2022spring/notebook.java +++ b/src/java2022spring/notebook.java @@ -28,6 +28,8 @@ import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; +import java.util.HashMap; +import java.util.Scanner; import java.util.logging.Level; import java.util.logging.Logger; @@ -349,11 +351,9 @@ public class notebook { //状态栏-统计字数功能 status.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - } + JOptionPane.showMessageDialog(status, "状态良好"); + } }); - - - //帮助菜单栏 //帮助功能 helpitem.addActionListener(new ActionListener(){ @@ -371,6 +371,20 @@ public class notebook { } }); } + public void total(String s) { + Scanner scanner=new Scanner(System.in); + String str=scanner.nextLine(); + str=s; + int sum = 0; + for (int i=0; i Date: Thu, 9 Jun 2022 13:58:08 +0800 Subject: [PATCH 17/17] 1 --- src/java2022spring/notebook.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/java2022spring/notebook.java b/src/java2022spring/notebook.java index 8e1bf6f..2683f4e 100644 --- a/src/java2022spring/notebook.java +++ b/src/java2022spring/notebook.java @@ -288,8 +288,7 @@ public class notebook { else JOptionPane.showMessageDialog(back, "空白文本,无法撤销"); } - }); - + }); //剪切功能 ctrlx.addActionListener(new ActionListener(){ @Override @@ -382,9 +381,6 @@ public class notebook { sum++; } } - - - public static void main(String []args) { new notebook(); } -- Gitee