Advertisement
letsdoitjava

Stickman

Jul 16th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.07 KB | None | 0 0
  1. // Stickman program that generates a stickman figure
  2. // Renee Waggoner
  3. // July 26, 2019
  4. // Special Requirements: None
  5. package stickman;
  6. import java.awt.Color;
  7. import java.awt.Dimension;
  8. import java.awt.Graphics;
  9. import javax.swing.JFrame;
  10.  
  11. public class Stickman extends JFrame {
  12.  
  13.         Stickman (String name)
  14.         {
  15.                 // setting background
  16.                 super(name);
  17.                 setSize (500, 500);
  18.                 setVisible (true);
  19.                 setDefaultCloseOperation (EXIT_ON_CLOSE);
  20.  
  21.         }
  22.        
  23.         public void paint (Graphics g)
  24.         {
  25.                 Dimension d = getSize ();
  26.                 g.setColor (Color.white); //white board
  27.                 g.fillRect (0, 0, d.width, d.height);
  28.                
  29.                 g.setColor(Color. yellow);
  30.                 g.fillRect(200, 164, 60, 150); //body
  31.                 g.fillRect(222, 147, 15, 17); //neck
  32.                 g.fillOval (210, 110, 40, 40); //attaching face to body
  33.                
  34.                
  35.                 g.setColor (Color.black);
  36.                 g.fillRect (217, 100, 28, 14); // hat
  37.                 g.drawOval(210, 110, 40, 40); // line of the face
  38.                 g.fillOval(220, 125, 4, 3); // left eye
  39.                 g.fillOval(237, 125, 4, 3); // right eye                                          
  40.                 // left to right, vertical
  41.                 g.drawLine(210, 314, 200, 380); // left leg
  42.                 g.drawLine(252, 314, 260, 380); // right leg
  43.                 g.drawLine (207, 112, 252, 112); // line of the hat
  44.                 g.drawLine(200, 172, 155, 180); // left arm
  45.                 g.drawLine(260, 172, 300, 180); // right arm
  46.                
  47.                 g.setColor(Color.gray);
  48.                 g.drawLine(228, 132, 231, 132); // nose
  49.                                
  50.                 g.setColor(Color. yellow);
  51.                 g.fillRect(222, 147, 15, 17); //neck
  52.         }
  53.  
  54.         public static void main(String[] args) {
  55.                 Stickman s = new Stickman ("My First Drawing");
  56.         }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement