Arrays in Applets
Right first of all, I'd just like to say Im still new to Java, Im a total beginner, so Im still not too great at coping with jargon, so please excuse me if my explanation isn't great.
Basically I've made an applet with a textfield and whatever you type into the textfield is output underneath it.
Now I need to create an array within the applet that takes the input and puts each char of the string into an array, of which is used to change the colour of certain letters upon output.
Here's my applet so far
So for example, upon output, if any chars in the String which was input are the letter 'c' I want them to be yellow and any chars in the string which are the letter 'k' to be black.
public class finalApplet extends Applet implements ActionListener
public void init()
f = new Font("Calibri", Font.BOLD,15);
input = new TextField (20);
public void start()
text = "";
public void actionPerformed (ActionEvent e)
text = e.getActionCommand();
public void paint(Graphics g)
g.drawString(text, 25, 100);
If you follow me.
So Im reading up on arrays as we speak but still not too sure on how to do it, especially within an applet.
Any chance you guys could help out a rookie?
Does this have to be an AWT Applet? Could it be a Swing JApplet?
Yeah it does Im afraid.
It's for an assignment and we've only learnt to use awt so far, so if I use something else it will be evident I didn't do it.
I dont have the intention of copying word for word any code that people may offer me here, I just need guidance with this because Im pretty much at my wits end with it right now. =/
And I'll never learn if I do just copy stuff.
So I've been reading around and Im thinking I need to add something along the lines of:
for(int i = 0; i < stringArray; i++)
But thats just an educated guess, not sure if any of the above code is wrong because I'm not actually sure where in the Applet code I would stick these chunks, seeing as I would still get an error if the code was right but in the wrong place.
if(stringArray[i] == 'c')
Im guessing the char variable would be in the init() section?
Please excuse my amateurish terminology and such.