Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Setting Defferent Color Of Alphabet In A String

 
Koh Khai Huat
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I am doing on a program to let user enter a Alphabet then the program will search the sentance in put by the user and highlight the Alphabet and display the Alphabet in a different color from the string.

this is the problem i know how to extract the Alphabet from the string but i dun know how to print the string out with individual Alphabet in a different color.

I am open to all suggestion and advice thanks in advance!!!
 
madhup narain
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is this a command line application program that we are talking about..?
or is it a GUI ? if its a GUI then ever heard of AWT.

im not sure if the command line program can allow individual characters to change color, but there must be some way i guess so, mean while let me check if i can change colors at when ouputt is on command line prompt
 
Koh Khai Huat
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

Thx for yr help I am doing a GUI program

regards
kkh
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use a JEditorPane or even a JLabel:
The JEditorPane has the advantage that it is editable.
[ February 02, 2006: Message edited by: Jeff Albertson ]
 
Koh Khai Huat
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

thx i see yr way but it dun't seem to fit in to what i am doing sorry about that may be i never explain my self clearly. I am leting the user to select the color by using the 3 scrollbar which is Red, Green, Blue so how do u go about doing that???

regards
KKH
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is the problem? Is it with creating a color from your user's input? Recall that in HTML you can specify color as a number, for example yellow is:

color = "#FFFF00"
 
Koh Khai Huat
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

thx i have a problem. the ptoblem is that i will be checking for vowels agains the string which the user input. then the user will select the RGB color using 3 scroll bar and then click submit then at the bottom the program will print out the string again but this time with the vowels lettes in the color the user select. hope this explaination is a better one thx sry to trouble u so much thx in advance

regards
KKH
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you have described your task fairly, well. I've shown you how Java can use basic HTML markup to add colors to text. I suggest you start coding and post specific questions when you get stuck.
 
Koh Khai Huat
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Thx Jeff your method works and i learn something new haha and i did't know that u can display html code in a JLabel Wow once angain thank you.

regards
KKH
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic