Article View: cn.bbs.comp.lang.java
Article #24361Re: ��������������ȡ���ģ�
From: diff.bbs
Date: Mon, 19 Jan 1998 00:00
Date: Mon, 19 Jan 1998 00:00
159 lines
7291 bytes
7291 bytes
�� �� johntom (john) �Ĵ������ᵽ: ��
: hi,��Һã�����һ�������ģ���������java�����Ƽ���
: ���ÿ����ҵ����ˡ�
:
: ����һ�����⣬�Ѿ�������һ���������ˣ�ϣ�������
: ���ֲ��ߴͽ̣�
:
: ����JDBC��д��ݿ������getString()ȥȡ����
: ����ʱ��ȡ����ȴ���ҷ����execteUpdate()����ݿ�
: ��д����ʱ��д��ȥ��Ҳ���ҷ�֪��ν����
:
: ���õ���JDK1.1.1.
:
�Ҹ�ݸ��˾��飬��������½��飬���ܸ���ط���ȷ�����Ҿ���
��������Ч��ʵ�õġ�
�ÿ������ʲô�룬ͨ��ͬ�������������?ͬ���룬
�����unicode,��ô��getChar()��Ӧ��ȡ�õ���һ���ֵ�
unicode�룬�����GB�룬��ô���������getString()����ʱ
ϵͳӦ����Ϊ��Ķ�����UTF�룬��ˣ������ͨ�����������
���GB�룬����˵����ͨ��getBytes()��getByte()���������
GB��ֵ��
���ԣ���һ�����������ȷ��ȡ����Ҫ���룬������Ҳ��̫���
��ľ����̻�������������Լ���Щʵ�飬���ܴ������
ͷ�����õ������ȷ����ֵ��������unicode����GB.
��һ��������ΰ���ֵ��ȷת��ΪҪ��ʾ��String��������⡣
��Ϊ���Ҹ���ӡ���У�����AWT�ַ���ʾ��������ͨ���String
����IJ�������ɵġ�
���ȣ������unicode�룬��ô�Ҽ�����ȡ������char[]�������
��new String( (char[]) ..) ���ɣ�
������ȷ��String������Ҫ���ĵ�����ǰ���JDK 1.1
Internationalization����˵��������ȷ�������font.properties
�ļ�������ܶ�����¼ذ�font.properties.zh����
font.properties �Dz����ģ�Ҫ�����ĵ���˵����ϸ���òųɡ�
������ĵ�����BMC������ǰ�����¡�
�����ȡ�õ���GB�룬��ʱ�Ҽ�����õ�����byte[]������
ʱ���������õ���unicodeΪ���String��������
ת����ת����ƽ̨��ص�sun.io.*�еĶ������ж��ڼ������ģ�
�ֱ�ΪByteToCharGB2312 ��CharToByteGB2312�������������
����̣������ͨ�����̿�����������������ã���ͨ������
Ҳ�ܲµ�ǰ����GB -> Unicode������� unicode -> GB�ġ�
ͨ�������ת������Ҳ�ܵõ���ȷ��unicode String����
��ʱ�����ظ�����ĵ�����Ϳ�����ȷ��ʾ�õ�������ʾ��
Ȼ�����AWT�еIJ���ԭ�еķ�light weight�����磬List
TextField, TextArea,������String����ʾ���ġ���õ��Ľ��
���Ǽ�������������ƽ̨�ġ�
���в���ȷ�Ķ�������������ʡ���ӭ���Ժ�������������¡�
<pre>
import java.awt.event.*;
import java.awt.*;
import sun.io.*;
import java.io.*;
public class JTst extends Frame
{
// You must declare the following converter here.
// ByteToCharGB2312 - GB to Unicode.
// CharToByteGB2312 - Unicode to GB.
ByteToCharGB2312 GB2UNIConvertor = new ByteToCharGB2312();
CharToByteGB2312 UNI2GBConvertor = new CharToByteGB2312();
ByteToCharGB2312 c1 = GB2UNIConvertor;
CharToByteGB2312 c2 = UNI2GBConvertor;
InerPanel tstPane = new InerPanel();
public static void main(String argv[])
{
JTst tstFrm = new JTst();
tstFrm.add( tstFrm.tstPane );
String menuStr1 = new String( tstFrm.conver( new String("�ļ�") ) );
String menuStr1_1 = new String( tstFrm.conver( new String("�½�") ) );
String menuStr1_2 = new String( tstFrm.conver( new String("��") ) );
String menuStr1_3 = new String( tstFrm.conver( new String("�洢") ) );
String menuStr2 = new String( tstFrm.conver( new String("�༭") ) );
String menuStr2_1 = new String( tstFrm.conver( new String("����") ) );
String menuStr2_2 = new String( tstFrm.conver( new String("����") ) );
String menuStr2_3 = new String( tstFrm.conver( new String("���") ) );
MenuBar menu_bar = new MenuBar();
Menu menu1 = new Menu( menuStr1 );
MenuItem menu1_1 = new MenuItem( menuStr1_1 );
MenuItem menu1_2 = new MenuItem( menuStr1_2 );
MenuItem menu1_3 = new MenuItem( menuStr1_3 );
menu1.add( menu1_1 ); menu1.add( menu1_2 ); menu1.add( menu1_3 );
Menu menu2 = new Menu( menuStr2 );
MenuItem menu2_1 = new MenuItem( menuStr2_1 );
MenuItem menu2_2 = new MenuItem( menuStr2_1 );
MenuItem menu2_3 = new MenuItem( menuStr2_1 );
menu2.add( menu2_1 ); menu2.add( menu2_2 ); menu2.add( menu2_3 );
menu_bar.add( menu1 ); menu_bar.add( menu2 );
tstFrm.setMenuBar( menu_bar );
tstFrm.setVisible( true ); tstFrm.setSize( 320 , 200 );
tstFrm.setLocation( 50, 50 );
tstFrm.addWindowListener( new WindowAdapter(){
public void windowClosing( WindowEvent e )
{ System.exit(0); } } );
}
char[] conver( String str_in )
{
char[] new_char = null;
try{ new_char = c1.convertAll( str_in.getBytes() ); }
catch( MalformedInputException e ) {}
int len = new_char.length;
return new_char;
}
public class InerPanel extends Panel
{
public void paint(Graphics g)
{
char[] ch = {0x5e01, 0x5e02, 0x5e03, 0x5e04 };
String tmpStr = new String( ch );
g.drawString(tmpStr, 50, 50 );
}
}
}
</pre>
--
[1;36m ��Դ: ����������BBSվ��bbs.nease.net�E[FROM: www-post@bbs.nease.n]
Technical Details
Message-ID:
<3MaK4D$7Kl@bbs.nease.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: Chinese,GB X-Google-Thread: f6cb0,f33d1911fa4c9572 X-Google-Attributes: gidf6cb0,public From: diff.bbs@bbs.nease.net () Subject: Re: ��������������ȡ���ģ� Date: 1998/01/19 Message-ID: <3MaK4D$7Kl@bbs.nease.net> X-Deja-AN: 317365490 X-Filename: Java/M.885224653.A Organization: gzdcb Newsgroups: cn.bbs.comp.lang.java,