Saturday, June 21, 2008

Count Vowels Example in Java

This example show you how to check and calculate how many vowel are in the string entered by user. With the help of for loop, we calculate how many vowels a user entered in the string. Here is the source code :

import java.lang.String;
import java.util.*;

public class vowels{

public static void main(String args[])throws IOException{
BufferedReader bf = new BufferedReader(new InputStreamReader(;
System.out.println("Enter New String to Check :");
String text = bf.readLine();
int cnt = 0;
for (int a = 0; a < text.length(); a++) {
char b = text.charAt(a);
if (b=='a' || b=='e' || b=='i' || b=='o' || b=='u') {
System.out.println("Total Vowels are" + " : " + cnt);

Tuesday, June 17, 2008

How to Create Checkbox in Java Swing?

What is Check Box?

A check box or tick box is a graphical user interface element that allow or permits user to make selections from the options. User can select more than one item or element.

The given example will explain you how to create check box in java swing. It is created in java by creating the instance of JCheckBo class. Here is the check box program :

public class CreateCheckBox{
public static void main(String[] args){
JFrame frame = new JFrame("The Check Box Example");
JCheckBox chk = new JCheckBox("Check Box 1");
JCheckBox chk = new JCheckBox("Check Box 2");
JCheckBox chk = new JCheckBox("Check Box 3");
frame.setSize(400, 400);