(JAVA)
Use the basic shapes you learned in this chapter to draw a
house. Be sure to include at
least two windows and a door
code so far:
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.shape.LineTo;
import javafx.scene.shape.MoveTo;
import javafx.scene.shape.Path;
public class House extends Application {
@Override
public void start(Stage stage) {
//Creating a Path
Path path = new Path();
Rectangle = new rectangle(20,220);
//Moving to the starting point
MoveTo moveTo = new MoveTo(160,20);
//Creating 1st line
LineTo line1 = new LineTo(20,220 );
LineTo Line2= new LineTo(310,220);
LineTo Line3= new LineTo(160,20);
Polygon paralllogram = new Polygon();
parallelogram.getPoints().addAll(20,220,310,20,20,420,510,20);
//Adding all the elements to the path
path.getElements().add(moveTo);
path.getElements().addAll(line1, Line2, Line3);
//Creating a Group object
Group root = new Group(path);
//Creating a scene object
Scene scene = new Scene(root, 600, 300);
//Setting title to the Stage
stage.setTitle("Drawing an arc through a path");
//Adding scene to the stage
stage.setScene(scene);
//Displaying the contents of the stage
stage.show();
}
public static void main(String args[]){
launch(args);
}
}
import java.applet.Applet;
import java.awt.Graphics;
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Deepak
*/
public class house extends Applet
{
public void paint(Graphics gp)
{
int [] x = {150, 300, 225};
int [] y = {150, 150, 25};
gp.drawRect(150, 150, 150, 200); //House //rectangle
gp.drawRect(200, 200, 50, 150); // Door //rectangle
gp.drawRect(170, 200, 20, 40); // window1 //rectangle
gp.drawRect(260, 200, 20, 40); // window2 //rectangle
gp.drawOval(200, 75, 50, 50); // Up window //oval
gp.drawPolygon(x, y, 3); // Top //polygon
this.setSize(500, 400);
}
}
Using the basic shapes this is done in an easy way.For any queries
pls comment
Get Answers For Free
Most questions answered within 1 hours.