-1
這是我的代碼,迄今爲House類和NeighborHoodDrive類。我想知道我的線對象需要什麼值來爲房子中的每個窗口創建窗口窗格?我希望我的問題明確而充分,我不能提出一個問題,但不幸的是它不會被標記出來。我的線對象需要什麼值爲每個窗口創建窗格?
內訓課:
import javafx.scene.Group;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
import javafx.scene.shape.Polygon;
import javafx.scene.shape.Rectangle;
public class House {
final int BASEWID = 200;
final int BASEHT = 250;
final int DOORWID = 40;
final int DOORHT = 65;
final int WINHT = 40;
final int WINWID = 40;
private Rectangle[] bx = new Rectangle[6]; //base, four windows, doors
private Line[] ln = new Line[8]; //roof and window cross frames
private Circle[] cr = new Circle[1]; //doorknob
private Polygon[] ply = new Polygon[2];
private Group trGrp = new Group(); //group
public House(int xOff, int yOff, Pane pane) {
initHouse();
setX(xOff);
setY(yOff);
pane.getChildren().add(trGrp);
}
//Initialize the house components
public void initHouse() {
//base of house
bx[0] = new Rectangle(DOORWID/2, DOORHT+DOORHT/2, BASEWID, BASEHT);
bx[0].setStroke(Color.BLACK);
bx[0].setFill(Color.IVORY);
//door
bx[1] = new Rectangle(bx[0].getX()+DOORWID+40, bx[0].getY()+DOORHT+120, DOORWID, DOORHT);
bx[1].setStroke(Color.BLACK);
bx[1].setFill(Color.POWDERBLUE);
//window 1
bx[2] = new Rectangle(bx[0].getX()+DOORWID-10, bx[0].getY()+DOORHT-30, WINWID, WINHT);
bx[2].setStroke(Color.BLACK);
bx[2].setFill(Color.LAVENDERBLUSH);
//window 2
bx[3] = new Rectangle(bx[0].getX()+DOORWID+90, bx[0].getY()+DOORHT-30, WINWID, WINHT);
bx[3].setStroke(Color.BLACK);
bx[3].setFill(Color.LAVENDER);
//window 3
bx[4] = new Rectangle(bx[0].getX()+DOORWID-10, bx[0].getY()+DOORHT+50, WINWID, WINHT);
bx[4].setStroke(Color.BLACK);
bx[4].setFill(Color.LAVENDER);
//window 4
bx[5] = new Rectangle(bx[0].getX()+DOORWID+90, bx[0].getY()+DOORHT+50, WINWID, WINHT);
bx[5].setStroke(Color.BLACK);
bx[5].setFill(Color.LAVENDERBLUSH);
//doorknob
double crX1 = bx[0].getX() + BASEWID/2.3;
double crY = bx[0].getY() + BASEHT + BASEWID/-7;
double crRad = BASEWID/60;
cr[0] = new Circle(crX1, crY, crRad);
cr[0].setStroke(Color.BLACK);
cr[0].setFill(Color.FLORALWHITE);
//house line
double midX = bx[0].getX() + BASEWID/2;
double leftX = bx[0].getX() - BASEWID/2;
double rightX = bx[0].getX() + BASEWID + BASEWID/2;
double topY = bx[0].getY() - BASEHT/2;
double bottomY = bx[0].getY() + BASEHT/2;
ln[0] = new Line(midX, topY, leftX, bottomY);
ln[1] = new Line(midX, topY, rightX, bottomY);
//top of house
ply[0] = new Polygon(ln[0].getStartX(),ln[0].getStartY(),
bx[0].getX(),bx[0].getY(),
bx[0].getX()+bx[0].getWidth(),bx[0].getY());
ply[0].getPoints().addAll();
ply[0].setStroke(Color.BLACK);
ply[0].setFill(Color.MEDIUMAQUAMARINE);
//window panes
ln[2] = new Line();
trGrp.getChildren().addAll(bx[0], bx[1], bx[2], bx[3], bx[4], bx[5], cr[0], ply[0], ln[2]);
}
// Get the X Coordinate
public double getX()
{
return trGrp.getLayoutX();
}
// Set the X Coordinate
public void setX(double x)
{
trGrp.setLayoutX(x);
}
// Get the Y Coordinate
public double getY()
{
return trGrp.getLayoutY();
}
// Set the Y Coordinate
public void setY(double y)
{
trGrp.setLayoutY(y);
}
}
主要方法:
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.layout.Pane;
import javafx.util.Duration;
public class NeighborhoodDrive extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
//Create a pane to hold the group
Pane pane = new Pane();
House house = new House(175, 75 ,pane);
//Create handler for moving cars
EventHandler<ActionEvent> eventHandler = e ->
{
};
Timeline animation = new Timeline(
new KeyFrame(Duration.millis(25), eventHandler));
animation.setCycleCount(Timeline.INDEFINITE);
animation.play(); // Start animation
//Create a scene and place it in the stage
Scene scene = new Scene(pane, 600, 600);
primaryStage.setTitle("Neighborhood Drive"); // Set the stage title
primaryStage.setScene(scene); // Place the scene in the stage
primaryStage.show(); // Display the stage
}
}
您的代碼示例似乎是Java的,但你標記,如JavaScript你的問題。爲什麼? –
我明白了。我可能只是在推翻它。 – BasdGod
有人可以向我解釋爲什麼我的帖子被拒絕投票嗎?這不可能是因爲沒有研究工作,字面上所有的代碼都在那裏。如果有人不清楚,請解釋一下。 – BasdGod