我正在用 java (netbeans) 创建一个打字导师。
现在我已经在 gui 中制作了一个键盘。
我想要的一个简单示例:B 和 A 是按钮,您可以在文本字段中键入。
现在有一些课程要做
第 1 课:abb ab abb (示例)
因此,A 按钮需要变为红色,然后按 A,B 变为红色,然后按 B。
如何将这些课程导入到我的应用程序中? (记事本)
我怎样才能使 A 在需要时变成红色?
我还没有一些代码,因为我不知道从哪里开始。
I'm making a typing tutor in java (netbeans).
Now i have made an keyboard in gui .
A simple example of how I want it: the B and A are buttons and in the text field you can type.
Now there are some lessons to do
Lesson 1: abb ab abb (example)
So the A button needs to be red then you press A, B becomes red you press B.
How can I import this lessons into my application ? (notepad)
And how can I make the A becomes red when it needs to be?
I do not have some codes yet because I don't know where to start.
发布评论
评论(3)
我认为您会执行以下两个选项之一:
InputMethodListener
)到文本字段。在侦听器中,更新 GUI 以更改相应按键的颜色。JTextComponent.addImputMetherListener
Keymap
,其中每个键都有一个将更改背景颜色的Action
GUI 的相应部分。JTextComponent.setKeymap
I would think you would do one of two options:
InputMethodListener
) to the text field. In the listener, update the GUI to change the appropriate key's color.JTextComponent.addImputMetherListener
Keymap
where for each key you have anAction
that will change the background color of the appropriate section of the GUI.JTextComponent.setKeymap
使用字符集合创建一个类
Lesson
。您可以为每个
课程
创建一个文件。将文件读入
Lesson
对象,然后在用户按下右侧按钮时遍历集合到下一个字符。Make a class
Lesson
with a collection of characters.You can make for each
Lesson
a file.Read the files into
Lesson
objects and then go over the collection to the next char when the user has pressed the right button.我不太确定这个问题是关于什么的。您似乎需要导师的帮助来编程并在旅途中学习 Java。 Stackoverflow 是一个问答平台,您应该在一个问题中提出每个具体问题。
无论如何,我可以看到帖子中包含两个问题:
1.如何在程序中读取文本文件?
至少这就是我对“导入课程”的理解。使用
BufferedReader
。使用readLine()
您可以将一行接着一行读入String
。2. 如何给我涂成红色的东西上色?
不知道键盘是怎么画的。但很可能您使用了
Graphics
-paint()-方法中的对象。图形
有一个setColor()
-方法,因此您可以在绘制元素之前输入如下内容:setColor(Color.RED);
。I'm not really sure what this question is about. It seems you want help to program the tutor and learning Java in the go. Stackoverflow is a Q&A-Platform, you should ask every concrete problem in a single question.
Anyways, I can see two questions packaged in the post:
1. How can I read a textfile in my program?
At least that is what I understand with 'importing the lesson'. Use a
BufferedReader
. WithreadLine()
you can read one line after the other into aString
.2. How to color something I painted red?
I don't know how you painted the keyboard. But most likely you used the
Graphics
-object in thepaint()
-method.Graphics
has asetColor()
-method, so you can type something like this:setColor(Color.RED);
before painting the element.