Mr. Truncale - Robert E. Lee High School
  • Home
  • Digital Media
    • HTML
  • Video Game Design
  • Comp. Programming I
  • Comp. Programming II
  • AP Computer Science
  • 3D Printing
  • Teacher Resources
  • Contact Me

Java Drawing Lab 3


In this lab you will be creating arcs, custom colors and fonts.
This is the code from DrawingBasics.java from drawing Lab 2
import java.awt.*;
import javax.swing.*;

public class DrawingBasics extends JPanel{

   public void paint(Graphics g) {
      super.paint(g);
      Graphics2D g2d = (Graphics2D) g;
      g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,                                           RenderingHints.VALUE_ANTIALIAS_ON);

      g2d.setColor(Color.BLACK);
      //           x1,y1,x2,y2
      g2d.drawLine(0, 0, 200, 200);

      g2d.setColor(Color.RED);
      //           x,y,w,h
      g2d.fillOval(0, 0, 30, 30);
      g2d.drawOval(50, 0, 30, 30);

      g2d.setColor(Color.BLUE);
      //           x,y,w,h
      g2d.fillRect(0, 50, 30, 30);
      g2d.drawRect(50, 50, 30, 30);

      g2d.setColor(Color.GREEN);
      //             text,x,y
      g2d.setFont(new Font("Arial", Font.ITALIC|Font.BOLD, 30));
      g2d.drawString("HELLO World!", 0, 115);

      //Go to colorpicker.com and use the RGB numbers to customize color
      g2d.setColor(new Color(225,145,0));
      //Changes line width
      g2d.setStroke(new BasicStroke(5));
      //          x,y,width,height,startingAngle,arcLengthInDegrees
      g2d.fillArc(0, 150, 30, 30, 0, 180);
      g2d.drawArc(50, 150, 30, 30, 90, 145);

   }

}
Now create a new class called DrawingLab3. Using the code above create the picture below.

Make these changes DrawingRunner.
import javax.swing.*;

public class DrawingRunner {

   public static void main(String args[]){
      JFrame frame = new JFrame("Drawing Lab 3");
      DrawingLab3 game = new  DrawingLab3();
      frame.add(game);
      frame.setSize(400, 400);
      frame.setVisible(true);
      frame.setResizable(false);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   }
}
Picture
400x400

    Turn in DrawingLab3.java

    Max file size: 20MB
Submit
Robert E. Lee High School
1809 Market
Baytown, TX 77520
281-420-4535
digital media | computer programming I and II | BIM
ap computer science | architectural cad | video game design
national technical honor society | contact me