Order Now  +1 678 648 4277 

Creating a House Project Help Involving Java.

The following Creating a House Project Help demonstrates how to write a program for creating a house with specified shapes in Java. Our Java Assignment Help programmer wrote an accurate program that meets all the underlying house's requirements.

creating a house project help
Using Absolute coding techniques with the swing API.
7. 6 (at least) other shapes of your choice
You must use absolute coding techniques with the swing API. Your picture must be centered on any screen and shouldn't exceed 1440 by 800 (size). The size of the JFrame should not be changeable by the user. The JFrame must be titled. The Java program mist close when the JFrame is closed.
Solution
import javax.swing.*;
import java.awt.*;
import java.awt.geom.CubicCurve2D;
import java.awt.geom.QuadCurve2D;
public class CanvasFrame extends JFrame {
    public CanvasFrame() {
        setTitle("My canvas");
        getContentPane().add(new Canvas());
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setPreferredSize(new Dimension( 800, 600));
        setResizable(false);
        setVisible(true);
        pack();
    }
    private static class Canvas extends JPanel {
        @Override
        public void paint(Graphics g) {
            // drawing background
            g.setColor(Color.BLUE);
            g.fillRect(0, 0, getWidth(), getHeight());
            // drawing field
            g.setColor(Color.GREEN);
            g.fillArc(-getWidth()/2, 400, 2*getWidth(), 400, 0, 180);
            // drawing house
            int[] housePointsX = new int[]{250, 250, 550, 550};
            int[] housePointsY = new int[]{500, 200, 200, 500};
            g.setColor(Color.YELLOW);
            g.fillPolygon(new Polygon(housePointsX, housePointsY, 4));
            // drawing roof
            int[] roofPointsX = new int[]{220, 400, 580};
            int[] roofPointsY = new int[]{220, 100, 220};
            g.setColor(new Color(128, 64, 0, 255));
            g.fillPolygon(new Polygon(roofPointsX, roofPointsY, 3));
            // drawing door
            g.fillRect(450, 290, 80, 200);
            // drawing door sections
            g.setColor(Color.WHITE);
            int[] doorSectionsX = new int[]{460, 460, 520, 520, 460, 460, 520, 520};
            int[] doorSectionsY = new int[]{400, 300, 300, 400, 400, 480, 480 ,400};
            g.drawPolyline(doorSectionsX, doorSectionsY, 8);
            // drawing window
            g.setColor(Color.CYAN);
            g.fillRoundRect(280, 290, 100, 100, 20, 20);
// g.setColor(Color.RED);
// QuadCurve2D quad = new QuadCurve2D.Double(100, 100, 100, 400, 200, 100);
// ((Graphics2D) g).draw(quad);
            // drawing chimney
            g.setColor(Color.GRAY);
            g.fillRect(280, 120, 30, 80);
            // drawing smoke
            g.setColor(Color.LIGHT_GRAY);
            QuadCurve2D quad1 = new QuadCurve2D.Double(285, 115, 275, 55, 270, 70);
            ((Graphics2D) g).draw(quad1);
            QuadCurve2D quad2 = new QuadCurve2D.Double(305, 115, 315, 55, 320, 70);
            ((Graphics2D) g).draw(quad2);
            CubicCurve2D cubic = new CubicCurve2D.Double(295, 115, 285, 100, 305, 85, 295, 70);
            ((Graphics2D) g).draw(cubic);
        }
    }
    public static void main(String[] args) {
        SwingUtilities.invokeLater(CanvasFrame::new);
    }
}