Results 1 to 3 of 3
Thread: Arrays in Applets
- 02-26-2011, 06:33 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 2
- Rep Power
- 0
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.Java Code:import java.util.*; import java.applet.Applet; import java.awt.*; import java.awt.event.*; public class finalApplet extends Applet implements ActionListener { String text; TextField input; Font f; public void init() { setBackground(Color.gray); f = new Font("Calibri", Font.BOLD,15); input = new TextField (20); add(input); input.addActionListener(this); } public void start() { text = ""; } public void actionPerformed (ActionEvent e) { text = e.getActionCommand(); repaint(); } public void paint(Graphics g) { g.setFont(f); g.setColor(Color.blue); 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?
Thanks
-
Does this have to be an AWT Applet? Could it be a Swing JApplet?
- 02-26-2011, 06:44 PM #3
Member
- Join Date
- Feb 2011
- Posts
- 2
- Rep Power
- 0
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.
EDIT
So I've been reading around and Im thinking I need to add something along the lines of:
Java Code:char stringArray[]
Java Code: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.Java Code:if(stringArray[i] == 'c') g.setColor(Color.yellow)
Im guessing the char variable would be in the init() section?
Please excuse my amateurish terminology and such.
Thanks.Last edited by ChaosEvaUnit; 02-26-2011 at 07:59 PM.
Similar Threads
-
Arrays.sort... why sorting all arrays in class?
By innspiron in forum New To JavaReplies: 6Last Post: 03-23-2010, 01:40 AM -
New to Applets
By Psyclone in forum Java AppletsReplies: 8Last Post: 02-28-2010, 04:00 AM -
I need help with Applets
By ProgrammingPup in forum Advanced JavaReplies: 1Last Post: 12-22-2009, 08:07 PM -
Can't see any Applets
By pyr0chem in forum Java AppletsReplies: 9Last Post: 12-17-2008, 04:24 AM -
applets on mac what´s going on?
By willemjav in forum Java AppletsReplies: 6Last Post: 04-19-2008, 07:03 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks