Agenda For Feb 23 2. Finish up Unit 3 Exercises on page 20 4. Unit 4 Exercises on page 33. Question #2 3. Create a Happy Face Java Applet (due next class).

Slides:



Advertisements
Similar presentations
PowerPoint Heaven – The Power to Animate
Advertisements

2D Graphics Drawing Things. Graphics In your GUI, you might want to draw graphics E.g. draw lines, circles, shapes, draw strings etc The Graphics class.
PHY-102 SAPIntroductory GraphicsSlide 1 Introductory Graphics In this section we will learn how about how to draw graphics on the screen in Java:  Drawing.
Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
Building Java Programs Supplement 3G Graphics Copyright (c) Pearson All rights reserved.
Building Java Programs Supplement 3G Graphics Copyright (c) Pearson All rights reserved.
Copyright 2008 by Pearson Education Building Java Programs Graphics Reading: Supplement 3G.
1 Chapter 15 l Basic Figures l Colors l Fonts and Other Text Details Graphics Objects.
Chapter Day 5. © 2007 Pearson Addison-Wesley. All rights reserved2-2 Agenda Day 5 Questions from last Class?? Problem set 1 Posted  Introduction on developing.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Topics  Applets  Classes used for graphics Graphics Point Dimension.
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
2D Graphics in Java COMP53 Nov 14, Applets and Applications Java applications are stand-alone programs – start execution with main() – runs in JVM.
A Simple Applet --- Digital Clock import java.awt.*; import java.util.Calendar; public class DigitalColok extends java.applet.Applet implements Runnable.
Copyright 2008 by Pearson Education Building Java Programs Graphics reading: Supplement 3G videos: Ch. 3G #1-2.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 5 Java Graphics Applets.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 5 Applets and Graphics.
Copyright 2008 by Pearson Education Building Java Programs Graphics reading: Supplement 3G videos: Ch. 3G #1-2.
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
Chapter 5 Graphics. Topics Applets Classes used for graphics –Graphics –Point –Dimension –Color.
1 Drawing Shapes and Text With Applets. 2 Drawing in the paint method import java.awt.*;// access the Graphics object import javax.swing.*;// access to.
1 Graphical objects We will draw graphics in Java using 3 kinds of objects: DrawingPanel : A window on the screen. Not part of Java; provided by the authors.
Graphics. Graphics Features in Java Topics to be covered Topics to be covered Graphics Basics Graphics Basics Coordinate System Coordinate System Graphics,
Agenda For Feb Discussion (Assignments & Rubric) 2. PowerPoint Presentation (Drawing Basic Shapes). 4.Read Unit 3 carefully (pages ) then.
Applets CS 3331 Sections 3.3 & 4.7 of [Jia03].
Line Graphics Summary 1.drawLine(xStart, yStart, xEnd, yEnd); 2.drawRect(x, y, width, height); 3.drawRoundRect(x, y, width, height, cornerWidth, cornerHeight);
Copyright 2010 by Pearson Education Building Java Programs Graphics reading: Supplement 3G.
Chapter 15Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 15 l Basic Figures l Colors l Fonts and Other Text Details.
Chapter 7 Graphics. © Daly and Wrigley Objectives Use Graphic Components: ▫ Strings ▫ Lines ▫ Rectangles ▫ Ovals ▫ Arcs Change the color and font of elements.
Graphics & Java 2D Drawing Two Dimensional Shapes Controlling Fonts Controlling Colors.
Chapter 2: Color and Applets Coming up: Introduction to Graphics.
Graphics & Applets CSC 1051 – Data Structures and Algorithms I
Graphic Basics in C ATS 315. The Graphics Window Will look something like this.
1 Building Java Programs Supplement 3G: Graphics These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may not be rehosted, sold,
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
(c)2006 E.S.Boese All Rights Reserved.1 Drawing Shapes and Text Chapter 2 – Lecture Slides.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Agenda March 8 1.PowerPoint Presentation on Variables. For download:
10/4: the for loop & the switch structure Primitive data types –why we mention them Return to counter-controlled repetition.
1 Introduction to Graphics b The last one or two sections of each chapter of the textbook focus on graphical issues b Most computer programs have graphical.
Building Java Programs Graphics Reading: Supplement 3G.
Introduction to Graphics. Graphical objects To draw pictures, we will use three classes of objects: –DrawingPanel : A window on the screen. –Graphics.
IT11 Agenda for Feb Golden Rule Reminder. 2. PowerPoint demonstration on the structure of Java Applet programs. Source Files HTML Files Class Files.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
CSC1401 Drawing in Java - 1. Goals Understand at a conceptual and practical level How to use the Turtle class to draw on a picture How to use the java.awt.Graphics.
Agenda For Feb PowerPoint Presentation on Java Methods. 3. Finish Happy Face Assignment (Due by the.
Copyright 2008 by Pearson Education Building Java Programs Graphics reading: Supplement 3G videos: Ch. 3G #1-2.
K GLE 20: Draw circles, squares, rectangles, and triangles.
CS 112 Introduction to Programming Java Graphics Yang (Richard) Yang Computer Science Department Yale University 208A Watson, Phone:
Creating an Object that can draw itself The paint method can ‘draw’ because it is passed a graphics environment as a parameter. If a class method is passed.
CompSci 4 Java 4 Apr 14, 2009 Prof. Susan Rodger.
Java Applets Getting Started. Import Files In order to run the applet properly, we have to import some files into our class. These files are: –import.
Building Java Programs
CSC 1051 – Data Structures and Algorithms I
Building Java Programs
Building Java Programs
Building Java Programs
Basic Graphics Drawing Shapes 1.
4.14 GUI and Graphics Case Study: Creating Simple Drawings (Cont.)
Building Java Programs
SSEA Computer Science: Track A
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Graphics Reading: Supplement 3G
APPLET PROGRAMMING.
Presentation transcript:

Agenda For Feb Finish up Unit 3 Exercises on page Unit 4 Exercises on page 33. Question #2 3. Create a Happy Face Java Applet (due next class). Criteria:  Use lines for the hair (at least 5 lines)  Use ovals for the eyes (fill the ovals with a color you create from scratch).  The nose must be a polygon.  Use at least one arc for the mouth.  Your Happy Face must use at least 3 different colors. 1. PowerPoint Presentation on Colors and Polygons

Using Colors There are two ways you can set the current drawing color. You can use pre-defined Java colors or you can define your own color from scratch. This is how you can set the current drawing using the pre-defined Java color red. screen.setColor (Color.red); You can replace the word red with any other Java pre- defined color.

Creating Your Own Color You can also set the current drawing color using a color you created from scratch. This is how you can create and set your own drawing color from scratch: Color myColor;// goes above the init method myColor = new Color (100, 60, 255); // goes inside the init method screen.setColor (myColor); // goes inside the paint method The following is a list of the available pre-defined Java colors (found on page 27): red, blue, cyan, gray, darkGray, lightGray, green, magenta, orange, pink, white, yellow

These three parameters can be any integer between and including 0 to 255. The 255’s in the images above mean I want a particular color to be turned on full blast and the zeros mean I don’t want to add any of that particular color. What color would the RGB combination (255, 0, 255) make? RGB Colors (255,0,0)(0,0,255)(0,255,0)(0,255,255)

Drawing Polygons So far we’ve seen that Java provides us with pre-defined colors (red, green, etc) and shapes (circles, rectangles, etc). However, if the need arises we are able to make up our own color up from scratch. What happens when we need to create a shape that isn’t like any of the ones Java provides? You guessed it! We create our own shape from scratch. It takes more work because we have to define the shape ourselves, but that’s the price you pay for being able to customizing your program so that it may better suite the needs of your users.

Drawing Your Own Shapes Drawing your own shape requires four steps. 1. Declare a polygon variable. 3. Define the vertices of your new polygon. 4. Draw your polygon. 1. In your variable section declare a Polygon variable: public void init () { Polygon mypoly; } 2. Initialize your polygon variable.

Initializing Your Polygon 2. In the init method, initialize your variable. The textbook initializes this variable in the paint method (page 29). This is not a good idea because your applet program executes the paint method many times and there is no point in initializing the same variable over and over again. Variables only need to be initialized once. This is how you initialize the polygon variable within the init method. mypoly = new Polygon();

Adding Points To Your Polygon 3.Use the addPoint method to define all the point of your polygon (do this inside your init method). NOTE: The last point will automatically connect itself to the first point you defined. Your init method should now look like this: public void init() { myPoly = new Polygon();// step 2 mypoly.addPoint (10, 10); mypoly.addPoint (110, 10); mypoly.addPoint (60, 100); }

4.Now finally you can draw your polygon using the method fillPolygon or drawPolygon. public void paint (Graphics screen) { screen.fillPolygon (myPoly); } Drawing Your Polygon

The Whole Program import java.awt.*; import java.applet.*; public class HelloWorld extends Applet { public void init() { myPoly = new Polygon(); public void paint(Graphics screen) { screen.fillPolygon (myPoly); } } mypoly.addPoint (10, 10); mypoly.addPoint (110, 10); mypoly.addPoint (60, 100); Polygon myPoly; }

mypoly.addPoint (10, 10); mypoly.addPoint (110, 10); mypoly.addPoint (60, 100); screen.drawPolygon (myPoly2); screen.fillPolygon (myPoly);