-
text color changer based on words/ word classification by color
i am a complete novice programmer, I'm in high-school [freshmen] and i would like to create a program [it is not an assignment so font worry] but i would like a program that i could either have in an executable file [preferably] or be able to be put onto a website but basically what this program would do is it would have multiple text boxes that a user could put information in and one text box that would be the output.
now after reading this you may think that i am trying to create a spell checker well i already have one it's called Microsoft word and i know about it but rather this program would have one MAIN text box where you would put in your text from your document [preferably still for mated of coarse] and it would output with different words being different colors. it would figure out which words would be what colors by another set of text boxes, each of these text boxes would be assigned a color and the words [or set of words] inside these text boxes would be the words [or set of words] that would be turned that specific color [or would be highlighted by a specific color or underlined a specific color]
i know the basics of how it would work it would be something along the lines of say
if( and, the, but, But,) then output>
now i would be able to do this to an extent except this has to do with the color of the text and maybe/ hopefully a highlighted or underlined color of the text, and i have know idea what the terms are.
this would be used for proff reading essays and stuff [my English teacher said she would love to have something like this] or documents of code programming to proof read <<[this has already been done ] but the difference is that there wouldn't be a rigid set the user decides what words are what colors but i have no idea how to do this even though it would probably be easy. but basically what i want is a input box to put a couple pages of text in formatting and all and then have other text boxes one for red, blue, green, yellow, purple, orange.
but as i said before i have no idea how do do this due to the text color stuff [probably wouldn't anyways] and i would really really like some help with this as soon as possible.
and thank you just for reading this and if you want to contact me
Reply on here
or my Psn's are knoxy5467, Parad0xs12, and my xbx gamertag is Parad0xs [more likely to reach me at my Psn's though]
so thank you for reading and please help this would make me and several teachers very happy and our lives would be allot easier
-
Re: text color changer based on words/ word classification by color
What have you coded so far?
Look at the JEditorPane class as a way to have different lines in different colors.
-
Re: text color changer based on words/ word classification by color
nothing really because i dont know where to start i know that if it was more indavidual statments i could use if then statments but since it's going to be alot of words changing colors i dont know what to do will seperating staments with a comma do it?
-
Re: text color changer based on words/ word classification by color
Start with small bits and add to it as you go.
Quote:
will seperating staments with a comma do it?
Do what?
Please explain what adding commas will do for your problem.
-
Re: text color changer based on words/ word classification by color
i was thinking that in the text boxes where the text that supposed to change colors will separating each word with a comma allow the if statement to recognize each and every one of those words in the main text body using the main text input as a variable and the text color changers as something that recognizes specified words as things they need to change? [hope i didn't confuse you]
-
Re: text color changer based on words/ word classification by color
There are different ways to scan a String. One is to use delimiters and you seem to be thinking to use a comma.
Quote:
allow the if statement to recognize each and every one of those words
here you are running ahead and thinking of how you are going to implement some of the code.
Design what you want the program to do and then figure out the best technique for doing it.
-
Re: text color changer based on words/ word classification by color
i want to be able to take text from say a word document and put it into this program and then tell this program via dialog boxes to change specific words in this body of text to a specific color and then i want it to output the body of text i put in with the text color changes implemented
-
Re: text color changer based on words/ word classification by color
Quote:
i want it to output the body of text i put in with the text color changes implemented
I understand the first part, but not this part.
What is the output to look like? How are the colored words to be represented?
If you output the text with markup like HTML then the coloring could be preserved.
-
Re: text color changer based on words/ word classification by color
yes with markup like html
[|v| this may be a noob question |v|]
how do i preserve the coloring?
-
Re: text color changer based on words/ word classification by color
The coloring controls for the text being displayed would be around somewhere that you could read and use when you create the HTML.
I've never done this, so I'm not sure where they would be.
-
Re: text color changer based on words/ word classification by color
well i was thinking that i would have the main string [the place where the suser puts the main body of text]
and then have other strings that tells another funtion or somthing to change specific tokens different colors
also the content of the strings is added by the user via text box input
and then have it all acumulated in a output text where all the color changes are shown and the formatting is still there
-
Re: text color changer based on words/ word classification by color
Quote:
output text where all the color changes are shown and the formatting is still there
Sounds like HTML
-
Re: text color changer based on words/ word classification by color
maybe we could use strings somhow
-
Re: text color changer based on words/ word classification by color
That what HTML is made up of: Strings of text.
-
Re: text color changer based on words/ word classification by color
ok so we could make all of the words in the text box that states that the user wants the word lets say "car" to be blue well we would make "car" a known variable and if "car" is in the body of text that we want changed and its in the text box that we want those words blue then it would recognize it in the main body of text [classified as a string with each word being a token] and would change it's color to blue would that work? with like 30 different words possibly being blue and their being over 1000 words in the main body of text?
-
Re: text color changer based on words/ word classification by color
Yes, I think that could be done. I'm experimenting with the JTextPane (JTP) class as a possibility for your project.
The way it works is:
You add text to the JTP
When you want to color a word, search for the word, color it at the location it is found and loop back to search again and color again until all instances colored.
You'd have to define the output format for the text to be able to decide how to preserve the coloring when you write the text to a file.
-
Re: text color changer based on words/ word classification by color
would there be a way to look for the positions in the text that reterns are or where the words that are colord are OR just use a replace function like in word [i know java can do that i just dont have the slightest idea how]
-
Re: text color changer based on words/ word classification by color
Quote:
a way to look for the positions in the text that reterns are or where the words that are colord are OR just use a replace function
Sorry, I don't understand your question. What is a "reterns"?
To find where the words that are colored are located, you'd need to save their location as you colored them
-
Re: text color changer based on words/ word classification by color
I think you're asking a few different questions here. You might want to start with something that doesn't have a GUI- it could take a text file and output an html file, with certain hard-coded words colored using basic html font tags. Then just open that file in a web browser, and see how you like the effect.
From there, you can go to a GUI that allows the user to customize which words are which colors, and from there you can go to a GUI that displays the output html file.
There are many ways to accomplish your goal, so you might want to experiment a bit. This is a doable project for a novice, but it's going to be slow- slow down, take your time, and don't get carried away with "how cool would this be" type thoughts. Start small and go from there.
-
Re: text color changer based on words/ word classification by color
This is possible to achieve with HTML in, for example a JLabel - you start the text with "<html>", then wrap each word with HTML to set its color, for example: "<html>The cat <font color=red>sat</font> on the mat" would display: "The cat sat on the mat" (see How To Use HTML In Swing Components).
You could have lists of words for each required color, a text area to paste text into, a label area to display the colored text, and a button to process the text and display it in color. For (a crude) example:
http://gallery.idnet.com/main.php?g2...serialNumber=2
The main difficulties with this technique involve finding and wrapping the target words, and formatting the JLabel for display (e.g. line-wrapping needs "<br>" inserted as line breaks).
-
Re: text color changer based on words/ word classification by color
Nice job dlorde!
Quote:
main difficulties with this technique involve finding and wrapping the target words, and formatting the JLabel for display (e.g. line-wrapping needs "<br>" inserted as line breaks).
Using JTextPane moves the difficulties further on to the output step.
The JTP handles word wrap and can be in a JScrollPane to allow for longer text. Setting the color for a word is a simple search (indexOf) and a call to setCharacterAttributes to set the color for the word.
To build the output would require saving a few references to where the words were and their colors and then using that with substring to parse out the non colored and colored parts to build HTML output.
-
Re: text color changer based on words/ word classification by color
Yes Norm, I think you're absolutely right - using JTextPane for the initial color processing avoids all the problems of trying to edit HTML text (e.g. avoiding replacing the contents of the HTML tags already inserted, if the word list contains 'font' or 'blue', etc). Generating HTML output from the JTP would be relatively easy.
Having said that, finding a word to color in the text isn't necessarily as simple as just using indexOf, because quite a few words can appear as part of other words ('us', 'on', 'the', etc.), so a regex word search is necessary (to find the word between non-word characters), which isn't quite as simple as it sounds given the methods available. For example, you can replace with a regex, but if the regex is 'word between non-word characters', the replacement text will replace the non-word characters too, and you don't know what they are in advance... perhaps cunning use of Matcher can do the job.
-
Re: text color changer based on words/ word classification by color
I think for a student I'd leave the regex for version 2. Keep it simpler for version 1.
For example after indexOf() finds the word, verify that the char before and the char after is a terminating char by an easy lookup in a table of word terminating chars.
-
Re: text color changer based on words/ word classification by color
Quote:
Originally Posted by
dlorde
This is possible to achieve with HTML in, for example a JLabel - you start the text with "<html>", then wrap each word with HTML to set its color, for example: "<html>The cat
<font color=red>sat
</font> on the mat" would display: "The cat
sat on the mat" (see
How To Use HTML In Swing Components).
You could have lists of words for each required color, a text area to paste text into, a label area to display the colored text, and a button to process the text and display it in color. For (a crude) example:
http://gallery.idnet.com/main.php?g2...serialNumber=2
The main difficulties with this technique involve finding and wrapping the target words, and formatting the JLabel for display (e.g. line-wrapping needs "<br>" inserted as line breaks).
um you have the sorce code for this?
-
Re: text color changer based on words/ word classification by color
Quote:
would either of those help?
What problem are you trying to solve?
There are two different solutions posted earlier in the thread.