appletというものは使わなくても,グラフは書けるのでしょうか.
以下のコードでグラフが書けるのですが,appletというものは今後廃止に向かっているという話を聞いて,appletなしでグラフ化したいのですが,やりかたはあるのでしょうか.質問が投げやりになってしまい申し訳ありません.
import java.applet.;
import java.awt.;
public class Rose extends Applet{
int width, height;
public void init(){ width = getSize().width; height = getSize().height; setBackground(Color.White); SetForeground(Color.red); } public void paint(Graphic g){ double a=100, r,rad=2.0*Math.PI/100, th; int xc = width/2, yc = height/2; int x0 = xc, y0 = yc, x1,y1; for(int i=1; i<=100; i++){ th = rad*(double)i; r = a*Math.sin(2.0*th); x1 = xc+(int)(r*Math.cos(th)); y1 = yc-(int)(r*Math.sin(th)); g.drawLine(x0,y0,x1,y1); x0 = x1; y0 = y2; } }
}
受け売りですが、ソースコードは```Java ソースコード```でcodeタグで挟んでくださいね。あと10行目:setBackground(Color.white); 11行目:setForeground(Color.red); 23行目:x0 = x1; y0 = y1; とも修正してくださいね。
回答1件
あなたの回答
tips
プレビュー