944,052 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1539
  • Java RSS
Jan 19th, 2006
0

need help...

Expand Post »
: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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dammika is offline Offline
7 posts
since Jan 2006
Jan 19th, 2006
0

Re: need help...

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.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Jan 19th, 2006
0

Re: need help...

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.....
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dammika is offline Offline
7 posts
since Jan 2006
Jan 20th, 2006
0

Re: need help...

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.
Reputation Points: 92
Solved Threads: 51
Practically a Posting Shark
Phaelax is offline Offline
856 posts
since Mar 2004
Jan 23rd, 2006
0

Re: need help...

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....
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dammika is offline Offline
7 posts
since Jan 2006
Jan 23rd, 2006
0

Re: need help...

Quote originally posted by dammika ...
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.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Jan 23rd, 2006
0

Re: need help...

/**
* @(#)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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dammika is offline Offline
7 posts
since Jan 2006
Jan 24th, 2006
0

Re: need help...

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....
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dammika is offline Offline
7 posts
since Jan 2006
Jan 24th, 2006
0

Re: need help...

no, I'm not going to help you asap. I MIGHT help you if you ask nicely in a year or so.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Jan 24th, 2006
0

Re: need help...

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


Try this.

Java Syntax (Toggle Plain Text)
  1. class isYou
  2. {
  3. public static void main(String[] args)
  4. {
  5. String thwee = "iamthwee";
  6. char[] what = thwee.toCharArray();
  7. for(int dex=0; dex<what.length; dex++)
  8. {
  9. System.out.print(what[dex]);
  10. System.out.println("\n");
  11. }
  12. }
  13. }
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: first project in netbeans
Next Thread in Java Forum Timeline: hi,urgent





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC