java 实现我的记事本

由于不太会写博客,所以将运行截如下,代码有注释,需要的话可以去下载哈

下载地址:https://download.csdn.net/download/axiebuzhen/10895316

新建:新建一个文本文件

打开:调用JDK提供的“打开”对话框,选择要打开的文本文件,要求返回带路径的文件名。

保存或另存为:如果已有文件名,直接保存文件,否则调用“保存”对话框,获取文件名后保存。

退出:在退出前要判断是否保存,保存时要求如上,不保存直接退出。

撤销/重做:记录用户在编辑区的历史操作,可以进行撤销与重复。

复制/剪切/粘贴:将选中的文本复制到系统剪切板上;将选中的文本剪切到系统剪切板上;将选中的文本粘贴到系统剪切板上

全部选中:将编辑区中的文件全部选中

查找:根据向上/向下条件进行查找,或者区分大小写进行查找

替换:根据选项要求在编辑区的所有文本中查找到的全部文本

自动换行:文本编辑区是否自动换行

字体:调用“字体”对话框设置文本编辑区的字体、字形和大小

颜色:调用“颜色板”对话框设置文本编辑区的颜色

帮助主题:调用网上API文档网页

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
好的,这是一个简单的Java记事本实现示例: ```java import java.io.*; import java.util.Scanner; public class SimpleNotepad { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Welcome to Simple Notepad!"); while (true) { System.out.println("Enter '1' to create a new file, '2' to open an existing file, or '3' to exit:"); int choice = scanner.nextInt(); switch (choice) { case 1: createFile(); break; case 2: openFile(); break; case 3: System.out.println("Exiting Simple Notepad..."); System.exit(0); break; default: System.out.println("Invalid choice. Please try again."); } } } private static void createFile() { Scanner scanner = new Scanner(System.in); System.out.println("Enter the name of the file to create:"); String filename = scanner.nextLine(); try { File file = new File(filename); if (file.createNewFile()) { System.out.println("File created: " + file.getAbsolutePath()); } else { System.out.println("File already exists."); } FileWriter writer = new FileWriter(file); System.out.println("Enter text to write to the file:"); String text = scanner.nextLine(); writer.write(text); writer.close(); System.out.println("Text written to file."); } catch (IOException e) { System.out.println("Error creating file: " + e.getMessage()); } } private static void openFile() { Scanner scanner = new Scanner(System.in); System.out.println("Enter the name of the file to open:"); String filename = scanner.nextLine(); try { File file = new File(filename); if (file.exists()) { FileReader reader = new FileReader(file); BufferedReader bufferedReader = new BufferedReader(reader); String line; System.out.println("File contents:"); while ((line = bufferedReader.readLine()) != null) { System.out.println(line); } reader.close(); } else { System.out.println("File does not exist."); } } catch (IOException e) { System.out.println("Error reading file: " + e.getMessage()); } } } ``` 这个简单的记事本程序提供了三个选项:创建新文件、打开现有文件或退出程序。如果选择创建新文件,程序会要求用户输入文件名和要写入文件的文本。如果选择打开现有文件,程序会要求用户输入文件名并显示文件内容。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值