Graphics.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Chapter 2—Programming by Example The Art and Science of An Introduction to Computer Science ERIC S. ROBERTS Java Programming by Example C H A P T E R 2.
Made with love, by Zachary Langley Applets The Graphics Presentation.
Laboratory Study II October, Java Programming Assignment  Write a program to calculate and output the distance traveled by a car on a tank of.
Graphics You draw on a Graphics object The Graphics object cannot directly be created by your code, instead one is generated when the method paintComponent.
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.
LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class.
Chapter 2 Programming by Example. A Holistic Perspective Three sections separated by blank lines. Program comment File: FileName.java
ObjectDraw and Objects Early Chris Nevison Barbara Wells.
Programming What is a program? –A set of instructions –Understood by a computer.
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
Chapter 9—Object-oriented Graphics
CSE 219 Computer Science III Images. HW1 Has been posted on Blackboard Making a Game of Life with limited options.
Graphical Structures Eric Roberts CS 106A January 29, 2010.
Graphics Concepts CS 2302, Fall /3/20142 Drawing Paths.
Lecture 15: Intro to Graphics Yoni Fridman 7/25/01 7/25/01.
Introduction to Java Simple Graphics. Objects and Methods Recall that a method is an action which can be performed by an object. –The action takes place.
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
Introduction to Graphics. Graphical objects To draw pictures, we will use three classes of objects: –DrawingPanel : A window on the screen. –Graphics.
Graphical Structures Eric Roberts CS 106A January 27, 2016.
Simple Java Eric Roberts CS 106A January 11, 2016.
Interactive Graphics Eric Roberts CS 106A January 25, 2016.
Control Statements Eric Roberts CS 106A January 15, 2010.
Object Oriented Programming Lecture 3: Things OO.
Yingcai Xiao Programming and Debugging in Unity Yingcai Xiao.
Five-Minute Review 1.What steps do we distinguish in solving a problem by computer? 2.What are essential properties of an algorithm? 3.What is a definition.
Five-Minute Review 1.What are enumerated types? How can we represent enumerations in Java? 2.What is character arithmetic? 3.What is a string, conceptually?
Five-Minute Review What steps do we distinguish in solving a problem by computer? What are essential properties of an algorithm? What is a definition of.
Five-Minute Review What are enumerated types? How can we represent enumerations in Java? What is character arithmetic? What is a string, conceptually?
Jerry Cain and Eric Roberts
Programming and Debugging
Strings and Graphics Jerry Cain CS 106J April 12, 2017.
Review.
Building Java Programs
Animation & Games Module
Building Java Programs
Building Java Programs
CS106A, Stanford University
Beyond Console Programs
Lesson One: The Beginning Chapter 1: Pixels Learning Processing Daniel Shiffman Presentation by Donald W. Smith Graphics from
Five-Minute Review What are enumerated types? How can we represent enumerations in Java? What is character arithmetic? What is a string, conceptually?
reading: Art & Science of Java,
CS 106A, Lecture 15 Events and Memory
CS 106A, Lecture 24 Interactors and NameSurfer
reading: Art & Science of Java, Ch. 9
CS 106A, Lecture 12 More Graphics
CS106A, Stanford University
CS 106A, Lecture 14 Events and Instance Variables
CS 106A, Lecture 22 More Classes
CS106A, Stanford University
4.14 GUI and Graphics Case Study: Creating Simple Drawings (Cont.)
Chapter 9—Object-oriented Graphics
Chapter 2—Programming by Example
Building Java Programs
SSEA Computer Science: Track A
CS106A, Stanford University
CS106A, Stanford University
Programming and Debugging
Interactive Graphics Jerry Cain and Ryan Eberhardt CS 106AJ
CSE 142 Lecture Notes Graphics with DrawingPanel Chapter 3
Building Java Programs
Building Java Programs
Building Java Programs
Chapter 2—Programming by Example
Building Java Programs
Graphics Reading: Supplement 3G
Introduction to Computer Science and Object-Oriented Programming
Presentation transcript:

Graphics

Programming takes practice.

Some common issues.

Reusing Variables You only need to tell Java the type of a variable once.

Where semicolons; belong Semicolons do not go after for, while, if, else. ; and { do NOT go together

Beyond Console Programs

GRect GRect is a variable that stores a rectangle. As an example, the following run method displays a rectangle public void run() { GRect rect = new GRect(200, 200); rect.setFilled(true); rect.setColor(Color.BLUE); add(rect, 50, 50); } LargestOval

GRect GRect is a variable that stores a rectangle. As an example, the following run method displays a rectangle public void run() { GRect rect = new GRect(200, 200); rect.setFilled(true); rect.setColor(Color.BLUE); add(rect, 50, 50); } LargestOval Coordinates for a rectangle are the top left corner. 50 50

Graphics Coordinates 0,0 40,20 120,40 getHeight(); 40,120 getWidth();

Karel’s Grandpa

Karel’s Grandpa

Karel’s Grandpa rect.getWidth() / 2 getWidth() / 2

Karel’s Grandpa rect.getHeight() / 2 getHeight() / 2

Constants

Karel’s Grandpa

GLabel hello, world A variable that represents text. public class HelloProgram extends GraphicsProgram { public void run() { GLabel label = new GLabel(”hello, world”, 100, 75); label.setFont(“SansSerif-36”); label.setColor(Color.RED); add(label); } HelloProgram HelloProgram hello, world

GLabel hello, world A variable that represents text. public class HelloProgram extends GraphicsProgram { public void run() { GLabel label = new GLabel(”hello, world”, 100, 75); label.setFont(“SansSerif-36”); label.setColor(Color.RED); add(label); } HelloProgram HelloProgram 75 hello, world 100

Karel’s Grandpa

GOval The GOval class represents an elliptical shape defined by the boundaries of its enclosing rectangle. As an example, the following run method creates the largest oval that fits within the canvas: public void run() { GOval oval = new GOval(getWidth(), getHeight()); oval.setFilled(true); oval.setColor(Color.GREEN); add(oval, 0, 0); } LargestOval

Karel’s Grandpa

Karel’s Grandpa

Graphics Methods Adds the object to the canvas at the front of the stack Moves the object to (x, y) and then adds it to the canvas Removes the object from the canvas Removes all objects from the canvas Returns the frontmost object at (x, y), or null if none Returns the width in pixels of the entire canvas Returns the height in pixels of the entire canvas Sets the background color of the canvas to c. add(object) add(object, x, y) remove(object) removeAll() getElementAt(x, y) getWidth() getHeight() setBackground(c) Pauses the program for the specified time in milliseconds Suspends the program until the user clicks the mouse pause(milliseconds) waitForClick()

Graphics Methods Adds the object to the canvas at the front of the stack Moves the object to (x, y) and then adds it to the canvas Removes the object from the canvas Removes all objects from the canvas Returns the frontmost object at (x, y), or null if none Returns the width in pixels of the entire canvas Returns the height in pixels of the entire canvas Sets the background color of the canvas to c. add(object) add(object, x, y) remove(object) removeAll() getElementAt(x, y) getWidth() getHeight() setBackground(c) Pauses the program for the specified time in milliseconds Suspends the program until the user clicks the mouse pause(milliseconds) waitForClick()

Reference Sheet

GLine The GLine class represents a line defined by a start point and an end point. As an example, the following run method creates a diagonal line across the canvas: public void run() { GLine line = new GLine(0,0, getWidth(), getHeight()); add(line); }

Karel’s Grandpa