火曜日, 2月 20, 2007

Java AWT Font setting and TimeZone setting for DateFormat

I just noticed a few things while testing a refurbished machine so I am writing those out here for those who might get stranded in such things. The first one is about AWT Font class. The Font obtained from the Graphics objec won't be used to derive other types of Font object with different font sizes and so on. The way to change fonts is just to create one.

Font large=new Font("Sans Serif",Font.PLAIN,50);
g.setFont(large);

Another thing is about Calendar and DateFormat matter. It is about setting TimeZone. It just is that using DateFormat.setTimeZone(TimeZone) is the way to do it and not to get instance of the Calendar object. Like this:

TimeZone est=TimeZone.getTimeZone("US/Eastern");
Calendar calendar=Calendar.getInstance();
Date date=calendar.getTime();
dateFormat.setTimeZone(est);
String estTimeString=timeFormat.format(date);

Perhaps the above can be illustrated more precisely in a running application. Here is a source file of a Java clock application that shows the time and date in JST and EST time -- Japan and Eastern Standard Time. The application should compile with JDK 6.0.

Source: JavaClock.java

(The above file is modified to adjust the text width in various language environment as of 2007-02-22)

Qt: 外部プログラムを起動する

  Qt/C++ のアプリは、外部へ直接アクセスできます。これはネットアプリでは不可能な Qt のメリットです。 外部プログラムを起動することもできます。QProcess::startDetached() を使うと独立したプロセスを立ち上げることができます。 この QProces...