使用Java在Eclipse中使用Unicode显示棋子 [英] Displaying chess pieces with unicode in eclipse using java
问题描述
我只是想使用Java在日食中显示一些Unicode象棋符号,但是它只会打印出随机的矩形,并且除非最近棋子的样式发生了根本性变化-我不认为这是我想要的。
我的代码:
导入Java。 io.PrintStream;
import java.io.UnsupportedEncodingException;
公共类ChessSymbols {
public static void main(String [] args)抛出
UnsupportedEncodingException {
String unicodeMessage =
\u2654 + //白国王
\u2655 + //白皇后
\u2656 + //白鸦
\u2657 + //白主教
\u2658 + //白骑士
\u2659 + //白卒
\n +
\u265A + //黑王
\u265B + //黑色女王
\u265C + //黑色车
\u265D + //黑色主教
\u265E + //黑色骑士
\u265F + //黑色典当
\n;
PrintStream out =新的PrintStream(System.out,true, UTF8);
out.println(unicodeMessage);
}
}
如果如果您使用Eclipse运行配置来运行代码,则需要设置控制台对话框的字符编码。您可以执行以下操作(我正在检查Indigo,我不确定较早的版本),方法是:调出运行配置,选择有问题的Java运行命令,单击通用选项卡,然后在右侧有一种方法可以选择控制台的字符编码(通常是UTF8,以便您的程序可以使用)。
我是通过在搜索帮助对话框中键入 encoding for console发现的。 / p>
Im just trying to display some unicode chess symbols in eclipse using java, however it just prints out the random rectangles, and unless chess pieces have taken a radical change in style lately- i dont think its what i want. Help is much appreciated!
my code:
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
public class ChessSymbols {
public static void main (String [ ] args)throws
UnsupportedEncodingException {
String unicodeMessage =
"\u2654 " + // white king
"\u2655 " + // white queen
"\u2656 " + // white rook
"\u2657 " + // white bishop
"\u2658 " + // white knight
"\u2659 " + // white pawn
"\n" +
"\u265A " + // black king
"\u265B " + // black queen
"\u265C " + // black rook
"\u265D " + // black bishop
"\u265E " + // black knight
"\u265F " + // black pawn
"\n" ;
PrintStream out = new PrintStream (System.out, true , "UTF8" );
out.println(unicodeMessage);
}
}
If you are using the Eclipse run configuration to run your code, you need to set the character encoding of the console dialog. You can do this (I'm checking Indigo, I am not certain about earlier versions) by bringing up Run Configurations, selecting the Java run command in question, clicking on the Common tab, and on the right there is a way to select the character encoding of the console (which much be UTF8 for your program to work).
I found this out by typing "encoding for console" in the search help dialog.
这篇关于使用Java在Eclipse中使用Unicode显示棋子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!