Click here to Skip to main content
15,899,754 members
Home / Discussions / Java
   

Java

 
QuestionFinding Duplicates:(Loop within a Loop) Pin
squalled3-Sep-09 20:20
squalled3-Sep-09 20:20 
AnswerRe: Finding Duplicates:(Loop within a Loop) Pin
Nagy Vilmos3-Sep-09 21:58
professionalNagy Vilmos3-Sep-09 21:58 
AnswerRe: Finding Duplicates:(Loop within a Loop) Pin
TorstenH.4-Sep-09 2:55
TorstenH.4-Sep-09 2:55 
AnswerRe: Finding Duplicates:(Loop within a Loop) Pin
42774804-Sep-09 8:52
42774804-Sep-09 8:52 
QuestionValidation Pin
hitesh.kalra2-Sep-09 2:07
hitesh.kalra2-Sep-09 2:07 
AnswerRe: Validation Pin
42774802-Sep-09 7:11
42774802-Sep-09 7:11 
GeneralRe: Validation Pin
David Skelly2-Sep-09 22:24
David Skelly2-Sep-09 22:24 
GeneralRe: Validation Pin
42774803-Sep-09 1:44
42774803-Sep-09 1:44 
True there are many ways to do it.

Snippet 1: Integers
public Validate() 
	{
		Text.addKeyListener(new KeyAdapter() 
		{
			public void keyTyped(KeyEvent e) 
			{
				char c = e.getKeyChar();
				if (!(Character.isDigit(c) ||(c == KeyEvent.VK_BACK_SPACE) ||(c == KeyEvent.VK_DELETE))) 
				{
					getToolkit().beep();
					e.consume();
				}
				if( c == KeyEvent.VK_0)
				{
					Label.setText("0 entered");
					Label.setForeground(Color.red);
				}
				else
				{        	   
					Label.setText("ok");
					Label.setForeground(Color.black);
				}
			}
		});


Snippet 2: Double

public class Validate()
{
DoubleValidate dv = new DoubleValidate();
public Validate() 
	{
		Text.setDocument(dv);
		add(Text);
	}

	static class DoubleValidate extends PlainDocument 
	{
		public void insertString(int offset,String string, AttributeSet attributes)throws BadLocationException 
		{
			if (string == null) 
			{
				return;
			} 
			else 
			{
				String newValue;
				int length = getLength();
				
				if (length == 0) 
				{
					newValue = string;
				} 
				else 
				{
					String currentContent = getText(0, length);
					StringBuffer currentBuffer = new StringBuffer(currentContent);
					currentBuffer.insert(offset, string);
					newValue = currentBuffer.toString();
				}
				try 
				{
					Double.parseDouble(newValue);
					super.insertString(offset, string,attributes);
				} 
				catch (NumberFormatException exception) 
				{
					Toolkit.getDefaultToolkit().beep();
				}
			}
		}
	}
}

GeneralRe: Validation Pin
David Skelly3-Sep-09 2:39
David Skelly3-Sep-09 2:39 
QuestionRunning Blackberry Application........ Pin
shaina223131-Aug-09 21:41
shaina223131-Aug-09 21:41 
AnswerRe: Running Blackberry Application........ Pin
EliottA2-Sep-09 3:00
EliottA2-Sep-09 3:00 
Questionplease help ... Pin
hitesh.kalra30-Aug-09 23:25
hitesh.kalra30-Aug-09 23:25 
AnswerRe: please help ... Pin
Christian Graus2-Sep-09 14:50
protectorChristian Graus2-Sep-09 14:50 
Questionjava coding Pin
hitesh.kalra30-Aug-09 23:20
hitesh.kalra30-Aug-09 23:20 
AnswerRe: java coding Pin
427748030-Aug-09 23:48
427748030-Aug-09 23:48 
QuestionSVD of image using JAMA.. Pin
ankita0529-Aug-09 20:51
ankita0529-Aug-09 20:51 
AnswerRe: SVD of image using JAMA.. Pin
427748030-Aug-09 12:06
427748030-Aug-09 12:06 
GeneralRe: SVD of image using JAMA.. Pin
ankita0530-Aug-09 15:42
ankita0530-Aug-09 15:42 
QuestionRegarding jdk 1.6 features Pin
kirancgi29-Aug-09 20:23
kirancgi29-Aug-09 20:23 
AnswerRe: Regarding jdk 1.6 features Pin
427748030-Aug-09 12:09
427748030-Aug-09 12:09 
Questiongo through an HTML file and create a list of all the bold and italic words Pin
Sadaiyappan29-Aug-09 9:14
Sadaiyappan29-Aug-09 9:14 
AnswerRe: go through an HTML file and create a list of all the bold and italic words Pin
427748030-Aug-09 12:18
427748030-Aug-09 12:18 
QuestionJava code of Vernam Cipher Algorithm Pin
Munna Bhagat28-Aug-09 6:50
Munna Bhagat28-Aug-09 6:50 
AnswerRe: Java code of Vernam Cipher Algorithm Pin
David Crow28-Aug-09 8:42
David Crow28-Aug-09 8:42 
AnswerRe: Java code of Vernam Cipher Algorithm Pin
427748030-Aug-09 12:22
427748030-Aug-09 12:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.