AplusBug dude = new AplusBug(); A+ Computer Science -

Similar documents
public static void main(string[] args) { GTest mywindow = new GTest(); // Title This program creates the following window and makes it visible:

Lecture 3: Java Graphics & Events

Java Applet Basics. Life cycle of an applet:

AP CS Unit 12: Drawing and Mouse Events

Lecture 7 A First Graphic Program And Data Structures & Drawing

Lecture 5: Java Graphics

Appendix F: Java Graphics

CPS109 Lab 7. Source: Big Java, Chapter 7 Preparation: read Chapter 7 and the lecture notes for this week.

Chapter 7 Applets. Answers

Control Statements: Part Pearson Education, Inc. All rights reserved.

Appendix F: Java Graphics

IT101. Graphical User Interface

Unit 7: Event driven programming

CS 201 Advanced Object-Oriented Programming Lab 1 - Improving Your Image Due: Feb. 3/4, 11:30 PM

Java Coordinate System

Lab & Assignment 1. Lecture 3: ArrayList & Standard Java Graphics. Random Number Generator. Read Lab & Assignment Before Lab Wednesday!

cs Java: lecture #5

Practice Midterm 1. Problem Points Score TOTAL 50

6.092 Introduction to Software Engineering in Java January (IAP) 2009

TWO-DIMENSIONAL FIGURES

Example: Building a Java GUI

Example: Building a Java GUI

Introduction to Computer Science I

@Override public void start(stage primarystage) throws Exception { Group root = new Group(); Scene scene = new Scene(root);

Calling and Returning From a Method. Control Flow

Dr. Hikmat A. M. AbdelJaber

COMP102: Test 1 Model Solutions

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

curl -sl sh

Course overview: Introduction to programming concepts

Lecture 3.1. Using Graphics with JFrame 9/16/11. javax.swing.jframe. - int x - int y - int width - int height - Color backcolor

Give one example where you might wish to use a three dimensional array

Java Programming Lecture 6

Using Graphics. Building Java Programs Supplement 3G

CSCI 053. Week 5 Java is like Alice not based on Joel Adams you may want to take notes. Rhys Price Jones. Introduction to Software Development

Graphics Applets. By Mr. Dave Clausen

+! Today. Lecture 3: ArrayList & Standard Java Graphics 1/26/14! n Reading. n Objectives. n Reminders. n Standard Java Graphics (on course webpage)

Chapter 5 Lab Methods

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

CSE 11 Midterm Fall 2008

Graphics Applets. By Mr. Dave Clausen

Practice Midterm 1 Answer Key

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 7, Name:

Here is a list of a few of the components located in the AWT and Swing packages:

9. APPLETS AND APPLICATIONS

More about GUIs GEEN163

CS 315 Software Design Homework 1 First Sip of Java Due: Sept. 10, 11:30 PM

MaSH Environment graphics

2IS45 Programming

Graphics -- To be discussed

SIMPLE APPLET PROGRAM


Sample Solution Assignment 5. Question R3.1

CSC System Development with Java Introduction to Java Applets Budditha Hettige

CSE115 Lab 4 Fall 2016

AP CS Unit 11: Graphics and Events

Programming: You will have 6 files all need to be located in the dir. named PA4:

CSC 160 LAB 8-1 DIGITAL PICTURE FRAME. 1. Introduction

Graphics and Painting

class Shape { // Color of the shape. (Recall that class Color // is defined in package java.awt. Assume // that this class has been imported.

Submit your solution to the Desire2Learn drop box. You may submit as many versions as you like the last one will be graded.

Chapter 14: Applets and More

8/23/2014. Chapter Topics. Introduction to Applets. Introduction to Applets. Introduction to Applets. Applet Limitations. Chapter 14: Applets and More

1 Short Answer (10 Points Each)

Name CS/120 Sample Exam #1 -- Riley. a) Every program has syntax, which refers to the form of the code, and, which refers to the meaning of the code.

OBJECT ORIENTED PROGRAMMING. Course 8 Loredana STANCIU Room B613

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

CS Problem Solving and Object-Oriented Programming

Graphical User Interfaces 2

Overview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008

Chapter 14: Applets and More

CS 11 java track: lecture 3

User interfaces and Swing

Prototyping with Methods

Using the API: Introductory Graphics Java Programming 1 Lesson 8

Object-oriented programming in Java (2)

CSE wi Final Exam 3/12/18 Sample Solution

Graphic User Interfaces. - GUI concepts - Swing - AWT

Final Examination Semester 2 / Year 2011

Chapter 5 Lab Methods

Topic 8 graphics. -mgrimes, Graphics problem report 134

H212 Introduction to Software Systems Honors

JFrame In Swing, a JFrame is similar to a window in your operating system

CSC Algorithms and Data Structures I. Midterm Examination February 25, Name:

CS-140 Fall 2017 Test 1 Version Practice Practice for Nov. 20, Name:

Inheritance Systems. Merchandise. Television Camcorder Shirt Shoe Dress 9.1.1

Abstract Class. Lecture 21. Based on Slides of Dr. Norazah Yusof

Drawing Geometrical Objects. Graphic courtesy of Eric Roberts

Overview. Applets. A Java GUI inside your browser! Important methods Drawing images Playing audio Getting input parameters Double buffering

1.00/1.001 Introduction to Computers and Engineering Problem Solving Fall (total 7 pages)

G51PRG: Introduction to Programming Second semester Applets and graphics

Objects and Classes (1)

CP122 Computer Science I. Chapter 2: Using Objects

1. Traffic Control CIT/CSE 230 PROGRAMMING PROJECT 4

Assignment 2. Application Development

Shared Collection of Java Course Materials: New Topics Covered. Agenda

Computer Science 210: Data Structures. Intro to Java Graphics

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 25, Name: KEY A

Chapter 5 Lab Methods

Exam: Applet, Graphics, Events: Mouse, Key, and Focus

Transcription:

AplusBug dude = new AplusBug();

AplusBug dude = new AplusBug(); dude 0x234 AplusBug 0x234 dude is a reference variable that refers to an AplusBug object.

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

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

access return type name params code public void speak( ) { System.out.println("chirp-chirp"); }

All members with public access can be accessed or modified inside and outside of the class where they are defined.

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

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

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

reference variable Scanner keyboard = new Scanner(System.in); object instantiation / constructor call

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); } the constructor } public static void main( String args[] ) { GraphicsRunner run = new GraphicsRunner(); } constructor call

Frame / JFrame Canvas / JPanel The Frame is used to hold up / display a Canvas or Panel.

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 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. }

Graphics frequently used methods Name Use setcolor(x) drawstring(s,x,y) drawoval(x,y,w,h) filloval(x,y,w,h) sets the current drawing color to x draws String s at spot x,y draws an unfilled oval at spot x,y that is w wide and h tall 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 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

void fillrect (int x, int y, int width, int height) window.fillrect( 10, 50, 30, 70 ); method call with parameters

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.

Graphics frequently used methods Name drawline(a,b,c,d) drawrect(x,y,w,h) fillrect(x,y,w,h) Use draws a line starting at point a,b and going to point c,d draws an unfilled rectangle at spot x,y that is w wide and h tall 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;

0,0 X goes across Y goes down window.fillrect( 10, 50, 30, 70 ); 639,479

0,0 X goes across X=100 y=100 Y goes down width=50 height=50 window.filloval( 100, 100, 50, 50 );

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); }

Graphics frequently used methods Name Use drawarc(x,y,w,h,startangle,arcangle) fillarc(x,y,w,h,startangle,arcangle) draws an arc at spot x,y that is w wide and h tall 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;