public void paintComponent( Graphics g)
{
super.paintComponent( g);
Graphics2D g2 = (Graphics2D)g;
Rectangle r = getBounds();
System.out.printf("width = %d height = %d " +
"bounds = [%d, %d, %d, %d]%n",
getWidth(), getHeight(),
r.x, r.y, r.width, r.height);
g2.setPaint(Color.magenta);
g2.draw(r);
g2.setPaint(Color.black);
x1 = 0; x2 = 0; y1 = 0; y2 = 0;
while( x1 < 1000)
{
x2 = x1 + 1;
y1 = a * x1 * x1 + b * x1;
y2 = a * x2 * x2 + b * x2;
if(x1 == 200) {
System.out.printf("x1 = %d y1 = %d%n", x1, y1);
g2.setPaint(Color.red);
g2.fill(new Ellipse2D.Double(x1-1.5, y1-1.5, 4, 4));
g2.setPaint(Color.green.darker());
g2.fill(new Ellipse2D.Double(200 + x1, 200 - y1, 4, 4));
g2.setPaint(Color.blue);
g2.drawLine(200, 200, x1, y1);
g2.setPaint(Color.black);
}
g.drawLine( 200 + x1, 200 - y1,200 + x2, 200 - y2 );
g.drawLine( 200 - x1, 200 - y1,200 - x2, 200 - y2 );
x1 = x2;
}
} |