- 710 名前:688 mailto:sage [2007/04/17(火) 11:52:43 ]
- >>709
1の問題を自分なりにわかりやすく解いてみたのですが、線が点線のようになってしまいます。 なにが足りないのでしょうか? package Ex1; import java.applet.Applet; import java.awt.Graphics; public class level1 extends Applet { public void paint(Graphics g) { drawLine1(g, 100, 100, 600, 300); drawLine2(g, 100, 100, 300, 600); } private void drawLine1(Graphics g, int x1, int y1, int x2, int y2) { for (int y = y1; y < y2; y += 1) { double x = x1 + (double) (x2 - x1) / (y2 - y1) * (y - y1); setPixel(g, x, y); } } private void drawLine2(Graphics g, int x1, int y1, int x2, int y2) { for (int x = x1; x < x2; x += 1) { double y = y1 + (double) (y2 - y1) / (x2 - x1) * (x - x1); setPixel(g, x, y); } } private void setPixel(Graphics g, double x, double y) { g.fillRect((int) x, (int) y, 1, 1); } }
|

|