0% found this document useful (0 votes)
6 views

COD26

The document is a Java program that creates a graphical representation of a household scene using Swing. It includes elements such as the sky, sun, clouds, a house, windows, a car, and a tree, all drawn using various shapes and colors. The main method initializes a JFrame to display the drawing on the screen.

Uploaded by

Alma Raquel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

COD26

The document is a Java program that creates a graphical representation of a household scene using Swing. It includes elements such as the sky, sun, clouds, a house, windows, a car, and a tree, all drawn using various shapes and colors. The main method initializes a JFrame to display the drawing on the screen.

Uploaded by

Alma Raquel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

package com.mycompany.

houesehold;

import javax.swing.*;

import java.awt.*;

public class Houesehold extends JPanel {

@Override

protected void paintComponent(Graphics g) {

super.paintComponent(g);

// Escenario

g.setColor(Color.cyan);

g.fillRect(0, 0, 900, 500);

// Sol

g.setColor(Color.orange);

g.fillArc(100, 20, 80, 80, 0, 360);

g.drawLine(95, 55, 75, 55);

g.drawLine(140, 105, 140, 125);

g.drawLine(140, 15, 140, 0);

g.drawLine(185, 60, 205, 60);

g.drawLine(105, 35, 85, 25);

g.drawLine(120, 20, 105, 5);

g.drawLine(100, 80, 80, 90);

g.drawLine(115, 100, 100, 120);

g.drawLine(175, 5, 160, 20);

g.drawLine(205, 25, 175, 35);

g.drawLine(205, 90, 175, 80);

g.drawLine(175, 120, 160, 100);

// the top door


g.setColor (Color.yellow);

g.drawRect (460,200,80,8);

g.fillRect (460,208,40,91);

g.fillRect (500,208,41,91);

g.setColor (Color.white);

g.fillRect (463,211,36,85);

g.fillRect (503,211,35,85);

//cloud

g.setColor (Color.white);

g.fillArc (60,130,80,50,0,360);

g.fillArc (90,120,70,50,0,360);

g.fillArc (130,130,80,50,0,360);

g.fillArc (210,50,80,50,0,360);

g.fillArc (240,30,70,50,0,360);

g.fillArc (260,40,80,50,0,360);

g.fillArc (700,50,80,50,0,360);

g.fillArc (720,40,70,50,0,360);

g.fillArc (760,50,80,50,0,360);

//home

g.setColor (Color.red);

g.fillRect (600,150,150,300);

g.fillRect (430,130,160,20);

g.fillRect (600,130,150,20);

g.setColor (Color.black);

g.fillRect (750,70,10,380);

g.setColor (Color.red);
g.fillRect (400,150,200,300);

g.setColor (Color.black);

g.fillRect (400,150,10,300);

g.setColor (Color.black);

g.fillRect (400,300,350,10);

g.setColor (Color.black);

g.fillRect (590,130,10,320);

g.setColor (Color.black);

g.fillRect (430,130,10,20);

g.setColor (Color.black);

g.fillRect (400,140,40,10);

g.setColor (Color.yellow);

g.fillRect (250,300,150,150);

g.setColor (Color.black);

g.fillRect (250,440,500,10);

// Piso

g.setColor(Color.green);

g.fillRect(0, 450, 900, 100);

//car

g.setColor (Color.blue);

g.fillArc (75,415,140,60,0,180);

g.fillArc (105,400,80,60,0,180);

//glass

g.setColor (Color.white);

g.fillArc (120,404,52,37,0,90);

g.fillArc (113,404,55,36,90,90);

g.fillArc (85,427,7,7,0,360);
g.fillArc (197,427,7,7,0,360);

g.setColor (Color.black);

g.fillArc (100,430,20,20,0,360);

g.fillArc (160,430,20,20,0,360);

g.setColor (Color.white);

g.fillArc (104,434,12,12,0,360);

g.fillArc (164,434,12,12,0,360);

// bottom window

g.setColor (Color.blue);

g.drawRect (295,335,60,8);

g.drawRect (295,335,60,10);

g.fillRect (295,345,30,50);

g.fillRect (325,345,31,50);

g.setColor (Color.white);

g.fillRect (298,347,26,46);

g.fillRect (327,347,26,46);

// top window

g.setColor (Color.yellow);

g.drawRect (650,180,60,8);

g.fillRect (650,188,30,50);

g.fillRect (680,188,31,50);

g.setColor (Color.white);

g.fillRect (652,190,26,46);

g.fillRect (682,190,26,46);

//roof
g.setColor (Color.blue);

int c [] = {380,500,620};

int d [] = {130,60,130};

g.fillPolygon (c, d, 3);

g.setColor (Color.black);

int x [] = {380,500,620};

int y [] = {130,60,130};

g.drawPolygon (x, y, 3);

g.setColor (Color.blue);

int m [] = {515,750,750,620};

int n [] = {70,70,130,130};

g.fillPolygon (m, n, 4);

g.setColor (Color.black);

int q [] = {515,750,750,620};

int z [] = {70,70,130,130};

g.drawPolygon (q, z, 4);

g.setColor (Color.blue);

int k [] = {240,400,400};

int l [] = {300,200,300};

g.fillPolygon (k, l, 3);

g.setColor (Color.black);

int r [] = {240,400,400};

int s [] = {300,200,300};

g.drawPolygon (r, s, 3);

// Árbol

g.setColor(Color.red);

int[] a = {30, 40, 50, 60};

int[] b = {450, 300, 300, 450};

g.fillPolygon(a, b, 4);

g.setColor(Color.green);
g.fillArc(-10, 300, 120, 80, 0, 360);

g.fillArc(-10, 270, 130, 80, 0, 360);

g.fillArc(-10, 240, 110, 100, 0, 360);

g.fillArc(0, 210, 60, 90, 0, 360);

public static void main(String[] args) {

JFrame frame = new JFrame("Dibujo de una Casa");

Houesehold panel = new Houesehold();

frame.add(panel);

frame.setSize(900, 600);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setVisible(true);

You might also like