trying to colour text from a getText statement in an applet
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   thomas_bannister
Posted On:   Friday, March 4, 2011 06:29 AM

hi, i'm doing a basic applet project and i am trying to find out how to colour text that has been taken from a text box with a getText statement. I enter any text into the text box and after the enter button is pressed the word displays underneith, i need to know how to colour this word and maybe try to colour one certain letter (for example each time a H is entered every H will be green and the rest of the word will be blue, any help would be great!!! java coding for applet: import java.awt.*; import java.applet.*; import java.awt.Color; import java.awt.Font; public class bannister_T_B3 extends Applet { TextField tomBannister; public void init() { tomBannister   More>>

hi, i'm doing a basic applet project and i am trying to find out how to colour text that has been taken from a text box with a getText statement. I enter any text into the text box and after the enter button is pressed the word displays underneith, i need to know how to colour this word and maybe try to colour one certain letter (for example each time a H is entered every H will be green and the rest of the word will be blue, any help would be great!!!

java coding for applet:

import java.awt.*;
import java.applet.*;
import java.awt.Color;
import java.awt.Font;
public class bannister_T_B3
extends Applet
{
TextField tomBannister;
public void init()
{
tomBannister = new TextField(30);
add(tomBannister);
}
public void paint(Graphics g)
{
String t = tomBannister.getText();
g.drawString(t, 50, 50);
String nAS = t.toUpperCase();
tomBannister.setText(nAS);
tomBannister.setFont(new Font("Serif", Font.ITALIC, 16));
}
public boolean action(Event event, Object arg)
{
repaint();
return true;
}
}

   <<Less

Re: trying to colour text from a getText statement in an applet

Posted By:   Chad_Preisler  
Posted On:   Friday, March 4, 2011 01:26 PM


Use HTML to color the text. Check out this tutorial on how to use HTML in your Swing.


http://download.oracle.com/javase/tutorial/uiswing/components/html.html

About | Sitemap | Contact