Chapter 5 Sample Development DrawShapes. Sample Development: Drawing Shapes Write an application that simulates a screensaver by drawing various geometric.

Slides:



Advertisements
Similar presentations
Chapter 14 Graph class design Bjarne Stroustrup
Advertisements

© Calvin College, Being abstract is something profoundly different from being vague... The purpose of abstraction is not to be vague, but to create.
Chapter 5 Programming Graphics. Chapter Goals To be able to write applications with simple graphical user interfaces To display graphical shapes such.
Chapter 14 Graph class design John Keyser’s Modifications of Slides by Bjarne Stroustrup
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 5 Selection Statements.
CompSci 427jd.1 Javadoc. CompSci 427jd.2 Javadoc The Plan  What is Javadoc?  Writing Javadoc comments  Using the Javadoc tool  Practice.
Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
GUI and Swing, part 2 The illustrated edition. Scroll bars As we have previously seen, a JTextArea has a fixed size, but the amount of text that can be.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Object-Oriented.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
© The McGraw-Hill Companies, 2006 Chapter 9 Software quality.
ObjectDraw and Objects Early Chris Nevison Barbara Wells.
Subdue Graph Visualizer by Gayathri Sampath, M.S. (CSE) University of Texas at Arlington.
DrawingPaint What is DrawingPaint ? DrawingPaint operations. What are benefits of DrawingPaint ? Jason Hoang June 2, 2005.
Chapter 3 - Introduction to Java Applets Outline 3.1Introduction 3.2Thinking About Objects 3.4A Simple Java Applet: Drawing a String 3.5Two More Simple.
1 Object-Oriented Design. 2 Objectives F To become familiar with the process of program development. F To the relationship types: association, aggregation,
A Simple Applet.
Chapter 10 Classes Continued
Chapter 5 Graphics. Topics Applets Classes used for graphics –Graphics –Point –Dimension –Color.
Chapter Chapter 5 Selection Statements. Objectives Understand selection control statement –if statements –switch statements Write boolean expressions.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 5 Selection Statements.
PROCESSING Animation. Objectives Be able to create Processing animations Be able to create interactive Processing programs.
CS 2511 Fall UML Diagram Types  2 Main Types Structure Diagrams ○ Class Diagrams ○ Component Diagrams ○ Object Diagrams Behavior Diagrams ○
Copyright 2008 by Pearson Education Building Java Programs Chapter 9 Lecture 9-4: Interfaces reading: self-check: exercises: #11.
Using Jeroo To Teach Object-Oriented Concepts By Christian Digout.
1 Interface Types & Polymorphism & introduction to graphics programming in Java.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented.
Lab 5: drawing and output User Interface Lab: GUI Lab Sep. 25 th, 2013.
Introduction to Programming with Java. Overview What are the tools we are using – What is Java? This is the language that you use to write your program.
Chapter 11 Inheritance and Composition. Chapter Objectives Learn about inheritance Learn about subclasses and superclasses Explore how to override the.
1 Java Inheritance. 2 Inheritance On the surface, inheritance is a code re-use issue. –we can extend code that is already written in a manageable manner.
1. Chapter 12 Inserting Shapes and WordArt 3 Inserting Shapes, WordArt, and More Create shapes, text boxes, and WordArt to add visual appeal to a Word.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Hello, little turtles. Hello, little turtles! There are many modules in Python that provide very powerful feature that we can use in our own program.
1. Understanding the Problem 2. Brainstorming 3. Drawing an I/O (Input/Output) diagram 4. 5-step Process (or: Small iPods Make Copying Tough) Developing.
Static Methods. 2 Objectives Look at how to build static (class) methods Study use of methods calling, parameters, returning values Contrast reference.
Polymorphism, Abstraction and Virtual Functions. In this slide, we introduce virtual functions and two complex and powerful uses for derived classes that.
1. Chapter 15 Creating Charts 3 Charting Data in Word A chart or graph presents data visually. A chart depicts numeric data in a graphical format. If.
Inheritance Chapter 10 Programs built from objects/instances of classes An O.O. approach – build on earlier work. Use classes in library and ones you have.
CSCI 1100/1202 April 1-3, Program Development The creation of software involves four basic activities: –establishing the requirements –creating.
Chapter 13 ATM Case Study Part 2: Implementing an Object-Oriented Design Java How to Program, 8/e (C) 2010 Pearson Education, Inc. All rights reserved.
Graphics Concepts CS 2302, Fall /17/20142 Drawing in Android.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 11 Object-Oriented.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Object-Oriented Design.
Creating a Java Application and Applet
Chapter 3: Introducing the UML
CompSci 427jd.1 Javadoc. CompSci 427jd.2 Javadoc The Plan  What is Javadoc?  Writing Javadoc comments  Using the Javadoc tool  Practice.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 5 Selection Statements Animated Version.
1 Interfaces and Abstract Classes The ability to define the behavior of an object without specifying that behavior is to be implemented Interface class.
Interfaces, Abstract Classes, and Polymorphism. What Is an Interface? An interface is the set of public methods in a class Java provides the syntax for.
CMSC 2021 Software Development. CMSC 2022 Software Development Life Cycle Five phases: –Analysis –Design –Implementation –Testing –Maintenance.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
Abstract Classes. Recall We have the ability to create hierarchies of classes. Good design practice suggests that we move common methods as high as possible.
Basic Graphics 03/03/16 & 03/07/16 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
Notices Assn 2 is due tomorrow, 7pm. Moodle quiz next week – written in the lab as before. Everything up to and including today’s lecture: Big Topics are.
 The word static is used to declare either a ________ variable or method.  Why do we use statics?  What is Polymorphism? class In general, we use a.
10/20/2005week71 Graphics, mouse and mouse motion events, KeyEvent Agenda Classes in AWT for graphics Example java programs –Graphics –Mouse events –Mouse.
Parametric Equations Until now, we’ve been using x and y as variables. With parametric equations, they now become FUNCTIONS of a variable t.
Sections Inheritance and Abstract Classes
Chapter 3 Syntax, Errors, and Debugging
Chapter 11 Object-Oriented Design
Basic Graphics Chapter 5 3/19/15 Thursday Section Only
JavaDoc CECS277 Mimi Opkins.
Intro to OOP with Java, C. Thomas Wu Selection Statements
Java Programming: Guided Learning with Early Objects
Inheritance, Polymorphism, and Interfaces. Oh My
Chapter 5 Selection Statements
Chapter 6 Selection Statements
Presentation transcript:

Chapter 5 Sample Development DrawShapes

Sample Development: Drawing Shapes Write an application that simulates a screensaver by drawing various geometric shapes in different colors. The user has an option of choosing a type (ellipse or rectangle), color, and movement (stationary, smooth, or random).

Predefined Classes Until now, we've used predefined classes by calling their methods.

Predefined Classes, cont. –There is another kind of predefined class requires us to define helper classes for it to use. –Since the given class is already written, the helper classes need to have methods that match those the given class calls

Functionality Specification How do we know what the helper class needs to do? –Writer of the class has provided documentation specifying the necessary functionality. –There could be an abstract class with the desired methods and extend that to make DrawableShape. –There could be an interface with the desired methods.

DrawingBoard Supports the drawing of DrawableShape objects –fixed position –smooth trajectory –random positions

DrawingBoard DrawingBoard methods take DrawableShape objects as parameters. DrawingBoard expects to be able to draw the following set of methods for a DrawableShape: –public void draw (java.awt.Graphics) –public java.awt.Point getCenterPoint() –public java.awt.Dimension getDimension () –public void setCenterPoint (java.awt.Point)

Drawing Shapes Program flow: 1.Get the shape the user wants to draw. 2.Get the color of the chosen shape. 3.Get the type of movement the user wants to use. 4.Start the drawing.

Drawing Shapes Program implementation: 1.Start with a program skeleton. Explore the DrawingBoard class. 2.Define an experimental DrawableShape class that draws a dummy shape. 3.Add code to allow the user to select a shape. Extend the DrawableShape and other classes as necessary. 4.Add code to allow the user to specify the color. Extend the DrawableShape and other classes as necessary. 5.Add code to allow the user to specify the motion type. Extend the DrawableShape and other classes as necessary. 6.Finalize the code by tying up loose ends.

Class Diagram for Ch5DrawShape

Drawing Shapes Step 1 Development: Program Skeleton –Use the DrawingBoard class to establish a launch pad for the development. –Keep the code simple at this stage: Make the DrawingBoard visible on the screen.

Drawing Shapes Step 2 Development: Draw a Shape Define the DrawableShape class with the specified set of methods: –public void draw (java.awt.Graphics) –public java.awt.Point getCenterPoint() –public java.awt.Dimension getDimension () –public void setCenterPoint (java.awt.Point)

Minimal DrawableShape Create a minimal class for DrawableShape Single instance variable is Point representing center of shape Shape drawn will be a circle of radius 100

Drawing Shapes Step 3 Development: Allow the User to Select a Shape –Use JOptionPane to allow the user to input a choice numerically, and to establish the height and width of the shape. –Modify the DrawableShape class so it can draw three different geometric shapes.

Drawing Shapes Step 4 Development: Allow the User to Select a Color –Adopt the same input style for accepting the shape in Step 3. –Add a method named inputColor to the Ch5DrawShape class.

Drawing Shapes Step 5 Development: Allow the user to select a motion type. –Adopt the same design as used in Steps 3 and 4 for the motion selection.

Drawing Shapes No changes are required for the DrawableShape class, as the DrawingBoard class is the one responsible for shape movement.

Drawing Shapes Step 6 Development: Finalize –Perform a critical program review, looking for unfinished methods, inconsistency or error in the methods, missing comments, etc. –Make extensions to the program if desired.