Membatasi hanya karakter angka - Java - Publisher - Royz Rambo
Ilham Penta
Site menu
Section categories
My articles [6]
Java [14]
Java Programming
Flash [6]
Flash
URL web dan Tutorial [29]
Petualangan [1]
Our poll
Rate my site
Total of answers: 19
Statistics

Total online: 2
Guests: 2
Users: 0
Login form
Main » Articles » Java

Membatasi hanya karakter angka

Buat kelas baru pada package, dan pastekan kode ini

public PlainDocument getOnlyDigit(){
PlainDocument filterDigit = new PlainDocument(){
public void insertString(int offs, String str, AttributeSet a)throws BadLocationException{
StringBuffer buffer = new StringBuffer();
int s= 0;
char[]dataInput = str.toCharArray();
for (int i = 0; i < dataInput.length; i++){
boolean isOnllyDigit = Character.isDigit(dataInput[i]);
if(isOnllyDigit == true){
dataInput[s] = dataInput[i];
s++;
}
}
buffer.append(dataInput, 0, s);
super.insertString(offs, new String(buffer), a);
}
};
return filterDigit;
}


untuk importnya gunakan:

import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;

Category: Java | Added by: penta (2010-09-24)
Views: 325 | Rating: 0.0/0
Total comments: 0
Name *:
Email *:
Code *:
Search
Site friends
  • Create a free website
  • Copyright Penta.Inc © Powered By: Senjapala