/////////////////////////////////////////////////////////MAIN.JAVA//////////////////////////////////////////////////////////////////
//Akshat Shah
//IT 313
//Project 2
// Source code file: Main.java
// Instantiate a MyFrame object derived from the
// JFrame class. The MyFrame object contains a JPanel
// object that displays a Swing drawing using Graphics
// methods.
public class main {
public static void main(String[] args) {
new MyFrame();
}
}
//////////////////////////////////////////////////////MYFRAME.JAVA//////////////////////////////////////////////////////////////////
//Akshat Shah
//IT 313
//Project: Drawing
// No modules defined in project
// Source code file: MyFrame.java
// Define MyFrame from Swing class JFrame.
import javax.swing.*;
import java.awt.*;
public class MyFrame extends JFrame {
private MyPanel p = null;
public MyFrame()
{
// Set caption in title bar to "Drawing Project"
super("Akshat's drawing project!");
// Create and add panel to frame.
p = new MyPanel();
p.setLayout(new FlowLayout());
setContentPane(p);
// Configure frame.
setSize(400, 500);
setVisible(true);
}
}
//////////////////////////////////////////////////////MYPANEL.JAVA//////////////////////////////////////////////////////////////////
//Akshat Shah
//IT 313
// No modules defined in project
// Source code file: MyPanel.java
// Define MyPanel class derived from Swing class JPanel.
// Use Graphics methods to draw on panel.
//Gives graphical user interface i.e. is drawing for the java program created on this page
import javax.swing.*;
//It contains all of the classes for creating the drawing
import java.awt.*;
//extends means "is a" mypanel is a jpanel, jpanel is inheritance
public class MyPanel extends JPanel {
//setting the background color to white
public MyPanel( ) {
setBackground(Color.white);
}
// The paintComponent method is invoked
// whenever paint event occurs. This occurs
// when the panel is
// (1) first displayed.
// (2) restored after being minimized.
// (3) exposed after being hidden.
public void paintComponent(Graphics g) {
super.paintComponent(g);
// Printing the title that appears at the top of the drawing.
//setcolor changes the color of the object I am drawing
//drawstring is way to put text in this drawing
g.setFont(new Font("arial", Font.BOLD, 30));
g.setColor(Color.black);
g.drawString("Akshat's Java Project!", 60, 60);
//Drawing bottom part of the background(Green Grass)
// fillrect method allows me to draw a rectangle color filled in it
g.setColor(Color.green);
g.fillRect(1,500 , 1300, 300);
// Drawing Triangle with the help of draw polygon method(Roof of the house)
//fillpolygon allows me to draw any traingular type shapes while filling that object with the color I have set.
g.setColor(Color.DARK_GRAY);
g.fillPolygon(new int[] {240, 500, 730}, new int[] {298, 70, 300}, 3);
//Draw the rectangle(Body of the house)
g.setColor(Color.yellow);
g.fillRect(240, 300, 490, 350);
//Drawing the door(Door Frame) with rectangle method
g.setColor(Color.black);
g.fillRect(420, 340, 150, 310);
//Drawing the door(Door) With rectangle method
g.setColor(Color.white);
g.fillRect(430, 350, 130, 295);
//Drawing the door knob
//fill oval method allows me to draw circular shapes objects and fill it with the color I have set
g.setColor(Color.black);
g.fillOval(540, 510, 20, 20);
//Drawing the window Frame(1)
g.setColor(Color.black);
g.fillRect(620, 340, 100, 100);
//Drawing the Window(1)
g.setColor(Color.white);
g.fillRect(627, 348, 85, 85);
//Drawing the window frame (Vertical Bar)(1)
g.setColor(Color.black);
g.fillRect(665, 348, 10, 90);
//Drawing the window frame(Horizontal Bar)(1)
g.setColor(Color.black);
g.fillRect(627, 385, 90, 10);
//Drawing the window Frame(2)
g.setColor(Color.black);
g.fillRect(250, 340, 100, 100);
//Drawing the Window(2)
g.setColor(Color.white);
g.fillRect(257, 348, 85, 85);
//Drawing the window frame (Vertical Bar)(2)
g.setColor(Color.black);
g.fillRect(295, 348, 10, 90);
//Drawing the window frame(Horizontal Bar)(2)
g.setColor(Color.black);
g.fillRect(255, 385, 90, 10);
//Drawing nail on door two hold the name plate
g.fillOval(482, 400, 15, 15);
//Drawing two lines on door for holding the name plate
g.drawLine(490, 400, 460, 450);
g.drawLine(490, 400, 520, 450);
//Drawing rectangle for name plate
g.fillRect(450, 450, 80, 20);
//Write the name on the name plate
g.setFont(new Font("arial", Font.BOLD, 20));
g.setColor(Color.white);
g.drawString("IT 313", 460, 468);
//Drawing the body of the person
g.setColor(Color.black);
g.fillRect(780, 500, 80, 100);
//Drawing the face of the person
g.setColor(Color.pink);
g.fillOval(780, 450, 60, 60);
//Drawing the hair
//fill arc allows me to draw any complicated shapes like curve shapes
g.setColor(Color.black);
g.fillArc(780, 450, 55, 30, 0, 180);
//Drawing Eyes and Nose.
g.setColor(Color.black);
g.fillOval(790, 470, 10, 10);
g.fillOval(810, 470, 10, 10);
g.fillOval(800, 480, 10, 10);
//Drawing the smiling mouth
g.fillArc(800, 490, 15, 10, 0, -180);
//Drawing the person's hands.
g.setColor(Color.pink);
g.fillRect(760, 450, 20, 60);
g.setColor(Color.pink);
g.fillRect(850, 500, 20, 60);
//Drawing the person's legs.
g.setColor(Color.GRAY);
g.fillRect(780, 600, 38, 70);
g.setColor(Color.gray);
g.fillRect(822, 600, 38, 70);
//Creating my own color and setting it to the background
Color myWhite = new Color(135, 206, 250);
setBackground(myWhite);
//Creating birds using arc method
g.drawArc(300, 100, 20, 10, 0, 150);
g.drawArc(320, 100, 20, 10, 0, 190);
g.drawArc(380, 120, 20, 10, 0, 150);
g.drawArc(400, 120, 20, 10, 0, 190);
g.drawArc(600, 100, 20, 10, 0, 150);
g.drawArc(620, 100, 20, 10, 0, 190);
g.drawArc(660, 80, 20, 10, 0, 150);
g.drawArc(680, 80, 20, 10, 0, 190);
//Drawing flowers
g.fillRect(8, 600, 2, 70);
g.setColor(Color.MAGENTA);
g.fillOval(10, 600, 30, 30);
g.fillOval(10, 580, 30, 30);
g.fillOval(-10, 580, 30, 30);
g.fillOval(-10, 600, 30, 30);
g.setColor(Color.yellow);
g.fillOval(3, 595, 20, 20);
g.fillRect(88, 600, 2, 70);
g.setColor(Color.MAGENTA);
g.fillOval(90, 600, 30, 30);
g.fillOval(90, 580, 30, 30);
g.fillOval(70, 580, 30, 30);
g.fillOval(70, 600, 30, 30);
g.setColor(Color.yellow);
g.fillOval(85, 595, 20, 20);
}
}