在 JButton 上显示一个 Unicode 字符
Display an Unicode character on JButton
我正在为计算器编写代码。一切正常,但我得到的不是平方根符号 (√),而是一个问号 (?)。这是否意味着我无法在 JButton
上打印 Unicode 字符,还是我错了?
这里有两个包含所需字符的片段。
String operatorButtonText[] = {"/", "√", "*", "%", "-", "1/X", "+", "=" };
/***************/
if(opText.equals("√"))
{
try
{double tempd=Math.sqrt(temp);
cl.displayLabel.setText(MyCalculator.getFormattedText(tempd));}
catch(ArithmeticException excp)
{cl.displayLabel.setText("Divide by 0.");}
return;
}
这是一张可能有用的图片。
我已经用红圈标记了我的问题。
试试这个。
String SQR = "\u221A";
Button b=new Button(SQR);
我正在为计算器编写代码。一切正常,但我得到的不是平方根符号 (√),而是一个问号 (?)。这是否意味着我无法在 JButton
上打印 Unicode 字符,还是我错了?
这里有两个包含所需字符的片段。
String operatorButtonText[] = {"/", "√", "*", "%", "-", "1/X", "+", "=" };
/***************/
if(opText.equals("√"))
{
try
{double tempd=Math.sqrt(temp);
cl.displayLabel.setText(MyCalculator.getFormattedText(tempd));}
catch(ArithmeticException excp)
{cl.displayLabel.setText("Divide by 0.");}
return;
}
这是一张可能有用的图片。 我已经用红圈标记了我的问题。
试试这个。
String SQR = "\u221A";
Button b=new Button(SQR);