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());
}
}


Friday, April 18, 2008


Display Time in JSpinner : Swing Examples

Spinner allow user to select and type the value from a range of values. It has no drop-down list and this reason it is different to combo box. Here is the example to display time in JSpinner and also edit the time :

import javax.swing.*;
import java.awt.*;
import java.util.*;

public class ShowTimeJSpinner{
public static void main(String[] args) {
ShowTimeJSpinner h = new ShowTimeJSpinner();
}

public ShowTimeJSpinner(){
JFrame frame = new JFrame("JSpinner Time Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Date date = new Date();
SpinnerDateModel sm = new SpinnerDateModel(date, null, null, Calendar.HOUR_OF_DAY);
JSpinner spinner = new JSpinner(sm);
JSpinner.DateEditor de = new JSpinner.DateEditor(spinner, "hh:mm");
spinner.setEditor(de);
frame.add(spinner,BorderLayout.NORTH);
frame.setSize(100,100);
frame.setVisible(true);
}
}