:cry: ..i hav 2 hand over my java project soon..but i cannot figure out how 2 count da vowels in text i type inside ma textfield...i need a simple method because i just started java..i will be pleased if some one can send me commands for counting vowels in a text..
thank you

First, you need to clean up your own english(the abbreviations ) so we can understand you. Then you need to show us what you've already done, and specifically what you're having trouble with.

In the meantime, remember Java has a String class with many methods such as indexOf() and other stuff.

this is what i did........

/**
* @(#)VowelAnalyzer.java
*
* Sample Applet application
*
* @author
* @version 1.00 06/01/13
*/

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class VowelAnalyzer extends Applet implements ActionListener,AdjustmentListener {
Label L1,L2,L3,L4,L5,L6,L7;
Button B1;
Panel p=new Panel();
Panel p1=new Panel();
Panel p2=new Panel();
Panel p3=new Panel();
Panel p4=new Panel();
TextField T1;
int R=0,G=0,B=0,size;
Scrollbar S1,S2,S3;
String word="";
int aCount = 0,eCount = 0,iCount = 0,oCount = 0,uCount = 0;

public void init() {
L1=new Label(" INPUT TEXT:");
L3=new Label(" ");
L4=new Label(" ");
L2=new Label(" COLOR OF VOWELS:");
L5=new Label(" Red");
L6=new Label(" Green");
L7=new Label(" Blue");
T1=new TextField(30);
B1=new Button("Submit");
B1.addActionListener (this);
S1=new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,256);
add(S1);
S1.addAdjustmentListener(this);
S2=new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,256);
add(S2);
S2.addAdjustmentListener(this);
S3=new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,256);
add(S3);
S3.addAdjustmentListener(this);
p.setLayout(new BorderLayout());
p.add("East",L4);
p.add("Center",L1);
p.add("West",L3);
p.add("South",T1);
add(p);
p1.setLayout(new BorderLayout());
p1.add("North",p);
p1.add("South",L2);
add(p1);
p2.setLayout(new GridLayout(2,3,5,1));
p2.add(L5);
p2.add(L6);
p2.add(L7);
p2.add(S1);
p2.add(S2);
p2.add(S3);
add(p2);
p3.setLayout(new BorderLayout());
p3.add("North",p1);
p3.add("South",p2);
add(p3);
p4.setLayout(new BorderLayout(0,2));
p4.add("North",p3);
p4.add("South",B1);
add(p4);
}

public void actionPerformed(ActionEvent e){
word=T1.getText();
repaint();
}

public void adjustmentValueChanged(AdjustmentEvent e){
if(e.getSource()==S1)
R=S1.getValue();
if(e.getSource()==S2)
G=S2.getValue();
if( e.getSource()==S3)
B=S3.getValue();
// setForeground(new Color(R,G,B));
repaint();
}
public void paint(Graphics g) {
g.drawString("Vowels are displayed in RGB color of ("+R+","+G+","+B+").", 10,200);
Font font=new Font("Serif",Font.BOLD,17);
g.setFont(font);
g.setColor(new Color(R,G,B));
g.drawString(""+word, 8, 180 );

}
}

i need some help from here onnnnn.....

next time, use the CODE tags please.

I don't see anything where you tried to solve this yet. But anyway, what you could is store the 5 vowels into an ArrayList. Then loop through each Character in your string and see if it's contained within the array. If it is, then it must be a vowel.

hey i do da vowel counting....now i need to change ma colors of vowels when i change ma scrollbar..can any 1 help me....

hey i do da vowel counting....now i need to change ma colors of vowels when i change ma scrollbar..can any 1 help me....

Show us ur new code and highlite da areas where is a problem.

/**
* @(#)VowelAnalyzer.java
*
* Sample Applet application
*
* @author
* @version 1.00 06/01/13
*/


import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class VowelAnalyzer extends Applet implements ActionListener,AdjustmentListener {
Label L1,L2,L3,L4,L5,L6,L7;
Button B1;
Panel p=new Panel();
Panel p1=new Panel();
Panel p2=new Panel();
Panel p3=new Panel();
Panel p4=new Panel();
TextField T1;
int R=0,G=0,B=0,size;
Scrollbar S1,S2,S3;
String word="";


public void init() {
L1=new Label("           INPUT TEXT:");
L3=new Label("           ");
L4=new Label("        ");
L2=new Label("                 COLOR OF VOWELS:");
L5=new Label("        Red");
L6=new Label("      Green");
L7=new Label("       Blue");
T1=new TextField(30);
B1=new Button("Submit");
B1.addActionListener (this);
S1=new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,256);
add(S1);
S1.addAdjustmentListener(this);
S2=new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,256);
add(S2);
S2.addAdjustmentListener(this);
S3=new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,256);
add(S3);
S3.addAdjustmentListener(this);
p.setLayout(new BorderLayout());
p.add("East",L4);
p.add("Center",L1);
p.add("West",L3);
p.add("South",T1);
add(p);
p1.setLayout(new BorderLayout());
p1.add("North",p);
p1.add("South",L2);
add(p1);
p2.setLayout(new GridLayout(2,3,5,1));
p2.add(L5);
p2.add(L6);
p2.add(L7);
p2.add(S1);
p2.add(S2);
p2.add(S3);
add(p2);
p3.setLayout(new BorderLayout());
p3.add("North",p1);
p3.add("South",p2);
add(p3);
p4.setLayout(new BorderLayout(0,2));
p4.add("North",p3);
p4.add("South",B1);
add(p4);
}


public void actionPerformed(ActionEvent e){
word=T1.getText();
size= word.length();
repaint();
}


public void adjustmentValueChanged(AdjustmentEvent e){
if(e.getSource()==S1)
R=S1.getValue();
if(e.getSource()==S2)
G=S2.getValue();
if( e.getSource()==S3)
B=S3.getValue();
//  setForeground(new Color(R,G,B));
repaint();
}
public void paint(Graphics g) {
int pos=0;
int aCount = 0,eCount = 0,iCount = 0,oCount = 0,uCount = 0;


while(pos<size){
switch (word.charAt(pos))
{


case 'a': case 'A':
++aCount;g.setColor(new Color(R,G,B)); break;
case 'e': case 'E':
++eCount;g.setColor(new Color(R,G,B)); break;
case 'i': case 'I':
++iCount;g.setColor(new Color(R,G,B)); break;
case 'o': case 'O':
++oCount;g.setColor(new Color(R,G,B)); break;
case 'u': case 'U':
++uCount;g.setColor(new Color(R,G,B)); break;
}
++pos;
}
g.setColor(new Color(0,0,0)) ;
g.drawString(" A = "+aCount, 8,220);
g.drawString(" E = "+eCount, 8, 240 );
g.drawString(" I = "+iCount, 8, 260 );
g.drawString(" O = "+oCount, 8, 280 );
g.drawString(" U = "+uCount, 8, 300 );
g.drawString("Vowels are displayed in RGB color of ("+R+","+G+","+B+").", 10,200);
Font font=new Font("Serif",Font.BOLD,17);
g.setFont(font);
//  g.setColor(new Color(R,G,B));
g.drawString(""+word, 8, 180 );


}
}

this is what i did..but not working..i just want only my vowels 2 change color when i change ma scrollbar

Edited 3 Years Ago by happygeek: fixed formatting

:sad: hey any one know how to convert a string in to char...
it will be really gr8..if some one can help me asap...
thank u....

no, I'm not going to help you asap. I MIGHT help you if you ask nicely in a year or so.

:D

Try this.

class isYou
{
    public static void main(String[] args)
    {
        String thwee = "iamthwee";
        char[] what = thwee.toCharArray();
        for(int dex=0; dex<what.length; dex++)
        {
            System.out.print(what[dex]);
            System.out.println("\n");
        }
    }
}
This article has been dead for over six months. Start a new discussion instead.