★★ Java の宿題ここで答えます Part 68 ★★at TECH
★★ Java の宿題ここで答えます Part 68 ★★ - 暇つぶし2ch822:デフォルトの名無しさん
10/01/31 21:36:24
>>821
import java.awt.Graphics;
import javax.swing.*;
public class Parabola extends JComponent {
@Override public void paintComponent(Graphics g) {
int w = getWidth(), h = getHeight();
for (int x = 0; x < w; x++) g.drawLine(x, y(x, w, h), x+1, y(x+1, w, h));
}
private int y(int x, int w, int h) { // y = - (4h/w^2)(x - w/2)^2 + h
return (int)(h - 4.0 * h / w / w * (x - w / 2.0) * (x - w / 2.0));
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(new Parabola());
f.setSize(500, 500);
f.setVisible(true);
}
});
}
}


次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch