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.add(chk);
frame.setSize(400, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}


Tuesday, May 27, 2008


Java String Trim Example

The string trim() method remove the blank spaces from the left and right in the given string.

Here is the example how to remove blank spaces :

import java.lang.*;
public class StringTrim{
public static void main(String[] args) {
System.out.println("Source code of String Trim Method");
String str = " blankspaces ";
System.out.println("Entered String :" + str);
System.out.println("Output of the Program :" +str.trim());
}
}