import java.applet.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Scanner;
public class histogram extends Applet implements ActionListener{
Button increase, decrease; // These are two buttons
TextField enter;
String str;
private int uvwl=0,lvwl=0,ucnt=0,lcnt=0,other=0;
public void init ()
{
setSize(1000,700);
setLayout(new FlowLayout());
increase = new Button("GO");
increase.addActionListener(this);
add(increase);
enter=new TextField(11);
add(enter);
decrease = new Button("QUIT");
decrease.addActionListener(this);
add(decrease);
}
private static int CountUpperCasevwl(String str)
{
int count=0;
for(int i=0;i<str.length();i++)
{
char ch=str.charAt(i);
if(ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
count++;
}
return count;
}
private static int CountlowerCasevwl(String str)
{
int count=0;
for(int i=0;i<str.length();i++)
{
char ch=str.charAt(i);
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
count++;
}
return count;
}
private static int CountUpperCasecnt(String str)
{
int count=0;
for(int i=0;i<str.length();i++)
{
char ch=str.charAt(i);
if(ch>='A'&&ch<='Z'&&ch!='A'&&ch!='E'&&ch!='I'&&ch!='O'&&ch!='U')
count++;
}
return count;
}
private static int CountlowerCasecnt(String str)
{
int count=0;
for(int i=0;i<str.length();i++)
{
char ch=str.charAt(i);
if(ch>='a'&&ch<='z'&&ch!='a'&&ch!='e'&&ch!='i'&&ch!='o'&&ch!='u')
count++;
}
return count;
}
public void actionPerformed(ActionEvent a) {
// TODO Auto-generated method stub
if(a.getSource()==increase){
str=enter.getText();
uvwl=CountUpperCasevwl(str);
lvwl=CountUpperCasecnt(str);
ucnt=CountlowerCasevwl(str);
lcnt=CountlowerCasecnt(str);
other=str.length()-uvwl-lvwl-ucnt-lcnt;
}
else if(a.getSource()==decrease)
{
System.exit(3);
}
repaint();
}
public void paint(Graphics g)
{
setBackground(Color.gray);
g.drawRect(300, 100, 500, 500);
g.setColor(Color.blue);
g.drawString("UVWL", 320, 590);
g.drawString("LVWL", 380, 590);
g.drawString("UCNT", 440, 590);
g.drawString("LCNT", 500, 590);
g.drawString("OTHER", 560, 590);
for(int i=0;i<10;i++)
{
String str = Integer.toString(i);
g.drawString(str,305,590-(20*i));
}
g.setColor(Color.red);
g.fillRect(320, 580-( 20*uvwl),30 , 20*uvwl);
g.fillRect(380, 580-(20*lvwl), 30, 20*lvwl);
g.fillRect(440, 580-(20*ucnt), 30, 20*ucnt);
g.fillRect(500, 580-(20*lcnt), 30, 20*lcnt);
g.fillRect(560, 580-(20*other), 30, 20*other);
}
}
No comments:
Post a Comment