Monday, January 12, 2009

Setting the current time in a J2ME DateField with mode TIME

So many wasted hours! arg!

If you wanted to create a DateField with only time input (i.e. ask the user to input the time only, not a date as well), with the default value the current system time, all the documentation would point to doing it like this:


DateField df = new DateField ("Enter time:", DateField.TIME);
df.setDate(new Date());


That doesn't work, though. To set the current time in a date field, you need to pass in a date with the year, month and day values of the epoch, and the time that you want to set into the field. Like this:


Calendar epoch = Calendar.getInstance();
epoch.setTime(new Date(0));

Calendar currentTime = Calendar.getInstance();
currentTime.setTime(new Date());
currentTime.set(Calendar.YEAR,epoch.get(Calendar.YEAR));
currentTime.set(Calendar.MONTH,epoch.get(Calendar.MONTH));
currentTime.set(Calendar.DATE,epoch.get(Calendar.DATE));

DateField df = new DateField ("Enter time:", DateField.TIME);
df.setDate(new Date());

Monday, August 25, 2008

JMF on Ubuntu

Two tweaks seem to be needed to use JMF to capture video from a webcam on Ubuntu:

1. As described in this thread, you need to edit the install script (before running it as it erases itself when run!) you get off Sun's site
- edit the file using vim -b as it is partially a binary file
- change the arguments to tail from 'tail +309' to 'tail -n+309'

2. As described in this thread, copy all the libraries (.so files) in JMFHOME/lib/ to /usr/lib, and run ldconfig (as root) to update.For distribution you would obviously want to do this differently, this is just a quick hack to get started

Friday, January 04, 2008

7 months on..

I can't say why I'm suddenly back at blogging. Possible factors include:

- New years' resolution to waste less time on Internet randomness
- Presence of 4 essay deadlines (for a total of 14000 words) in the next 7 days, hence a *very* good reason not to waste more time on Internet randomness
- The realization that, 7 months on, 'cups+java printing aargh' is still a recurrent theme in my life
- The almost total decline of all areas of my life not occurring indoors (or rather, in this one dodgy university-issue chair, in my very small room)

Whatever, welcome to 2007!

Except that of course, it's 2008 now. Give me a few months.

Monday, June 04, 2007

CUPS + Java Printing Aaargh

After being able to print fine from Java in Ubuntu Edgy, I upgraded to Feisty and found that Java was now unable to detect printers using PrintServiceLookup.lookupPrintServices(null, null);

A couple of frustrating hours later, I found this article on the CUPS website explaining the problem (a Java bug, caused by updating to CUPS 1.2). The fix is:

In cupsd.conf, comment out:

#Listen /var/run/cups/cups.sock

leave uncommented:

Listen localhost:631

Another weird Java / CUPS problem I came across was that some Java versions will apparently refuse to print to printers with a - or an @ in the printer name. This wasn't my problem, but it's probably best avoiding these anyway.

Friday, May 25, 2007

*shiver*

Kokstad is officially the coldest and most unfortunately named South African town I've been to. The small 800W heater I'm huddling next seems incapable of heating anything further than 30cm away, and burns everthing closer than that.

I'm flying home tomorrow after a week of interviewing district municipalities about water quality monitoring, and showing them a demo of the cellphone reporting system I've developed for my masters (and/or, work). The response has been very positive, particularly in rural districts where they struggle to reach many small, remote water supply schemes.


... and as if that wasn't enough grouching, the power just went out. This has happened a lot in the last week - 2 of the 6 interviews we did took place in the dark.

We've driven through some quite beautiful places, on some difficult roads - my cow avoidance skills are improving. Luckily, cows seem to have a kind of inertia about them - once they decide to head off slowly across the road, they generally keep moving in the same direction, albeit at their own pace and oblivious to passing cars.

Transkei traffic officials have a similar inertia - I swear the two who trapped me doing 77 in a 60 zone, were in exactly the same place the last time I was on this road, maybe 7 years ago.

There's snow everywhere! The oxcart maybe isn't as remarkable, although the photo was taken on the N2, which makes this one seriously brave ox.


Friday, April 13, 2007

Someone saying something worth saying

"I am a humanist, which means, in part, that I have tried to behave decently without any expectation of regards or punishments after I'm dead."

"If I should ever die, God forbid, let this be my epitaph:

THE ONLY PROOF HE NEEDED
FOR THE EXISTENCE OF GOD
WAS MUSIC"



Source of both quotes is slashdot's um, "epitaph thread" following the death of Kurt Vonnegut yesterday.

Tuesday, April 10, 2007

Lion's Head Sunset