Create data representing an image, write a procedure that can accept the data and draw it
2
New cards
Object Oriented Language
Create an object that contains image data AND the function to draw it (data + function in one container)
3
New cards
public
keyword fro access control that allows all other classes in your program to access
4
New cards
private
can only be accessed within the class where the member (field or method) is defined
5
New cards
static
keyword that specifies that the member belongs to the class instead of a specific instance
6
New cards
main
method drives Java applications, which is the first place the JRE visits when running your application
7
New cards
methods
reusable commands
8
New cards
methods are composed of:
method signature + (method body)
9
New cards
method signature is composed of
return type + method name + parameters (void main (String args[])
10
New cards
Parameter
place holders for values
11
New cards
Arguments
actual values passed in
12
New cards
Application Programming Interface (API)
a set of publicly accessible methods, variables, and constants of classes typically stored in a library
13
New cards
JFrame to JPanel?
JFrame is like the picture frame, JPanel is like the canvas
14
New cards
Variable
a named memory location for storing a value
15
New cards
3 Things You Can Do With a Variable
1. Declaration (int x; int y)
16
New cards
2. Initialization (x \= 20, y \= 40, first time)
17
New cards
3. Assignment (post initialization
18
New cards
Benefits of declaring data types (2)
1. what kind of value to expect
19
New cards
2. how to allocate space accordingly
20
New cards
Primitive Variable Types
an identifier for a value
21
New cards
22
New cards
1. integer (byte, short, int, and long)
23
New cards
2. decimal (float and double)
24
New cards
3. char (a, b, c, &, *)
25
New cards
4. boolean (true or false)
26
New cards
Reference Data Types
A reference to an object's memory location
27
New cards
28
New cards
1. class
29
New cards
2. string
30
New cards
3. array
31
New cards
4. arraylist
32
New cards
Class
a program entity that represents a blueprint (aka template) for a type of objects
33
New cards
Object
A runtime entity that combines attributes and behaviours (many ball objects, one ball class)
34
New cards
Interface
provides a description o fa role declared with some capabilities (via method declarations)
35
New cards
What kind of object do you need to use to create animations?
swing timer object
36
New cards
- java.swing.timer
37
New cards
random function that returns a number between 1 and 6
(int) (1+ Math.random() * 5));
38
New cards
Client Object
An object that uses another object's functionalities
39
New cards
2 Meanings for Encapsulation
1. an object contains within itself both attributes and behaviours
40
New cards
41
New cards
2. An object hides its data from client programs (data hiding)
42
New cards
getter method
method that returns the current value of a private field
43
New cards
setter method
method we need to change the value of a private field
44
New cards
How to flip a drawing when it hits an edge?
scale(-1,1);
45
New cards
addMouseListener can only be added to \_______?
java.awt.Component (or its subclass, JPanel is a sublcass)
46
New cards
Use MouseListener for?
mouseclicked()
47
New cards
Use MouseMotionListener for?
mouseDragged()
48
New cards
Adapter class
classes that provide 'dummy implementations' for all the methods declared in the corresponding interface
49
New cards
Array
a contiguous collection of data items of a single type
50
New cards
Data structure
a particular way of storing and organizing data in a computer so that it can be used efficiently
51
New cards
52
New cards
- generally used for a computer to store and fetch data at any place in its memory, specified by an address
53
New cards
ArrayList
a resizable array that holds objects
54
New cards
Benefits of Graphics2D (3)
- It draws or fills primitives in a more flexible way
55
New cards
- It can draw more primitives than its parent class, e.g. curves
56
New cards
- It has functionality for checking intersection and containment between objects
57
New cards
shape
a geometric object passed in as argument, rather than coupled with method name
58
New cards
59
New cards
- e.g draw (shape)
60
New cards
fill (shape)
61
New cards
Ellipse2D, Rectangle2D, Arc2D etc are \_______ classes
abstract
62
New cards
When do you use the setter methods for the geom class?
1. during initialization
63
New cards
2. when properties of an object being modelled have changed
64
New cards
Search algorithm
about searching for an item in a list per some criteria: largest to smallest etc
65
New cards
Linear search algorthm
1. declare variable s for holding smallest and initialize it with the first element
66
New cards
2. interate through the rest of the elements and compare
67
New cards
Rule of Thumb 1
Make active object call if it runs against inactive objects that typically doesn't alter its state/behaviour (e.g boundary detection)
68
New cards
Rule of Thumb 2
Make the controller (panel object) call for the following scenarios:
69
New cards
70
New cards
- Two objects of different types (active vs. passive), both change state/behavior with collision
71
New cards
72
New cards
- Two active objects of the same type, only one changing state/behavior
73
New cards
Nested loop
putting one loop inside another
74
New cards
Encapsulation (2 meanings)
- An Object contains both attributes and behaviors
75
New cards
- An Object hides its data from client programs
76
New cards
2 Methods to Use Data hiding
- Use private keyword to hide fields
77
New cards
- Use public getter/setter methods to allow access to fields when necessary
78
New cards
Inheritance
child class inherits all of its parent class' attributes and behaviors and also extends its functionality
79
New cards
2 reasons for inheritance
1. code reuse
80
New cards
2. extension
81
New cards
this
a keyword that refers to the current object itself: a way to say "me" or "myself" by an object
82
New cards
super
a keyword that refers to the superclass portion of an object
83
New cards
Overriding Polymorphism
A subclass can redefine any of its parent class' methods with the same signature
84
New cards
85
New cards
More than one implementation
86
New cards
Polymorphism
The ability to create a variable or method that has more than one form
87
New cards
Inclusion polymorphism
A single variable can be used to reference an object of different classes that are connected by inheritance - a variable has more than one form
88
New cards
Finite State Machine (FSM)
commonly used in AI programming for creating variations of behaviour
89
New cards
90
New cards
A number of states and transitions between them based on conditions
91
New cards
Focus (for keyboard inputs)
you or the system has selected a particular component to be active to receive keyboard input
92
New cards
Code Pull up
pull fields or methods up to their superclass, or remove the redundant fields or methods from subclasses
93
New cards
Inheritance by Interface
allows us to group dissimilar classes of objects that are related only be certain common behaviour(s)
94
New cards
Interface allows for \_______ inheritance
multiple inheritance, whereas you can only extend one subclass or abstract class
95
New cards
Abstract class should be used with polymorphism when . . .
objects have common properties and even a common behaviour (draw)
96
New cards
Rule of abstract methods
any subclass that extends an abstract class must implement all the abstract methods it has declared
97
New cards
Why use abstract class and not interface?
you may need the parent class to hold some common properties and also define some common methods (other than those abstract ones), where an abstract class can do but an interface cannot