從沒接觸過程式
一碰就是java語言
初學者的我
面臨史上最大難題
想問以下的程式是為什麼形成
各部份是代表什麼(好像是要做一台車吧)
解釋的越清楚越好,謝謝
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
/**
A car shape that can be positioned anywhere on the screen.
*/
public class Car
{
/**
Constructs a car with a given top left corner
@param x the x coordinate of the top left corner
@param y the y coordinate of the top left corner
*/
public Car(double x, double y)
{
xLeft = x;
yTop = y;
}
/**
Draws the car
@param g2 the graphics context
*/
public void draw(Graphics2D g2)
{
Rectangle2D.Double body
= new Rectangle2D.Double(xLeft, yTop + 10, 60, 10);
Ellipse2D.Double frontTire
= new Ellipse2D.Double(xLeft + 10, yTop + 20, 10, 10);
Ellipse2D.Double rearTire
= new Ellipse2D.Double(xLeft + 40, yTop + 20, 10, 10);
// the bottom of the front windshield
Point2D.Double r1
= new Point2D.Double(xLeft + 10, yTop + 10);
// the front of the roof
Point2D.Double r2
= new Point2D.Double(xLeft + 20, yTop);
// the rear of the roof
Point2D.Double r3
= new Point2D.Double(xLeft + 40, yTop);
// the bottom of the rear windshield
Point2D.Double r4
= new Point2D.Double(xLeft + 50, yTop + 10);
Line2D.Double frontWindshield
= new Line2D.Double(r1, r2);
Line2D.Double roofTop
= new Line2D.Double(r2, r3);
Line2D.Double rearWindshield
= new Line2D.Double(r3, r4);
g2.draw(body);
g2.draw(frontTire);
g2.draw(rearTire);
g2.draw(frontWindshield);
g2.draw(roofTop);
g2.draw(rearWindshield);
}
private double xLeft;
private double yTop;
}
---------------------------------------------------------------------
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Graphics2D;
/**
This applet draws two car shapes.
*/
public class CarApplet extends Applet
{
public void paint(Graphics2D g)
{
Graphics2D g2 = (Graphics2D)g;
Car car1 = new Car(100, 100);
Car car2 = new Car(200, 200);
car1.draw(g2);
car2.draw(g2);
}
}
---------------------------------------------------------------------
為了這個開點數
希望能獲得解答
謝謝各位
2005-04-08 20:35:55 · 3 個解答 · 發問者 Anonymous in 電腦與網際網路 ➔ 程式設計
建議你買書吧
不然看這裡
http://www.jjhou.com/tij2-c-20020711.pdf
記得寫信去感謝侯捷老師
2005-04-11 15:43:56 · answer #1 · answered by Shanfu 6 · 0⤊ 0⤋
那個pdf檔現在可以連了,你試試看吧!
2005-04-12 08:06:48 · answer #2 · answered by Anonymous · 0⤊ 0⤋
非常謝謝你,可是那個網址不能連結耶!參考資料的可以
2005-04-13 10:16:23 補充:
我開那個pdf檔就會當機,是我電腦的問題嗎?= ='''
2005-04-11 22:59:05 · answer #3 · answered by Anonymous · 0⤊ 0⤋