简体   繁体   English

在链接到 gui 的 java 中实现编辑器

[英]implementing an editor in java linked to the gui

is there any editor in Java? Java有编辑吗? To expand that, want to - let's say - open a text file, edit it, and then save it back or cancel?为了扩展它,想要 - 比如说 - 打开一个文本文件,编辑它,然后将其保存回来或取消?

What I want to do is that I have a GUI and I want to click a button that will bring up the file chooser, then I choose my text file that will be opened using this editor, I will then edit the file and finally save it or cancel to not save the changes, which will return me back to my GUI.我想要做的是我有一个 GUI,我想单击一个按钮来显示文件选择器,然后我选择将使用此编辑器打开的文本文件,然后我将编辑文件并最终保存它或取消以不保存更改,这将使我返回我的 GUI。

I would like to do all of these while in the Java environment, closing the GUI, editing the file and then reopening can be easily done.我想在 Java 环境中完成所有这些操作,关闭 GUI,编辑文件然后重新打开可以轻松完成。

If you are Trying to make your own editor, Its a big process.如果您正在尝试制作自己的编辑器,这是一个很大的过程。 You got to construct your UI, (1 big text area) set up a file chooser.你必须构建你的 UI,(1 个大文本区域)设置一个文件选择器。

Basically use a JFrame with a JTextArea JFileChooser基本上使用带有JTextArea JFileChooserJFrame

I'm not sure if that exactly what you are asking for, but sure enough there's JEdit , which is an editor written in Java.我不确定这是否正是您所要求的,但确实有JEdit ,它是用 Java 编写的编辑器。

that will allow them to edit their strategy on the run这将允许他们在运行中编辑他们的策略

I don't know much about games, but why would the "strategy" be expressed in a text file?我对游戏了解不多,但是为什么“策略”会用文本文件来表达呢? I would think you would want to use check boxes or radio buttons or combo boxes to allow the user to alter the strategy by selecting keywords etc. Then your could store the strategy is a Properties file.我认为您可能希望使用复选框或单选按钮或组合框来允许用户通过选择关键字等来更改策略。然后您可以将策略存储为属性文件。

A text editor would not allow for editing of the text for valid values or key works.文本编辑器不允许编辑有效值或关键作品的文本。 So if the user entered "abcd" I'm sure that would be just garbage.因此,如果用户输入“abcd”,我敢肯定那只是垃圾。 If all you want is text then a JTextArea should work just fine, since I don't see that you need any need for highlighting or bolding of the text.如果您想要的只是文本,那么 JTextArea 应该可以正常工作,因为我认为您不需要突出显示或加粗文本。 A text area supports the ability to read() and write() the contents from and to a file directly.文本区域支持直接从文件读取()和写入()内容的能力。

What are the exact feature you expect this "text editor" to provide?您期望这个“文本编辑器”提供的确切功能是什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM