How to Create a Typing Program
Typing programs, or word processors, are useful programs both for the purposes of actually using them for creating text documents and learning about programming. Regardless of which reason you are looking to create a typing program, the basic mechanics of establishing the program's structure are not difficult to employ. Java, a workhorse language that is often used as a first language to teach programming, comes with many tools that you can use for this project.
Instructions
-
-
1
Open a text file, or the development environment of your choice. If you have not already, download the Java development kit (SDK) from Oracle's website. The link is in the "Resources" section below. Run the installer after you have finished downloading it.
-
2
Import the "javax.awt.*" library. You will also need the"javax.swing.*" and "java.awt.event.*" libraries. Use the "import" command for this purpose.
-
-
3
Declare a "String" variable before you write any functions. This variable will hold your user's input. Also declare the objects you intend to to add to your interface, including at least a "JTextField" object and a "JButton" object.
-
4
Create your main() function within your program's public class. Add the objects you feel relevant to the way you want the screen to look, but make sure to include at least the text field and button you declared in the previous step. Remember to use the basic formula of "JTextField [your-custom-name] = new JTextField();" to create new objects.
-
5
Create a separate "actionPerformed" function that takes a parameter of "(ActionEvent e)." The syntax will look like "public void actionPerformed(ActionEvent e)" followed by your function brackets.
-
6
Create an "if" statement within the "actionPerformed" function to execute if the variable "e" equals the custom name you gave your button in Step 4. Within that "if" statement, set the string variable you declared in step three to "[the-custom-name-you-gave-your-text-field].getText()" to store the text your user has typed in that string variable.
-
7
Add the extra functions for your typing program to manipulate your user's text input, that is stored in the text string.
-
8
Compile your source code into an executable file. Use your development environment's "compile" function, or use the "javac [your source-code-file]" command in the command line.
-
1
References
- Photo Credit typing image by Dariusz Urbanczyk from Fotolia.com