資源簡介
點陣字庫在JAVA中的實現源碼

代碼片段和文件信息
import?java.io.*;
import?javax.swing.*;
import?java.awt.*;
import?java.awt.image.*;
public?class?Test?extends?Jframe?{
????byte[]?dotfont;
????BufferedImage?imgCH;
????int[]?verify?=?{128?64?32?16?8?4?2?1};
????String?test?=?“點陣漢字的測試“;
????int?imgWidth?=?300;
????int?imgHeight?=?200;
????public?Test()?{
????????super(“DotFont“);
????????File?file?=?new?File(“gb.dat“);
????????try?{
????????????FileInputStream?fis?=?new?FileInputStream(file);
????????????dotfont?=?new?byte[fis.available()];
????????????fis.read(dotfont);
????????????fis.close();
????????}?catch?(FileNotFoundException?ex)?{
????????}?catch?(IOException?ex)?{
????????}
????????this.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
????????this.setSize(300?240);
????????this.show();
????}
????void?createCH(byte[]?ch?int?off)?{
????????int?q1?=?ch[off]?&?0xff;
????????int?q2?=?ch[off?+?1]?&?0xff;
????????int?offset?=?(q1?-?0xa1)?*?94?*?24;
????????q2?-=?0xa1;
????????offset?+=?q2?*?24;
????????imgCH?=?new?BufferedImage(12?12?BufferedImage.TYPE_INT_RGB);
????????for?(int?h?=?0;?h?12;?h++)?{
????????????byte?b?=?dotfont[offset++];
????????????for?(int?w?=?0;?w?8;?w++)?{
????????????????if?((b?&?verify[w])?==?verify[w])?{
????????????????????imgCH.setRGB(w?h?0xffffffff);
????????????????}?else?{
????????????????????imgCH.setRGB(w?h?0);
????????????????}
????????????}
????????????b?=?dotfont[offset++];
????????????for?(int?w?=?0;?w?4;?w++)?{
????????????????if?((b?&?verify[w])?==?verify[w])?{
????????????????????imgCH.setRGB(w?+?8?h?0xffffffff);
????????????????}?else?{
????????????????????imgCH.setRGB(w?+?8?h?0);
????????????????}
????????????}
????????}
????}
????public?void?paint(Graphics?g)?{
????????g.setColor(Color.black);
????????g.fillRect(0?0?getWidth()?getHeight());
????????byte[]?an?=?str2bytes(test);
????????int?offset?=?0;
????????int?x?=?10?y?=?34;
????????while?(y?????????????int?b?=?an[offset]?&?0xff;
????????????if?(b?>?0x7f)?{
????????????????createCH(an?offset);
????????????????g.drawImage(imgCH?x?y?null);
????????????????x?+=?12;
????????????????offset?+=?2;
????????????}?else?{?//英文暫時不考慮
????????????????x?+=?6;
????????????????offset++;
????????????}
????????????if?(x?>?imgWidth)?{
????????????????x?=?10;
????????????????y?+=?14;
????????????}
????????}
????}
????byte[]?str2bytes(String?s)?{
????????if?(null?==?s?||?““.equals(s))?{
????????????return?null;
????????}
????????byte[]?abytes?=?null;
????????try?{
????????????abytes?=?s.getBytes(“gb2312“);
????????}?catch?(UnsupportedEncodingException?ex)?{
????????}
????????return?abytes;
????}
????public?static?void?main(String[]?args)?{
????????new?Test();
????}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2006-11-03?14:30??dotfont_src\
?????文件????????2826??2006-07-18?16:31??dotfont_src\Test.java
?????文件??????196272??2005-08-31?10:46??dotfont_src\gb.dat
?????文件????????2401??2006-07-18?16:31??dotfont_src\Test.class
?????文件???????????9??2006-07-18?17:06??dotfont_src\run.bat
- 上一篇:基于java實現中國象棋小游戲升級版
- 下一篇:Java實現信息安全技術 密鑰分配
評論
共有 條評論