使用Java,如何在对话框中显示以下“格式化代码”?
System.out.printf("%20s%20s%20.-5f%n%n", "Assessed Value:", "$", assessedValue);
System.out.printf("%20s%20s%-5f%n%n", "Taxable Amount:", "$", taxedAmount);
System.out.printf("%20s%20s%-5f%n%n", "Tax Rate for $100.00:", "$", taxDollars);
System.out.printf("%20s%20s%-5f%n%n", "Property Tax:", "$", propertyTax);
答案 0 :(得分:2)
您可以使用JOptionPane
类以对话框的形式显示消息。
看起来像这样:
public void showDialog() {
String message = String.format("%20s%20s%20.-5f%n%n", "Assessed Value:", "$", assessedValue) + String.format("%20s%20s%-5f%n%n", "Taxable Amount:", "$", taxedAmount) + String.format("%20s%20s%-5f%n%n", "Tax Rate for $100.00:", "$", taxDollars) + String.format("%20s%20s%-5f%n%n", "Property Tax:", "$", propertyTax);
JOptionPane.showMessageDialog(null, message);
}
答案 1 :(得分:0)
在内部,这些调用仅使用String.format
,您可以使用它来生成对话框的内容。