Advertisement
daniel_lawson9999

Daniel Lawson Java 3G Exercises 2,4,6

Apr 12th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.11 KB | None | 0 0
  1. /**
  2.  * Created by Daniel on 4/12/2016.
  3.  */
  4. //Exercise 2
  5. import java.awt.*;
  6. public class Exercise2 {
  7.     public static void main(String[] args){
  8.         DrawingPanel panel = new DrawingPanel(450,150);
  9.         Graphics g = panel.getGraphics();
  10.         drawFigure(g,50,25);
  11.         drawFigure(g,250,45);
  12.     }
  13.     public static void drawFigure(Graphics g, int x, int y){
  14.         Color orange = new Color(255, 141, 0);
  15.         g.setColor(Color.BLACK);
  16.         g.fillOval(x,y,40,40);
  17.         g.fillOval(x+80,y,40,40);
  18.         g.setColor(orange);
  19.         g.fillRect(x+20,y+20,80,80);
  20.         g.setColor(Color.BLACK);
  21.         g.drawLine(x+20,y+20+40,x+20+80,y+20+40);
  22.  
  23.     }
  24.  
  25. }
  26. //-------------------------------------------------------------------------------------------------------------------------------------
  27. //Exercise 4
  28.  
  29. /**
  30.  * Created by Daniel on 4/12/2016.
  31.  */
  32. import java.awt.*;
  33. public class Exercise4 {
  34.     public static void main(String[] args){
  35.         DrawingPanel panel = new DrawingPanel(520,180);
  36.         Graphics g = panel.getGraphics();
  37.         for(int i = 0 ;i<5;i++) {
  38.             Face(g, 10 +i*100, 30);
  39.         }
  40. }
  41.     public static void Face(Graphics g, int x, int y){
  42.         g.setColor(Color.BLACK);
  43.         g.drawOval(x,y,100,100);
  44.  
  45.         g.setColor(Color.BLUE);
  46.         g.fillOval(x+20,y+30,20,20);
  47.         g.fillOval(x+60,y+30,20,20);
  48.  
  49.         g.setColor(Color.RED);
  50.         g.drawLine(x+30,y+70,x+70,y+70);
  51.     }
  52. }
  53.  
  54. //-------------------------------------------------------------------------------------------------------------------------------------
  55. //Exercise 6
  56. /**
  57.  * Created by Daniel on 4/12/2016.
  58.  */
  59. import java.awt.*;
  60. public class Exercise6 {
  61.     public static final int X = 300;
  62.     public static final int Y = 100;
  63.     public static void main(String[] args){
  64.        DrawingPanel panel = new DrawingPanel(X,Y);
  65.         Graphics g = panel.getGraphics();
  66.        design(g,X,Y);
  67.     }
  68.     public static void design(Graphics g,int x,int y){
  69.         for(int i = 1; i <= 4;i++){
  70.             g.drawRect(x/10*i,y/10*i,x - i*(x/5),y-i*(y/5));
  71.         }
  72.     }
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement