Tuesday, April 12, 2011

JAVA FUNCTION TO FIND SPECIAL CHARACTERS IN STRING

import java.util.regex.*;
import java.io.*;


public class SpecialCharacters
{
public static void main( String[] args ) throws IOException
{

String string = "ashzxcvbnmasdfghjklopiuytrewqASHWINI00675%%%%";
Pattern pattern = Pattern.compile( "[^a-zA-Z0-9*]" );
Matcher matcher = pattern.matcher( string );

System.out.println(matcher.find());
String str = matcher.replaceAll( "F" );
System.out.print( str );
}
}

where [^a-zA-Z0-9*] Any character except a to z, A-Z , 0 to 9 or *
If it will find other then these character the matcher.find() return true else false
matcher.replaceAll( "F" ) will replace all the occurrence of other characters with F

Thursday, March 24, 2011

JOptionPane with bold text and different font

  1. public class abc {
  2. public static void main(String[] args) {
  3. String msg = "my name is :
    • italics abc "
    • + "
    • bold and "
    • + "
    • underlined...
    "
    ;
  4. JLabel label = new JLabel(msg);
  5. label.setFont(new Font("serif", Font.PLAIN, 14));
  6. JOptionPane.showConfirmDialog(null, label);
  7. System.exit(0);
  8. }
  9. }

JOptionPane with JCheckBox

JCheckBox checkbox = new JCheckBox("Non Callable Debt");
String message = "Enter CUSIP";
Object[] params = {message, checkbox};
String cusip = JOptionPane.showInputDialog( m_Page,params, "Input", JOptionPane.PLAIN_MESSAGE );
boolean nonCallableDebt = checkbox.isSelected();

How to use JOptionPane with to display bold text and customize message option


String msg = "You cannot transact or perform financial calculations from this "
+ "version
for use in business, without permission from the VP of M&R Operations and the VP of Model Change Control
";
System.getProperty( "Environment" );
if( !WorkBenchController.isProductionEnvironment() )
{
Object[] options =
{ "I Acknowledge", "Cancel" };
int n = JOptionPane.showOptionDialog( splashScreenPageController.getWindow(), msg, "Warning",
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[ 1 ] );
if( n != 0 )
{

System.exit( 0 );
}
}