简体   繁体   English

是否可以在不使用JTextArea的情况下用Java构建简单的文本编辑器?

[英]is that possible to built a simple text editor in java without using JTextArea?

I have questions according to my final project in my IT Faculty.. I have to make A simple text editor (like notepad) without using JTextArea (GUI Java), I have to make my own JTextArea.. 根据我在IT系的最后一个项目,我有一些问题。我必须使用A简单的文本编辑器(如记事本)而不使用JTextArea(GUI Java),我必须创建自己的JTextArea。

Idea/Topic= Own Text Editor 想法/主题=自己的文本编辑器

Algorithms= doesnt have any idea yet Algorithms =还没有任何想法

Data Structure= Rope(Member of Binary Trees) 数据结构=绳索(二叉树成员)

Requirement= Typing without JTextArea... Requirement =不使用JTextArea键入...

Is that possible to make that? 有可能做到这一点吗? Can a panel (or something else like that) has a listener or make a listener to do that? 面板(或类似的东西)可以有一个听众或让听众这样做吗? simply thinking, First step I just want to try for typing on a panel, absolutely algorithms needed but i dont get right algorithms so far.. Is that possible? 只是想,第一步,我只想尝试在面板上打字,绝对需要算法,但到目前为止我还没有得到正确的算法。

My thinking is, for text that im typing is stored to a tree.. Is that Rope(Member of Binary Trees) for my data Structure? 我的想法是,对于即时消息键入的文本存储到树上。我的数据结构是那根绳子(二叉树成员)吗?

Thanks for helping... 感谢您的帮助...

It's possible. 这是可能的。

Use as you mentioned JPanel attaching KeyListener and MouseListener . 如前所述,使用JPanel附加KeyListenerMouseListener

You need a model ( Document ). 您需要一个模型( Document )。 For simplest case it could be eg StringBuilder where you can add content and show the StringBuilder content. 对于最简单的情况,它可以是例如StringBuilder ,您可以在其中添加内容并显示StringBuilder内容。

You need caret position (int field) to indicate where the edit should happen. 您需要插入符号位置(int字段)以指示应在何处进行编辑。

You need Font field to keep all the font info to be used in the editor. 您需要“字体”字段来保留所有字体信息以在编辑器中使用。

Override paintComponent() and use FontMetrics to measure the text and calculate necessary width/height. 重写paintComponent()并使用FontMetrics测量文本并计算必要的宽度/高度。 For the start I would create a text area without line wrap. 首先,我将创建一个没有换行的文本区域。

Implement viewToModel/modelToView methods. 实现viewToModel / modelToView方法。 They should calculate position of caret for given x,y and x,y for given caret position. 他们应该针对给定的x,y和x,y计算给定插入符号位置的插入符号位置。

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

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