diff --git a/.classpath b/.classpath deleted file mode 100644 index ac9ce57c2f4d3a99eb1868e101f3060156474663..0000000000000000000000000000000000000000 --- a/.classpath +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/.gitignore b/.gitignore deleted file mode 100644 index ae3c1726048cd06b9a143e0376ed46dd9b9a8d53..0000000000000000000000000000000000000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/bin/ diff --git a/.idea/artifacts/0223_wuyuanzhao_text_jar.xml b/.idea/artifacts/0223_wuyuanzhao_text_jar.xml new file mode 100644 index 0000000000000000000000000000000000000000..6d0d8d9efda99002006f39647b5430fe77833476 --- /dev/null +++ b/.idea/artifacts/0223_wuyuanzhao_text_jar.xml @@ -0,0 +1,8 @@ + + + $PROJECT_DIR$/out/artifacts/0223_wuyuanzhao_text_jar + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000000000000000000000000000000000000..8019fd3ed35cb449e6e2959edb694ec21d2a2d0b --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000000000000000000000000000000000000..07115cdf15dd408d3affb9240e112578e04abf68 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000000000000000000000000000000000..f3958c7757dafe0361d8c8693c100b5dc317da3d --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000000000000000000000000000000000000..e96534fb27b68192f27f985d3879e173ec77adb8 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000000000000000000000000000000000000..94a25f7f4cb416c083d265558da75d457237d671 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000000000000000000000000000000000000..9cf963dc021ff3993903eb132d42029325669f67 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,219 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { + "keyToString": { + "ASKED_ADD_EXTERNAL_FILES": "true", + "RunOnceActivity.OpenProjectViewOnStart": "true", + "RunOnceActivity.ShowReadmeOnStart": "true", + "SHARE_PROJECT_CONFIGURATION_FILES": "true", + "WebServerToolWindowFactoryState": "false", + "last_opened_file_path": "D:/桌面/。", + "project.structure.last.edited": "工件", + "project.structure.proportion": "0.0", + "project.structure.side.proportion": "0.0" + } +} + + + + + + + + + + + + + + 1652268155998 + + + 1653311510665 + + + 1653311749636 + + + 1653311756561 + + + 1653400499228 + + + 1653489918144 + + + 1653838198520 + + + 1654096099867 + + + 1654528642557 + + + + + + + + + + + \ No newline at end of file diff --git a/.project b/.project deleted file mode 100644 index b7e8a74e9dd98bfb5b42b70cd6033510d6823948..0000000000000000000000000000000000000000 --- a/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - java2022spring - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index dbc27c5dc60ef7094a88953087ea0294b6c44a38..0000000000000000000000000000000000000000 --- a/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,14 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=17 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning -org.eclipse.jdt.core.compiler.release=enabled -org.eclipse.jdt.core.compiler.source=17 diff --git a/0223_wuyuanzhao_text.iml b/0223_wuyuanzhao_text.iml new file mode 100644 index 0000000000000000000000000000000000000000..8b2ade9842f818fc20488706c36455fd28df6d42 --- /dev/null +++ b/0223_wuyuanzhao_text.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..ee5839968a2bf86c93283efc09d40fd050b7cfa2 --- /dev/null +++ b/LICENSE @@ -0,0 +1,127 @@ + 木兰宽松许可证, 第2版 + + 木兰宽松许可证, 第2版 + 2020年1月 http://license.coscl.org.cn/MulanPSL2 + + + 您对“软件”的复制、使用、修改及分发受木兰宽松许可证,第2版(“本许可证”)的如下条款的约束: + + 0. 定义 + + “软件”是指由“贡献”构成的许可在“本许可证”下的程序和相关文档的集合。 + + “贡献”是指由任一“贡献者”许可在“本许可证”下的受版权法保护的作品。 + + “贡献者”是指将受版权法保护的作品许可在“本许可证”下的自然人或“法人实体”。 + + “法人实体”是指提交贡献的机构及其“关联实体”。 + + “关联实体”是指,对“本许可证”下的行为方而言,控制、受控制或与其共同受控制的机构,此处的控制是指有受控方或共同受控方至少50%直接或间接的投票权、资金或其他有价证券。 + + 1. 授予版权许可 + + 每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的版权许可,您可以复制、使用、修改、分发其“贡献”,不论修改与否。 + + 2. 授予专利许可 + + 每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的(根据本条规定撤销除外)专利许可,供您制造、委托制造、使用、许诺销售、销售、进口其“贡献”或以其他方式转移其“贡献”。前述专利许可仅限于“贡献者”现在或将来拥有或控制的其“贡献”本身或其“贡献”与许可“贡献”时的“软件”结合而将必然会侵犯的专利权利要求,不包括对“贡献”的修改或包含“贡献”的其他结合。如果您或您的“关联实体”直接或间接地,就“软件”或其中的“贡献”对任何人发起专利侵权诉讼(包括反诉或交叉诉讼)或其他专利维权行动,指控其侵犯专利权,则“本许可证”授予您对“软件”的专利许可自您提起诉讼或发起维权行动之日终止。 + + 3. 无商标许可 + + “本许可证”不提供对“贡献者”的商品名称、商标、服务标志或产品名称的商标许可,但您为满足第4条规定的声明义务而必须使用除外。 + + 4. 分发限制 + + 您可以在任何媒介中将“软件”以源程序形式或可执行形式重新分发,不论修改与否,但您必须向接收者提供“本许可证”的副本,并保留“软件”中的版权、商标、专利及免责声明。 + + 5. 免责声明与责任限制 + + “软件”及其中的“贡献”在提供时不带任何明示或默示的担保。在任何情况下,“贡献者”或版权所有者不对任何人因使用“软件”或其中的“贡献”而引发的任何直接或间接损失承担责任,不论因何种原因导致或者基于何种法律理论,即使其曾被建议有此种损失的可能性。 + + 6. 语言 + “本许可证”以中英文双语表述,中英文版本具有同等法律效力。如果中英文版本存在任何冲突不一致,以中文版为准。 + + 条款结束 + + 如何将木兰宽松许可证,第2版,应用到您的软件 + + 如果您希望将木兰宽松许可证,第2版,应用到您的新软件,为了方便接收者查阅,建议您完成如下三步: + + 1, 请您补充如下声明中的空白,包括软件名、软件的首次发表年份以及您作为版权人的名字; + + 2, 请您在软件包的一级目录下创建以“LICENSE”为名的文件,将整个许可证文本放入该文件中; + + 3, 请将如下声明文本放入每个源文件的头部注释中。 + + Copyright (c) [Year] [name of copyright holder] + [Software Name] is licensed under Mulan PSL v2. + You can use this software according to the terms and conditions of the Mulan PSL v2. + You may obtain a copy of Mulan PSL v2 at: + http://license.coscl.org.cn/MulanPSL2 + THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + See the Mulan PSL v2 for more details. + + + Mulan Permissive Software License,Version 2 + + Mulan Permissive Software License,Version 2 (Mulan PSL v2) + January 2020 http://license.coscl.org.cn/MulanPSL2 + + Your reproduction, use, modification and distribution of the Software shall be subject to Mulan PSL v2 (this License) with the following terms and conditions: + + 0. Definition + + Software means the program and related documents which are licensed under this License and comprise all Contribution(s). + + Contribution means the copyrightable work licensed by a particular Contributor under this License. + + Contributor means the Individual or Legal Entity who licenses its copyrightable work under this License. + + Legal Entity means the entity making a Contribution and all its Affiliates. + + Affiliates means entities that control, are controlled by, or are under common control with the acting entity under this License, ‘control’ means direct or indirect ownership of at least fifty percent (50%) of the voting power, capital or other securities of controlled or commonly controlled entity. + + 1. Grant of Copyright License + + Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable copyright license to reproduce, use, modify, or distribute its Contribution, with modification or not. + + 2. Grant of Patent License + + Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable (except for revocation under this Section) patent license to make, have made, use, offer for sale, sell, import or otherwise transfer its Contribution, where such patent license is only limited to the patent claims owned or controlled by such Contributor now or in future which will be necessarily infringed by its Contribution alone, or by combination of the Contribution with the Software to which the Contribution was contributed. The patent license shall not apply to any modification of the Contribution, and any other combination which includes the Contribution. If you or your Affiliates directly or indirectly institute patent litigation (including a cross claim or counterclaim in a litigation) or other patent enforcement activities against any individual or entity by alleging that the Software or any Contribution in it infringes patents, then any patent license granted to you under this License for the Software shall terminate as of the date such litigation or activity is filed or taken. + + 3. No Trademark License + + No trademark license is granted to use the trade names, trademarks, service marks, or product names of Contributor, except as required to fulfill notice requirements in Section 4. + + 4. Distribution Restriction + + You may distribute the Software in any medium with or without modification, whether in source or executable forms, provided that you provide recipients with a copy of this License and retain copyright, patent, trademark and disclaimer statements in the Software. + + 5. Disclaimer of Warranty and Limitation of Liability + + THE SOFTWARE AND CONTRIBUTION IN IT ARE PROVIDED WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED. IN NO EVENT SHALL ANY CONTRIBUTOR OR COPYRIGHT HOLDER BE LIABLE TO YOU FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO ANY DIRECT, OR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING FROM YOUR USE OR INABILITY TO USE THE SOFTWARE OR THE CONTRIBUTION IN IT, NO MATTER HOW IT’S CAUSED OR BASED ON WHICH LEGAL THEORY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + + 6. Language + + THIS LICENSE IS WRITTEN IN BOTH CHINESE AND ENGLISH, AND THE CHINESE VERSION AND ENGLISH VERSION SHALL HAVE THE SAME LEGAL EFFECT. IN THE CASE OF DIVERGENCE BETWEEN THE CHINESE AND ENGLISH VERSIONS, THE CHINESE VERSION SHALL PREVAIL. + + END OF THE TERMS AND CONDITIONS + + How to Apply the Mulan Permissive Software License,Version 2 (Mulan PSL v2) to Your Software + + To apply the Mulan PSL v2 to your work, for easy identification by recipients, you are suggested to complete following three steps: + + i Fill in the blanks in following statement, including insert your software name, the year of the first publication of your software, and your name identified as the copyright owner; + + ii Create a file named “LICENSE” which contains the whole context of this License in the first directory of your software package; + + iii Attach the statement to the appropriate annotated syntax at the beginning of each source file. + + + Copyright (c) [Year] [name of copyright holder] + [Software Name] is licensed under Mulan PSL v2. + You can use this software according to the terms and conditions of the Mulan PSL v2. + You may obtain a copy of Mulan PSL v2 at: + http://license.coscl.org.cn/MulanPSL2 + THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + See the Mulan PSL v2 for more details. diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF new file mode 100644 index 0000000000000000000000000000000000000000..c419093169f00118191214b6a915d303a70f847c --- /dev/null +++ b/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: text.Textbook + diff --git a/file b/file new file mode 100644 index 0000000000000000000000000000000000000000..b4ede3deb9f7cd96c0505020f53810ac59d36eac --- /dev/null +++ b/file @@ -0,0 +1,3 @@ +12312345a +是大概率是独立开关快乐 +阿松大 diff --git a/out/production/0223_wuyuanzhao_text/.idea/compiler.xml b/out/production/0223_wuyuanzhao_text/.idea/compiler.xml new file mode 100644 index 0000000000000000000000000000000000000000..8019fd3ed35cb449e6e2959edb694ec21d2a2d0b --- /dev/null +++ b/out/production/0223_wuyuanzhao_text/.idea/compiler.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/out/production/0223_wuyuanzhao_text/.idea/misc.xml b/out/production/0223_wuyuanzhao_text/.idea/misc.xml new file mode 100644 index 0000000000000000000000000000000000000000..07115cdf15dd408d3affb9240e112578e04abf68 --- /dev/null +++ b/out/production/0223_wuyuanzhao_text/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/out/production/0223_wuyuanzhao_text/.idea/modules.xml b/out/production/0223_wuyuanzhao_text/.idea/modules.xml new file mode 100644 index 0000000000000000000000000000000000000000..f3958c7757dafe0361d8c8693c100b5dc317da3d --- /dev/null +++ b/out/production/0223_wuyuanzhao_text/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/out/production/0223_wuyuanzhao_text/.idea/uiDesigner.xml b/out/production/0223_wuyuanzhao_text/.idea/uiDesigner.xml new file mode 100644 index 0000000000000000000000000000000000000000..e96534fb27b68192f27f985d3879e173ec77adb8 --- /dev/null +++ b/out/production/0223_wuyuanzhao_text/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/out/production/0223_wuyuanzhao_text/.idea/vcs.xml b/out/production/0223_wuyuanzhao_text/.idea/vcs.xml new file mode 100644 index 0000000000000000000000000000000000000000..94a25f7f4cb416c083d265558da75d457237d671 --- /dev/null +++ b/out/production/0223_wuyuanzhao_text/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/out/production/0223_wuyuanzhao_text/.idea/workspace.xml b/out/production/0223_wuyuanzhao_text/.idea/workspace.xml new file mode 100644 index 0000000000000000000000000000000000000000..d34ae11d900cbbe64e2ff7849fe8cf2b482da061 --- /dev/null +++ b/out/production/0223_wuyuanzhao_text/.idea/workspace.xml @@ -0,0 +1,219 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { + "keyToString": { + "ASKED_ADD_EXTERNAL_FILES": "true", + "RunOnceActivity.OpenProjectViewOnStart": "true", + "RunOnceActivity.ShowReadmeOnStart": "true", + "SHARE_PROJECT_CONFIGURATION_FILES": "true", + "WebServerToolWindowFactoryState": "false", + "last_opened_file_path": "D:/桌面/。", + "project.structure.last.edited": "工件", + "project.structure.proportion": "0.0", + "project.structure.side.proportion": "0.0" + } +} + + + + + + + + + + + + + + 1652268155998 + + + 1653311510665 + + + 1653311749636 + + + 1653311756561 + + + 1653400499228 + + + 1653489918144 + + + 1653838198520 + + + 1654096099867 + + + 1654528642557 + + + + + + + + + + + \ No newline at end of file diff --git a/out/production/0223_wuyuanzhao_text/0223_wuyuanzhao_text.iml b/out/production/0223_wuyuanzhao_text/0223_wuyuanzhao_text.iml new file mode 100644 index 0000000000000000000000000000000000000000..8b2ade9842f818fc20488706c36455fd28df6d42 --- /dev/null +++ b/out/production/0223_wuyuanzhao_text/0223_wuyuanzhao_text.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/out/production/0223_wuyuanzhao_text/text/Textbook$1.class b/out/production/0223_wuyuanzhao_text/text/Textbook$1.class new file mode 100644 index 0000000000000000000000000000000000000000..e8479db9a2e44cbe22aa77bd7c626d6b356025b8 Binary files /dev/null and b/out/production/0223_wuyuanzhao_text/text/Textbook$1.class differ diff --git a/out/production/0223_wuyuanzhao_text/text/Textbook.class b/out/production/0223_wuyuanzhao_text/text/Textbook.class new file mode 100644 index 0000000000000000000000000000000000000000..28ab7d50dc7ff58df190d848cda1cdab24707bac Binary files /dev/null and b/out/production/0223_wuyuanzhao_text/text/Textbook.class differ diff --git a/readme.md b/readme.md deleted file mode 100644 index 4af16add33b576d095308a1888db35774618715d..0000000000000000000000000000000000000000 --- a/readme.md +++ /dev/null @@ -1,2 +0,0 @@ -# ѧ -0103 \ No newline at end of file diff --git a/src/java2022spring/Test.java b/src/java2022spring/Test.java deleted file mode 100644 index 24deb29bfc0e5f50fdedcd21b504e77b529d48b6..0000000000000000000000000000000000000000 --- a/src/java2022spring/Test.java +++ /dev/null @@ -1,7 +0,0 @@ -package java2022spring; - -public class Test { - public static void main(String[] args) { - System.out.println("Hello world!"); - } -} diff --git a/text.txt b/text.txt new file mode 100644 index 0000000000000000000000000000000000000000..e9227da277764a61106be9cafd79b8a26a659fb7 --- /dev/null +++ b/text.txt @@ -0,0 +1 @@ +阿斯顿发生阿斯顿发生 diff --git a/text/Textbook.java b/text/Textbook.java new file mode 100644 index 0000000000000000000000000000000000000000..81d41e3f9fc9bf1dccf0fee0c587b85b57dc3012 --- /dev/null +++ b/text/Textbook.java @@ -0,0 +1,606 @@ +package text; + +import javax.swing.*; +import javax.swing.border.BevelBorder; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.text.BadLocationException; +import javax.swing.undo.UndoManager; +import java.awt.*; +import java.awt.event.*; +import java.io.*; + +import static text.Textbook.content; + +public class Textbook extends JFrame { + + public static void main(String args[]) { + Textbook textbook = new Textbook(); + textbook.setVisible(true); + } + + public File file2; + public boolean changed = false; + final JScrollPane scrollPane = new JScrollPane(); + public static JTextArea content = new JTextArea(); + boolean isLineWrap = true; + boolean chakan=true; + + public Textbook() { + + setTitle("textbook"); + setBounds(250, 250, 1000, 500); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + final JMenuBar menubar = new JMenuBar(); + setJMenuBar(menubar); + UndoManager undoManager = new UndoManager(); + //文本内容 + final JScrollPane scrollPane = new JScrollPane(); + JTextArea content = new JTextArea(); + content.getDocument().addUndoableEditListener(undoManager); + scrollPane.setViewportView(content); + add(scrollPane, BorderLayout.CENTER); + content.setLineWrap(true); + content.setWrapStyleWord(true); + // + + + //右键菜单 + JPopupMenu popupMenu = new JPopupMenu(); + JMenuItem mAll, mCopy, mCut, mPaste, mDel; + popupMenu = new JPopupMenu(); + mAll = new JMenuItem("全选(A)"); + mAll.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + content.selectAll(); + } + }); + mCopy = new JMenuItem("复制(C)"); + mCopy.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + content.copy(); + } + }); + + mCut = new JMenuItem("剪切(T)"); + mCut.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + content.cut(); + } + }); + + mPaste = new JMenuItem("粘贴(P)"); + mPaste.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + content.paste(); + } + }); + mDel = new JMenuItem("删除(D)"); + + mDel.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + content.replaceSelection(null); + } + }); + popupMenu.add(mAll); + popupMenu.add(mCopy); + popupMenu.add(mCut); + popupMenu.add(mPaste); + popupMenu.add(mDel); + JPopupMenu finalPopupMenu = popupMenu; + content.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + super.mouseClicked(e); + { + if (e.getButton() == MouseEvent.BUTTON3) { + //弹出右键菜单 + finalPopupMenu.show(Textbook.this, e.getX(), e.getY()); + } + + } + } + }); + // + + + //状态栏 + int row = 0; + int col = 0; + JPanel statusPanel = new JPanel(); + statusPanel.setBorder(new BevelBorder(BevelBorder.LOWERED)); + add(statusPanel, BorderLayout.SOUTH); + statusPanel.setPreferredSize(new Dimension(getWidth(), 16)); + statusPanel.setLayout(new BoxLayout(statusPanel, BoxLayout.X_AXIS)); + JLabel statusLabel = new JLabel("行:" + row + " 列:" + col); + statusLabel.setHorizontalAlignment(SwingConstants.LEFT); + statusPanel.add(statusLabel); + content.addMouseListener(new MouseAdapter() { + public void mousePressed(MouseEvent e) { + // 敲击左键 + if (e.getModifiers() == MouseEvent.BUTTON1_MASK) { + try { + getCurrenRowAndCol(); // 获得当前的行和列位置 + } catch (BadLocationException ex) { + throw new RuntimeException(ex); + } + } + } + + private void getCurrenRowAndCol() throws BadLocationException { + int col = 1; + int pos = content.getCaretPosition(); + //获取行数 + int row = content.getLineOfOffset(pos) + 1; + //获取列数 + col = pos - content.getLineStartOffset(row - 1) + 1; + statusLabel.setText("行:" + row + " 列:" + col); + } + + // 松开鼠标 + public void mouseReleased(MouseEvent e) { + // 敲击左键 + if (e.getModifiers() == MouseEvent.BUTTON1_MASK) { + try { + getCurrenRowAndCol(); // 获得当前的行和列位置 + } catch (BadLocationException ex) { + throw new RuntimeException(ex); + } + } + } + }); + content.addKeyListener(new KeyAdapter() { + // 按下某键 + public void keyPressed(KeyEvent e) { + try { + getCurrenRowAndCol(); // 获得当前的行和列位置 + } catch (BadLocationException ex) { + throw new RuntimeException(ex); + } + } + + private void getCurrenRowAndCol() throws BadLocationException { + int col = 1; + int pos = content.getCaretPosition(); + //获取行数 + int row = content.getLineOfOffset(pos) + 1; + //获取列数 + col = pos - content.getLineStartOffset(row - 1) + 1; + statusLabel.setText("行:" + row + " 列:" + col); + } + + + + // 释放某键 + public void keyReleased(KeyEvent e) { + try { + getCurrenRowAndCol(); // 获得当前的行和列位置 + } catch (BadLocationException ex) { + throw new RuntimeException(ex); + } + } + } + ); + + + // + + + final JMenu menu1 = new JMenu(); + final JMenu menu2 = new JMenu(); + final JMenu menu3 = new JMenu(); + final JMenu menu4 = new JMenu(); + final JMenu menu5 = new JMenu(); + menu1.setText("文件(F)"); + menu2.setText("编辑(E)"); + menu3.setText("查看(V)"); + menu4.setText("格式(O)"); + menu5.setText("帮助(H)"); + menubar.add(menu1); + menubar.add(menu2); + menubar.add(menu3); + menubar.add(menu4); + menubar.add(menu5); + //文件菜单的设计 + JMenuItem M11 = new JMenuItem(); + M11.setText("新建(N)"); + M11.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String string = content.getText(); + System.out.println(string); + if (string != null) { + JFileChooser fileChooser1 = new JFileChooser(); + //后缀名过滤器 + FileNameExtensionFilter filter = new FileNameExtensionFilter( + "文本文件(*.txt)", "txt"); + fileChooser1.setFileFilter(filter); + int state = fileChooser1.showSaveDialog(null); + + if (state == JFileChooser.APPROVE_OPTION) { + try { + + File file = fileChooser1.getSelectedFile(); + String fname = fileChooser1.getName(file); + if (fname.indexOf(".text") == -1) { + file = new File(fileChooser1.getCurrentDirectory(), fname + ".txt"); + System.out.println("renamed"); + System.out.println(file.getName()); + } + File dir = fileChooser1.getCurrentDirectory(); + String name = file.getName(); + File file1 = new File(dir, name); + FileWriter fileWriter = new FileWriter(file1); + BufferedWriter out = new BufferedWriter(fileWriter); + out.write(content.getText()); + out.close(); + fileWriter.close(); + } catch (IOException exp) { + } + + } + content.selectAll(); + content.replaceSelection(null); + setTitle("新建文本"); + } else { + setTitle("新建文本"); + } + + } + + }); + JMenuItem M12 = new JMenuItem(); + M12.setText("打开(O)"); + M12.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + content.selectAll(); + content.replaceSelection(null); + JFileChooser fileChooser2 = new JFileChooser(); + //后缀名过滤器 + FileNameExtensionFilter filter = new FileNameExtensionFilter( + "文本文件(*.txt)", "txt"); + fileChooser2.setFileFilter(filter); + int state = fileChooser2.showOpenDialog(null); + + if (state == JFileChooser.APPROVE_OPTION) { + try { + File dir = fileChooser2.getCurrentDirectory(); + String name = fileChooser2.getSelectedFile().getName(); + file2 = new File(dir, name); + FileReader fileReader = new FileReader(file2); + BufferedReader in = new BufferedReader(fileReader); + System.out.println(file2); + setTitle(file2.getName()); + String s = null; + while ((s = in.readLine()) != null) { + content.append(s + "\n"); + } + in.close(); + fileReader.close(); + } catch (IOException exp) { + } + + } + } + }); + JMenuItem M13 = new JMenuItem(); + M13.setText("保存(S)"); + M13.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + + String s = content.getText();//获取文本框中内容 + BufferedWriter out; + if (file2 != null) { + try { + + out = new BufferedWriter(new FileWriter(file2)); + out.write(s); + out.close(); + } catch (IOException e1) { + e1.printStackTrace(); + } + } else { + JFileChooser fileChooser1 = new JFileChooser(); + //后缀名过滤器 + FileNameExtensionFilter filter = new FileNameExtensionFilter( + "文本文件(*.txt)", "txt"); + fileChooser1.setFileFilter(filter); + int state = fileChooser1.showSaveDialog(null); + + if (state == JFileChooser.APPROVE_OPTION) { + try { + + File file = fileChooser1.getSelectedFile(); + String fname = fileChooser1.getName(file); + if(fname.indexOf(".text")==-1){ + file=new File(fileChooser1.getCurrentDirectory(),fname+".txt"); + System.out.println("renamed"); + System.out.println(file.getName()); + } + File dir = fileChooser1.getCurrentDirectory(); + String name = file.getName(); + File file1 = new File(dir, name); + FileWriter fileWriter = new FileWriter(file1); + out = new BufferedWriter(fileWriter); + out.write(content.getText()); + out.close(); + fileWriter.close(); + file2 = new File(dir, name); + } catch (IOException exp) { + } + + } + } + } + }); + JMenuItem M14 = new JMenuItem(); + M14.setText("另存为(A)"); + M14.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + JFileChooser fileChooser1 = new JFileChooser(); + //后缀名过滤器 + FileNameExtensionFilter filter = new FileNameExtensionFilter( + "文本文件(*.txt)", "txt"); + fileChooser1.setFileFilter(filter); + int state = fileChooser1.showSaveDialog(null); + + if (state == JFileChooser.APPROVE_OPTION) { + try { + + File file = fileChooser1.getSelectedFile(); + String fname = fileChooser1.getName(file); + if(fname.indexOf(".text")==-1){ + file=new File(fileChooser1.getCurrentDirectory(),fname+".txt"); + System.out.println("renamed"); + System.out.println(file.getName()); + } + File dir = fileChooser1.getCurrentDirectory(); + String name = file.getName(); + File file1 = new File(dir, name); + FileWriter fileWriter = new FileWriter(file1); + BufferedWriter out = new BufferedWriter(fileWriter); + out.write(content.getText()); + out.close(); + fileWriter.close(); + } catch (IOException exp) { + } + + } + } + }); + JMenuItem M15 = new JMenuItem(); + M15.setText("退出(X)"); + M15.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + System.exit(0); + } + }); + menu1.add(M11); + menu1.add(M12); + menu1.add(M13); + menu1.add(M14); + menu1.addSeparator(); + menu1.add(M15); + M11.setAccelerator(KeyStroke.getKeyStroke('N', InputEvent.CTRL_MASK)); + M12.setAccelerator(KeyStroke.getKeyStroke('O', InputEvent.CTRL_MASK)); + M13.setAccelerator(KeyStroke.getKeyStroke('S', InputEvent.CTRL_MASK)); + M14.setAccelerator(KeyStroke.getKeyStroke('S', InputEvent.SHIFT_MASK)); + // + + + //编辑菜单 + JMenuItem M21 = new JMenuItem(); + M21.setText("撤销"); + M21.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + undoManager.undo(); + } + }); + JMenuItem M22 = new JMenuItem(); + M22.setText("剪切"); + M22.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + content.cut(); + } + }); + JMenuItem M23 = new JMenuItem(); + M23.setText("复制"); + M23.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + content.copy(); + } + }); + JMenuItem M24 = new JMenuItem(); + M24.setText("粘贴"); + M24.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + content.paste(); + } + }); + JMenuItem M25 = new JMenuItem(); + M25.setText("删除"); + M25.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + content.replaceSelection(null); + } + }); + JMenuItem M26 = new JMenuItem(); + M26.setText("全选"); + M26.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + content.selectAll(); + } + }); + JMenuItem M27 = new JMenuItem("查找"); + class Tihuan implements ActionListener { + JLabel label1; + JTextField fiel, fiel2; + JButton but1; + int next; + + Tihuan() { + JFrame frame1 = new JFrame(); + frame1.setSize(350, 160); + frame1.setLocation(1000, 400); + frame1.setResizable(false); + frame1.setTitle("查 找"); + frame1.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + JPanel jpanel = new JPanel(); + label1 = new JLabel("查 找 内 容"); + fiel = new JTextField(10); + but1 = new JButton("查 找/下 一 个");//对按钮添加事件 + but1.addActionListener(this); + JLabel label2 = new JLabel(" 替 换 为 "); + fiel2 = new JTextField(10); + JButton but2 = new JButton("替 换"); + but2.addActionListener(this); + JButton but3 = new JButton("取 消"); + JCheckBox box = new JCheckBox("区 分 大 小 写"); + but3.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + frame1.dispose(); + } + }); + jpanel.add(label1); + jpanel.add(fiel); + jpanel.add(but1); + jpanel.add(label2); + jpanel.add(fiel2); + jpanel.add(but2); + jpanel.add(box); + jpanel.add(but3); + frame1.add(jpanel); + frame1.setVisible(true); + } + + public void actionPerformed(ActionEvent e) { + if (e.getActionCommand() == "查 找/下 一 个") { + String s = content.getText(); + String m = fiel.getText(); + int x = s.indexOf(m, content.getSelectionEnd()); + int n = x + m.length(); + content.select(x, n); + next = n; + content.select(next, s.length()); + String ss = content.getSelectedText(); + int newstartp = ss.indexOf(fiel.getText()) + next; + int newendp = newstartp + fiel.getText().length(); + content.select(newstartp, newendp); + + } + if (e.getActionCommand() == "替 换") { + int nexttemp = next; + String strall = content.getText(); + content.select(nexttemp, strall.length()); + String strnext = content.getSelectedText(); + int newstartp = strnext.indexOf(fiel.getText()) + nexttemp; + int newendp = newstartp + fiel.getText().length(); + content.select(newstartp, newendp); + content.replaceRange(fiel2.getText(), newstartp, newendp); + + } + } + } + M27.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + Tihuan tihuan = new Tihuan(); + } + }); + M21.setAccelerator(KeyStroke.getKeyStroke('Z', InputEvent.CTRL_MASK)); + M22.setAccelerator(KeyStroke.getKeyStroke('X', InputEvent.CTRL_MASK)); + M23.setAccelerator(KeyStroke.getKeyStroke('C', InputEvent.CTRL_MASK)); + M24.setAccelerator(KeyStroke.getKeyStroke('P', InputEvent.CTRL_MASK)); + M25.setAccelerator(KeyStroke.getKeyStroke('D', InputEvent.CTRL_MASK)); + M26.setAccelerator(KeyStroke.getKeyStroke('A', InputEvent.CTRL_MASK)); + menu2.add(M21); + menu2.addSeparator(); + menu2.add(M22); + menu2.add(M23); + menu2.add(M24); + menu2.add(M25); + menu2.add(M26); + menu2.addSeparator(); + menu2.add(M27); + // + + + + //查看菜单 + JMenuItem M31=new JMenuItem("状态栏(S)"); + Color color1 = Color.GREEN; + Color color2 = Color.white; + M31.setBackground(color1); + M31.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (chakan) { + remove(statusLabel); + remove(statusPanel); + revalidate(); + chakan = false; + System.out.println("状态栏取消"); + M31.setBackground(color2); + } else { + add(statusPanel, BorderLayout.SOUTH); + statusPanel.add(statusLabel); + revalidate(); + chakan = true; + System.out.println("状态栏形成"); + M31.setBackground(color1); + } + + } + }); + menu3.add(M31); + // + + + + //格式菜单 + JMenuItem M41 = new JMenuItem("自动换行(W)"); + M41.setBackground(color1); + M41.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (isLineWrap) { + content.setLineWrap(false); + isLineWrap = false; + System.out.println("自动换行取消"); + M41.setBackground(color2); + } else { + content.setLineWrap(true); + isLineWrap = true; + System.out.println("自动换行成功"); + M41.setBackground(color1); + } + + } + }); + menu4.add(M41); + //帮助菜单 + JMenuItem M51=new JMenuItem("提示:按键背景变绿代表启动"); + JMenuItem M52=new JMenuItem("功能:自动换行,查找与替换"); + menu5.add(M51); + menu5.add(M52); + // + } +} + + +