A Sample Program A rudimentary solar simulation: We want a click of the mouse in the window to make the ‘sun’ rise.

Slides:



Advertisements
Similar presentations
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 2 Getting Started with Java.
Advertisements

LOGGING ON AND SHUTTING DOWN How to do both successfully at school.
An Introduction to Computers For Middle School Students Mrs. G-Smith (University of Tennessee)
In put Devices and Media In order for a computer to do anything it must be told what to do.
1What is the Stage. 2How do you open a panel in Flash
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.
Using PeopleSoft’s User Productivity Kit (UPK)
ObjectDraw and Objects Early Chris Nevison Barbara Wells.
Programming What is a program? –A set of instructions –Understood by a computer.
Recall: Accessing Location Info private Location firstPoint; public void onMousePress( Location pressPt ) { new Text("Pressed", pressPt, canvas ); firstPoint.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
DIGITAL GRAPHICS & ANIMATION
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
CH1 – A 1 st Program Using C#. Program Set of instructions which tell a computer what to do. Machine Language Basic language computers use to control.
Slide 1 Chapter 2 Visual Basic Interface. Slide 2 Chapter 2 Windows GUI  A GUI is a graphical user interface.  The interface is what appears on the.
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
Chapter 2 Classes and Methods I Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
A First Program Using C#
Visual Basic Chapter 1 Mr. Wangler.
Microsoft® Small Basic
CS413: Java Programming language Applications Applets
Overview of our Approach Program Structure –Data, variables, and parameters –Basic control structures (conditionals, loops and Threads) –Class definitions.
© 2006 Lawrenceville Press Slide 1 Chapter 3 Visual Basic Interface.
© 2011 Delmar, Cengage Learning Chapter 9 Introduction to ActionScript 3.0.
CSC 142 B 1 CSC 142 Java objects: a first view [Reading: chapters 1 & 2]
Display Ratios The Student Union displays have ratios of 16:9 Most computer displays have ratios of 4:3 This often distorts graphics when they are changed.
Classes CS 21a: Introduction to Computing I First Semester,
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.
Exploring Computer Science 2/9/15 2/9Moving Scratch 2/10Moving Scratch worksheet 2/11 Scratch Baseball Game 2/12Scratch Alphabet Learning Game 2/13Game.
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.
Concurrent Programming and Threads Threads Blocking a User Interface.
Lec 16 Adding Mouse and KeyEvent handlers to an Applet Class.
Loops & Graphics IP 10 Mr. Mellesmoen Recall Earlier we wrote a program listing numbers from 1 – 24 i=1 start: TextWindow.WriteLine(i) i=i+1 If.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
1 CSE1340 Class 4. 2 Objectives Write a simple computer program in Java Use Swing components to build the GUI Use proper naming conventions for classes.
Some Graphics CS303E: Elements of Computers and Programming.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 21.1 Test-Driving the Painter Application.
CSC 230 (Blum)1 Visual Basic 2005 Hello World Fall 2005 T. Blum.
Multiplication Level 3 (facts 0 - 9) Read These Instructions:  Try to get the answer before the computer puts it on the screen.  Do not click on your.
How to use the PRS Clickers with PowerPoint Created by: Lindsay Proctor.
CSC 142 B 1 CSC 142 Java objects: a first view [Reading: chapters 1 & 2]
Chapter 2 Objects and Mutator Methods. A Sample Program A rudimentary solar simulation: We want a click of the mouse in the window to make the ‘sun’ rise.
A Class of Our Own We’ve used many classes: –Location –FilledRect –Color –Text –And More! –But what if we want to make our own class?
Making Billboards By Deborah Nelson Duke University, Under the direction of Professor Susan Rodger, July 14, 2008.
Conditional Statements Consider: if the mouse location is contained in the rectangle, display message “success” Some programming constructs can choose.
Java Decision Making and booleans (Java: An Eventful Approach, Ch 4), Slides Credit: Bruce, Danyluk and Murtagh CS 120 Lecture October 2012.
This week’s lessons are designed to reinforce the common core standards of: Click the mouse for the next screen.
Class 2 Remote Instruction Review of Working with Buttons EDU 556 Programming for Instruction Dr. Steve Broskoske This is an audio PowerCast. Make sure.
The Cortex-M3 Embedded Systems: Programming With the Kitronix K350QVG-V1-F LCD Refer to “Kitronix Ltd. PRODUCT SPECIFICATION” “SSD2119 Advance Information”
Graphics Tools and Parameters Chris Nevison Barbara Wells.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Events Programming with Alice and Java First Edition by John Lewis.
Java Working with Numbers (Java: An Eventful Approach, Ch 3), Slides Credit: Bruce, Danyluk and Murtagh CS 120 Lecture October 2012.
Transparency 7 Click the mouse button or press the Space Bar to display the answers.
Continuous. Flow of Control Programs can broadly be classified as being –Procedural Programs are executed once in the order specified by the code varied.
CSC 230 (Blum)1 Visual Basic 2005 Hello World Fall 2005 T. Blum.
Multiplication Level 1 (Facts 0-2) Read These Instructions:  Try to get the answer before the computer puts it on the screen.  Do not click on your.
Multiplication Level 2 (facts 0-2, 5, 9) Read These Instructions:  Try to get the answer before the computer puts it on the screen.  Do not click on.
1.1: Objects and Classes msklug.weebly.com. Agenda: Attendance Let’s get started What is Java? Work Time.
If screen is locked press: Ctrl*Alt*Delete Login: Your Sharepoint Login & Password Go to: Sharepoint then Construction Administration Go to: Drawing Review.
Java Objects (Java: An Eventful Approach, Ch 2), Slides Credit: Bruce, Danyluk and Murtagh CSCI 120 Lecture October 2012.
Teaching Control Structures, using objectdraw Chris Nevison Barbara Wells.
Agenda For Feb PowerPoint Presentation on Java Methods. 3. Finish Happy Face Assignment (Due by the.
Input Devices. Input devices allow us to enter data into the computer system –Mouse –Keyboard –Graphics Tablet –TrackPad –Touch-sensitive screen - Scanner.
Multiplication Level Read These instructions:  Try to get the answer before the computer puts it on the screen.  Do not click on your mouse,
Java Classes (Java: An Eventful Approach, Ch. 6),
Implementing Classes Chapter 3.
Java objects: a first view
Classes CS 21a: Introduction to Computing I
Presentation transcript:

A Sample Program A rudimentary solar simulation: We want a click of the mouse in the window to make the ‘sun’ rise

Moving an Oval Mutator methods: change an object that’s been created move ( 0, -5 ); But how does the computer know what to move? Give the object a name!

Some Building Blocks private FilledOval sun; sun = new FilledOval( 50, 150, 100, 100, canvas ); sun.move( 0, -5 );

Giving Names Declare all instance variables private FilledOval sun; Appropriate Names –Start with letters –Case sensitive –Letters, digits, underscores –Not a word already in Java

Comments for Clarity In our line private FilledOval sun; //sun is the name sun is the name is a comment

Mutator Methods in Context We want to move the sun when the user clicks the mouse: public void onMouseClick( Location point){ sun.move( 0, -5 ); }

More Mutator Methods private Text instructions; //Display of instructions instructions = new Text (…); instructions.hide(); instructions.show();

public class RisingSun extends WindowController { private FilledOval sun;// Circle that represents the sun private Text instructions;//Display of instructions public void begin() { //Place the sun and brief instructions on screen sun = new FilledOval( 50, 150, 100, 100, canvas ); instructions = new Text("Please click the mouse ", 20, 20, canvas ); } //Move the sun up each click public void onMouseClick( Location point ) { sun.move( 0, -5 ); instructions.hide(); }

More Classes Classes so far: Line, FilledOval, Text Can also have nongraphical classes! –Color –Location

Colors private Color purple; purple = new Color (255, 0, 255); sun.setColor( Color.YELLOW ); //makes sun yellow instructions.setColor( purple ); //makes instr purple

Locations private Location initialPosition; initialPosition = new Location( 50, 150 ); sun.moveTo ( initialPosition );

Layering the Canvas Create two overlapping FilledOvals. Which one’s on top? –Answer: The most recently constructed How do we change the order? –Answer: Mutator Methods sendBackward() sendForward() sendToBack() sendToFront()

Using a Mouse Point Recall onMousePress( Location point ); –We can use the Location! Consider: public void onMousePress ( Location point ) { new Text ( "Pressed", point, canvas ); } Displays "Pressed" wherever the mouse is clicked

Using Multiple Points private Location firstPoint; public void onMousePress( Location pressPt ){ new Text("Pressed", pressPt, canvas ); firstPoint = pressPt; } public void onMouseRelease ( Location releasePt){ new Text("Released", releasePt, canvas ); new Line( firstPoint, releasePt, canvas ); }

Multiple Point Picture Can play connect the dots!

Review Graphical and nongraphical objects Names and mutator methods Layering the canvas