© A+ Computer Science - www.apluscompsci.com. Chicken yeller = new Chicken();

Slides:



Advertisements
Similar presentations
Rectangles moving and responding to the mouse. We want a window with a pile of rectangles in it When we click a rectangle it changes from filled to unfilled.
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.
Web Design & Development Lecture 19. Java Graphics 2.
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.
Graphics Chapter 16.  If you want to draw shapes such as a bar chart, a clock, or a stop sign, how do you do it?
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.
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Multithreading : animation. slide 5.2 Animation Animation shows different objects moving or changing as time progresses. Thread programming is useful.
Java Graphics Section 1 - Multi-File Graphics Programs Section 2 - The Coordinate System and Graphics Context g Section 3 - The Java Drawing and Painting.
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.
Slides prepared by Rose Williams, Binghamton University Chapter 19 Swing II.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 16 : Swing VI Graphics King Fahd University of Petroleum & Minerals College of Computer.
Copyright 2008 by Pearson Education Building Java Programs Graphics reading: Supplement 3G videos: Ch. 3G #1-2.
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
Unit 11 Object-oriented programming: Graphical user interface Jin Sa.
Java Concepts Chapter 2 – Graphical Applications Mr. Smith AP Computer Science A.
Web Design & Development Lecture 18. Java Graphics.
Object-Oriented Programming in Java. Object-Oriented Programming Objects are the basic building blocks in an O-O program. – A program consists of one.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
Learn about the types of Graphics that are available Develop a basic Graphics applet Develop a basic Graphics application Review the Java API and use.
© A+ Computer Science - Inheritance © A+ Computer Science - Lab 20.
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
GCOC – A.P. Computer Science A. College Board Topics – A.P. Computer Science A Program Design - Read and understand a problem's description, purpose,
© A+ Computer Science - public Triangle() { setSides(0,0,0); } Constructors are similar to methods. Constructors set the properties.
J McQuillan SE204: 2004/2005: Lecture 4slide 1 The Graphics Class Used when we need to draw to the screen Two graphics classes –Graphics –Graphics2D.
1 Block1 – unit 2 (The Case study in Budd 5-6).  create a small application that uses the Abstract Windowing Toolkit (AWT)  Swing packages to simulate.
-Sai Phalgun Tatavarthy. Outline What is a “Graphing Calculator”? Graphics, Graphics2D classes Methods of Graphics object Custom Painting The paintComponent()
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
1 Even even more on being classy Aaron Bloomfield CS 101-E Chapter 4+
Chapter 5: Ball Worlds Features 2 classes, constant data fields, constructors, extension through inheritance, graphics.
Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 21.1 Test-Driving the Painter Application.
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
BallWorld.java A structured walkthrough. Key Features: 2 classes are created Execution is done through the procedure called “main” which are decleared.
Classes Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Clicker quick questions 10/17/13 CSE 1102 Fall 2013.
Review_6 AWT, Swing, ActionListener, and Graphics.
Using classes. One step instantiation, Composition I JFrame myWindow = new JFrame( ); Two step Instantiation, Composition II private JFrame myWindow;
Lecture 3.1 Using Graphics with JFrame. © 2006 Pearson Addison-Wesley. All rights reserved javax.swing.JFrame - int x - int y - int width - int.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 27.1 Test-Driving the Drawing Shapes Application.
Objects and Classes Start on Slide 30 for day 2 Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Much of.
© A+ Computer Science - In Java, any variable that refers to an Object is a reference variable. The variable stores the memory.
Graphical User Interface (GUI) Two-Dimensional Graphical Shapes.
College Board Topics – A.P. Computer Science A Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Java With NetBeans First Project. Java Are language for this semester is Java The Development Environment is Netbeans.
COP 2220 Computer Science I Topics –Breaking Problems Down –Functions –User-defined Functions –Calling Functions –Variable Scope Lecture 4.
GUI Tutorial Day 4. More GUI action  adding a Mouse Listener  SimpleDots  Simple mouse listener  Draw an oval where the mouse is clicked  Box example.
CSC 205 Programming II Lecture 4 Abstract Class. The abstract keyword indicate that a class is not instantiable Defining a type which will be specialized.
Basic Graphics 03/03/16 & 03/07/16 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
Introducing, the JFrame Gives us a work area beside System.out.println.
CPCS 391 Computer Graphics Lab One. Computer Graphics Using Java What is Computer Graphics: Computer graphics are graphics created using computers and,
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Import javax.swing.JOptionPane; public class Rectangle { public static void main(String[] args) { double width, length, area, perimeter; String lengthStr,
CS202 Java Object Oriented Programming GUI Programming – Color and Drawing Methods Chengyu Sun California State University, Los Angeles.
Basic Graphics Chapter 5 3/19/15 Thursday Section Only
GUI AND GRAPHICS.
4.14 GUI and Graphics Case Study: Creating Simple Drawings (Cont.)
Lesson A4 – Object Behavior
Using PARAMETERS In Java.
A+ Computer Science METHODS.
© A+ Computer Science - OOP © A+ Computer Science -
© A+ Computer Science - Classes And Objects © A+ Computer Science -
© A+ Computer Science - OOP Pieces © A+ Computer Science -
A+ Computer Science METHODS.
A+ Computer Science PARAMETERS
Presentation transcript:

© A+ Computer Science -

Chicken yeller = new Chicken();

© A+ Computer Science - Chicken yeller = new Chicken(); yeller yeller is a reference variable that refers to a Chicken object. 0x234 Chicken

© A+ Computer Science -

A method is a storage location for related program statements. When called, a method usually performs a specific task. System.out.println( )

© A+ Computer Science -

public void speak() { out.println("cluck-cluck"); } OUTPUT cluck-cluck

© A+ Computer Science - return typenameparams code access public void speak( ) { System.out.println("cluck-cluck"); }

© A+ Computer Science - All members with public access can be accessed or modified inside and outside of the class where they are defined.

© A+ Computer Science - public class Chicken { public void speak() { out.println("cluck-cluck"); } public static void main(String[] args) { Chicken red = new Chicken(); red.speak(); } OUTPUT cluck-cluck

© A+ Computer Science -

public class Turkey { public void speak() { out.println("gobble-gobble"); } public void sayName() { out.println("big bird"); } //code in the main of another class Turkey bird = new Turkey(); bird.speak(); bird.sayName(); bird.speak(); bird.sayName(); bird.speak(); OUTPUT gobble-gobble big bird gobble-gobble big bird gobble-gobble

© A+ Computer Science - public class Turkey { public void speak() { out.println("gobble-gobble"); } public void sayName() { out.println("big bird"); speak(); } //code in the main of another class Turkey bird = new Turkey(); bird.speak(); bird.sayName(); bird.speak(); bird.sayName(); bird.speak(); OUTPUT gobble-gobble big bird gobble-gobble big bird gobble-gobble

© A+ Computer Science -

Constructors always have the same name as the class. GraphOne test = new GraphOne(); Monster rob = new Monster();

© A+ Computer Science - Scanner keyboard = new Scanner(System.in); reference variable object instantiation / constructor call

© A+ Computer Science - public class GraphicsRunner extends JFrame { private static final int WIDTH = 640; private static final int HEIGHT = 480; public GraphicsRunner() { setSize(WIDTH,HEIGHT); getContentPane().add( new Circles() ); setVisible(true); } public static void main( String args[] ) { GraphicsRunner run = new GraphicsRunner(); } constructor call the constructor

© A+ Computer Science - Canvas / JPanel Frame / JFrame The Frame is used to hold up / display a Canvas or Panel.

© A+ Computer Science - public class Circles extends Canvas { //constructors public void paint( Graphics window ) { window.setColor(Color.BLACK); window.drawString("Circles", 50, 50); window.setColor(Color.BLUE); window.drawOval(500,300,40,40); } //other methods } paint() is called automatically when you instantiate the class containing the paint method. When an event is triggered that requires a redraw, paint is called again. To call paint() without a Graphics parameter, you can use the repaint() method. paint

© A+ Computer Science -

Graphics frequently used methods NameUse setColor(x)sets the current drawing color to x drawString(s,x,y)draws String s at spot x,y drawOval(x,y,w,h)draws an unfilled oval at spot x,y that is w wide and h tall fillOval(x,y,w,h)draws a filled oval at spot x,y that is w wide and h tall import java.awt.Graphics; import java.awt.Color; import javax.swing.JFrame;

© A+ Computer Science - A parameter/argument is a channel used to pass information to a method. setColor() is a method of the Graphics class the receives a Color. void setColor(Color theColor) window.setColor( Color.RED ); method call with parameter

© A+ Computer Science - void fillRect (int x, int y, int width, int height) window.fillRect( 10, 50, 30, 70 ); method call with parameters

© A+ Computer Science - void fillRect(int x, int y, int width, int height) window.fillRect( 10, 50, 30, 70 ); The call to fillRect would draw a rectangle at position 10,50 with a width of 30 and a height of 70.

© A+ Computer Science - Graphics frequently used methods NameUse drawLine(a,b,c,d)draws a line starting at point a,b and going to point c,d drawRect(x,y,w,h)draws an unfilled rectangle at spot x,y that is w wide and h tall fillRect(x,y,w,h)draws a filled rectangle at spot x,y that is w wide and h tall import java.awt.Graphics; import java.awt.Color; import javax.swing.JFrame;

© A+ Computer Science - 0,0 639,479 window.fillRect( 10, 50, 30, 70 ); X goes across Y goes down

© A+ Computer Science - 0,0 window.fillOval( 100, 100, 50, 50 ); X goes across Y goes down X=100 y=100 width=50 height=50

© A+ Computer Science - public void paint( Graphics window ) { window.setColor(Color.BLUE); window.fillRect(150, 300, 100, 20); window.setColor(Color.GRAY); window.drawRect(200,80,50,50); }

© A+ Computer Science -

Graphics frequently used methods NameUse drawArc(x,y,w,h,startAngle,arcAngle)draws an arc at spot x,y that is w wide and h tall fillArc(x,y,w,h,startAngle,arcAngle)draws a filled arc at spot x,y that is w wide and h tall startAngle specifies the start of the arc arcAngle specifies the length of the arc import java.awt.Graphics; import java.awt.Color; import javax.swing.JFrame;

© A+ Computer Science -