亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用圖形庫輸出 Java Applet?

如何使用圖形庫輸出 Java Applet?

拉丁的傳說 2022-11-02 15:45:59
我正在嘗試輸出一個數學函數,但我不知道如何調用我的類來繪制/計算該函數。在主課中,我嘗試了以下public class GraphingProgram {public static void main(String[] args) {        Applet program = new Applet();        program.setSize(300, 400);        program.setName("Graphing Program");        GraphApplet testFunction = new GraphApplet();        program.add(testFunction);        program.setVisible(true);    }   班級代碼public class GraphApplet extends Applet{  double f(double x)    {    return (Math.cos(x/5) + Math.sin(x/7) + 2) * getSize().height/ 4;                  }  public void paint (Graphics g)    {        for(int x = 0; x< getSize().width; x++)        g.drawLine(x, (int) f(x), x+1, (int) f(x+1));    }  public String getAppletInfo()    {        return "Draw a function graph";    } }執行程序時,我們應該期望看到類的函數圖。例如,我應該能夠在給定的間隔上輸出圖形 f(x) = cos(x/5) + sin(x/7) + 2,如下所示!https://i.imgur.com/przHRk6.png
查看完整描述

1 回答

?
一只斗牛犬

TA貢獻1784條經驗 獲得超2個贊

在 NetBeansIDE 8.2 中,我只需在 GraphApplet 類中按 F6 即可輸出圖形。



查看完整回答
反對 回復 2022-11-02
  • 1 回答
  • 0 關注
  • 117 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號