火曜日, 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)

I2S プロトコル

I²S(Inter-IC Sound)は、マイコンやオーディオ機器間で音声データをやり取りするために設計された、シリアル通信プロトコルです。I²CやSPIと名前は似ていますが、I²Sは音声専用のプロトコルです。 I²Sは、以下の3つの主要な信号線を使って通信します。 BCLK (...