Java 在处理过程中,如何在JOptionPane.showMessageDialog()中显示形状?
部分需求是在中复制条形图 我试着这样做,看看是否可以在对话窗口中显示矩形(显然它不起作用):Java 在处理过程中,如何在JOptionPane.showMessageDialog()中显示形状?,java,swing,processing,Java,Swing,Processing,部分需求是在中复制条形图 我试着这样做,看看是否可以在对话窗口中显示矩形(显然它不起作用): rectMode(中心); //阿尔伯塔省 if(prov_id.equals(“AB”)| prov_id.equals(“AB”)) { 如果(gross_income>=0&&gross_income=0&&gross_income显示条形图的窗口不是来自JOptionPane.showMessageDialog()的窗口,因为该窗口名为“TaxCalculator_kEY”,我假设它是文件名,而
rectMode(中心);
//阿尔伯塔省
if(prov_id.equals(“AB”)| prov_id.equals(“AB”))
{
如果(gross_income>=0&&gross_income=0&&gross_income显示条形图的窗口不是来自JOptionPane.showMessageDialog()的窗口,因为该窗口名为“TaxCalculator_kEY”,我假设它是文件名,而不是“Message”。不是非常详细的答案,只是一个提示(因此,只有一条注释):您可以创建任意组件(例如JLabel
或JPanel
,并在其上绘制矩形等内容),只需通过调用JOptionPane.showMessageDialog(框架,您的组件带有tuffonit)将其显示在对话框中即可
您确定要使用处理吗?这看起来像是纯Swing,而不是处理。或者,您确定必须在消息对话框中显示它吗?我意识到显示条形图的窗口很可能不是来自JOptionPane.showMessageDialog()的窗口,因为该窗口名为“TaxCalculator_kEY”不是“Message”。
rectMode(CENTER);
// Alberta
if ( prov_id.equals("AB") || prov_id.equals("ab"))
{
if (gross_income>=0&&gross_income<=40000)
{
tax_rate=0.25;
JOptionPane.showMessageDialog(frame,"Province: "+ prov_id + "\nGross Income: "+ gross_income + "\nTax Rate: "+ tax_rate+ "\nTax Amount: "+ tax_amount+"\nNet Income: "+ net_income + rect(10,10,10,10));
}
import javax.swing.JOptionPane;
//Input Variables
String prov_id = ""; //province_id will contain the user input for the province (E.g. 'AB').
float gross_income = 0; //gorss_income contains the user input for gross income (E.g. 30000).
//Output Variables:
//You will store the result of your analysis and calculations in these variables
float tax_rate = 0; //Variable tax_rate will hold the tax_rate percentage. You will assign a value for tax_rate based on the Taxable Income (Table 1) table given in the studio project document.
//The value of tax ranges between 0 to 1 (E.g. for Alberta, income of equal or less than $40000 tax = 0.25)
float net_income = 0; //Net income is calculated based on tax_rate. It is the take-home income after taxes are deducted.
//i.e. net_income = gross_income * (1 - tax_rate);
float tax_amount = 0; //tax amount is the amount of taxes paid based on gross income depending on the province.
//i.e. tax_amount = gross_income * tax_rate;
// prompt for and read the province id
prov_id = JOptionPane.showInputDialog("Please enter your province's two-letter abbreviation (e.g., AB for Alberta): ");
// prompt for and read the gross income
String answer = JOptionPane.showInputDialog("Please enter your taxable income: ");
//convert user input to folat
gross_income = Float.parseFloat(answer);
net_income=gross_income*(1-tax_rate);
tax_amount=gross_income*tax_rate;
rectMode(CENTER);
// Alberta
if ( prov_id.equals("AB") || prov_id.equals("ab"))
{
if (gross_income>=0&&gross_income<=40000)
{
tax_rate=0.25;
JOptionPane.showMessageDialog(frame,"Province: "+ prov_id + "\nGross Income: "+ gross_income + "\nTax Rate: "+ tax_rate+ "\nTax Amount: "+ tax_amount+"\nNet Income: "+ net_income);
}
}