• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Hi guys !! I really need your help here ..  RSS feed

 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
Meghna
 
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just try preeping it sideways. That usually works for me. If it doesn't make any difference you can trounce the schlobongs.
 
Meghna ks
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul
I'm sorry, but I could'nt understand a word in the solution you've suggested. Please make it more clear for me so that I could come up with a solution.Fill me in with some inputs the moment you come up with something. This code is inside a funtion which initialises the constructor DateTimeField(myString, 22)
where mystring = "2000/11/11 10:59:10:10" => This is taking inputs more than 12 months in the months field and more than 31 in the days field. and likewise for the time set.
import javax.swing.*;
import javax.swing.text.*;
import java.awt.Toolkit;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Locale;
import java.util.Date;
public class DateTimeField extends com.symantec.itools.javax.swing.JMaskedTextField {
private Toolkit toolkit;
private DateFormat dateFormatter;

public DateTimeField(String val, int columns) {
super(columns);
toolkit = Toolkit.getDefaultToolkit();
//dateFormatter = DateFormat.getDateInstance(new java.util.Locale("US", "US"));
//this.setDocument(new DateTimeDocument());
setValue(val);
}
public String getValue() {
String retVal = null;
//retVal = dateFormatter.parse(getText());
try {
retVal = dateFormatter.parse(getText()).toString();
} catch (ParseException e) {
// This should never happen because insertString allows
// only properly formatted data to get in the field.
toolkit.beep();
}
return retVal;
}
public void setValue(String val) {
//setText(parseValue(val));
setText(val);
//setText(dateFormatter.format(val).toString());
}
protected Document createDefaultModel() {
return new DateTimeDocument();
}
protected class DateTimeDocument extends PlainDocument {
public void insertString(int offs, String str, AttributeSet a)
throws BadLocationException
{
char[] source = str.toCharArray();
char[] result = new char[source.length];
char[] result1 = new char[22];
int j = 0;int i =0;
// for all the chars in source check if its between our limits.
if ( Character.isDigit(source[i]) && (Character.getNumericValue(source[i]) < 10) )
{
result[i] = source[i];
result1[j] = source[i];
i++;j++;
}
else
{
result[i] = '0';
result1[j] = '0';
toolkit.beep();
System.err.println("insertString: " + source[i]);
i++;j++;
}
if ( Character.isDigit(source[i]) && (Character.getNumericValue(source[i]) < 10) )
{
result[i] = source[i];
result1[j] = source[i];
i++;j++;
}
else
{
result[i] = '0';
result1[j] = '0';
toolkit.beep();
System.err.println("insertString: " + source[i]);
i++;j++;
}
if ( Character.isDigit(source[i]) && (Character.getNumericValue(source[i]) < 10) )
{
result[i] = source[i];
result1[j] = source[i];
i++;j++;
}
else
{
result[i] = '0';
result1[j] = '0';
toolkit.beep();
System.err.println("insertString: " + source[i]);
i++;j++;
}
if ( Character.isDigit(source[i]) && (Character.getNumericValue(source[i]) < 10) )
{
result[i] = source[i];
result1[j] = source[i];
i++;j++;
}
else
{
result[i] = '0';
result1[j] = '0';
toolkit.beep();
System.err.println("insertString: " + source[i]);
i++;j++;
}
//result[4] = source[4];
result1[j] = '/';j++;
//month
if ( Character.isDigit(source[i]) && (Character.getNumericValue(source[i]) < 2) )
{
result[i] = source[i];
result1[j] = source[i];
i++;j++;
}
else
{
result[i] = '0';
result1[j] = '0';
toolkit.beep();
System.err.println("insertString: " + source[i]);
i++;j++;
}
if ( Character.isDigit(source[i]) && (Character.getNumericValue(source[i]) < 3))
{
result[i] = source[i];
result1[j] = source[i];
i++;j++;
}
else
{
result[i] = '1';
result1[j] = '1';
toolkit.beep();
System.err.println("insertString: " + source[i]);
i++;j++;
}
//result[7] = source[7];
result1[j] = '/';j++;
//date
if ( Character.isDigit(source[i]) && (Character.getNumericValue(source[i]) < 4) )
{
result[i] = source[i];
result1[j] = source[i];
i++;j++;
}
else
{
result[i] = '0';
result1[j] = '0';
toolkit.beep();
System.err.println("insertString: " + source[i]);
i++;j++;
}
if ( Character.isDigit(source[i]) && (Character.getNumericValue(source[i]) < 10) )
{
result[i] = source[i];
result1[j] = source[i];
i++;j++;
}
else
{
result[i] = '1';
result1[j] = '1';
toolkit.beep();
System.err.println("insertString: " + source[i]);
i++;j++;
}
//result[10] = source[10];
result1[j] = '/';j++;
//hour
if ( Character.isDigit(source[i]) && (Character.getNumericValue(source[i]) < 7) )
{
result[i] = source[i];
result1[j] = source[i];
i++;j++;
}
else
{
result[i] = '0';
result1[j] = '0';
toolkit.beep();
System.err.println("insertString: " + source[i]);
i++;j++;
}
if ( Character.isDigit(source[i]) && (Character.getNumericValue(source[i])< 10) )
{
result[i] = source[i];
result1[j] = source[i];
i++;j++;
}
else
{
result[i] = '0';
result1[j] = '0';
toolkit.beep();
System.err.println("insertString: " + source[i]);
i++;j++;
}
//result[13] = source[13];
result1[j] = '/';j++;
//min
if ( Character.isDigit(source[i]) && (Character.getNumericValue(source[i])< 7) )
{
result[i] = source[i];
result1[j] = source[i];
i++;j++;
}
else
{
result[i] = '0';
result1[j] = '0';
toolkit.beep();
System.err.println("insertString: " + source[i]);
i++;j++;
}
if ( Character.isDigit(source[i]) && (Character.getNumericValue(source[i])< 10) )
{
result[i] = source[i];
result1[j] = source[i];
i++;j++;
}
else
{
result[i] = '0';
result1[j] = '0';
toolkit.beep();
System.err.println("insertString: " + source[i]);
i++;j++;
}
//result[16] = source[16];
result1[j] = '/';j++;
//secj
if ( Character.isDigit(source[i]) && (Character.getNumericValue(source[i])< 7) )
{
result[i] = source[i];
result1[j] = source[i];
i++;j++;
}
else
{
result[i] = '0';
result1[j] = '0';
toolkit.beep();
System.err.println("insertString: " + source[i]);
i++;j++;
}
if ( Character.isDigit(source[i]) && (Character.getNumericValue(source[i])< 10) )
{
result[i] = source[i];
result1[j] = source[i];
i++;j++;
}
else
{
result[i] = '0';
result1[j] = '0';
toolkit.beep();
System.err.println("insertString: " + source[i]);
i++;j++;
}
//result[19] = source[19];
result1[j] = '/';j++;
//mili sec
if ( Character.isDigit(source[i]) && (Character.getNumericValue(source[i])< 7) )
{
result[i] = source[i];
result1[j] = source[i];
i++;j++;
}
else
{
result[i] = '0';
result1[j] = '0';
toolkit.beep();
System.err.println("insertString: " + source[i]);
i++;j++;
}
if ( Character.isDigit(source[i]) && (Character.getNumericValue(source[i])< 10) )
{
result[i] = source[i];
result1[j] = source[i];
i++;j++;
}
else
{
result[i] = '0';
result1[j] = '0';
i++;j++;
toolkit.beep();
System.err.println("insertString: " + source[i]);
}
/*
String ss = new String(result, 0, 16);
System.out.println(" The new String is =" + ss);
super.insertString(offs, new String(result, 0, 16), a);
*/
String ss = new String(result1, 0, 22);
System.out.println(" The new String is ="+ss);
super.insertString(offs, new String(result1, 0, 22), a);
}
}
Thanks
Meghna

 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Meghna:
Could you edit your post to include [ code ] opening and
closing tags (without the spaces) so the code is properly
indented. This makes it easy to read.
Thanks for your cooperation.
- satya
 
Just the other day, I was thinking ... about this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!