簡體   English   中英

如何在處理中的 JOptionPane.showMessageDialog() 中顯示形狀?

[英]How would I display a shape in JOptionPane.showMessageDialog() in Processing?

部分要求是復制https://imgur.com/a/Gx2XOql中的條形圖

我試過這個,看看我是否可以在對話 window 中矩形(顯然它沒有工作):

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));

    }

我的代碼的rest:

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);

    }

  }

預期的輸出應該是這樣的: https://imgur.com/a/Gx2XOql

到目前為止,我的代碼顯示如下: https://imgur.com/a/Gx2XOql

顯示條形圖的 window 不是來自 JOptionPane.showMessageDialog() 的處理,因為 window 被命名為“TaxCalculator_kEY”,我假設它是文件的名稱,而不是“消息”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM