Lecture 18: Swing GUI Components
What is a Graphical User Interface?
A user interface is what clients of your program can see, access, and use A GUI gives a program a distinctive "look and feel". A GUI is event driven (User interaction determines
Lecture 7: Comparing Values, Boolean Operators
Comparing float and double values
do not test for equality since round-off errors are common instead, test if two floating point numbers are close enough to each other you specify how close they need
Lecture 8: Arrays
What is an array?
a data structure that consists of a sequence of related data items of the same type. a static entity (ie remains the same size once it is created) an object so must be allocated with new
What is the type of an
Lecture 9: Dialogs, Wrapper Classes, AutoBoxing, Enhanced for loop, Packages
Input Dialog Boxes
Getting input from the keyboard using an input dialog
String input = JOptionPane.showInputDialog("Enter some integers: "); /* Stores the user's data in
Lecture 10: Inheritance
What is inheritance?
Inheritance is a mechanism for building a new class by extending an existing one. The new derived class inherits behavior and attributes of an existing base class, yet has unique characteristics of its
Lecture 11: More Inheritance, final Methods and Classes, abstract Methods and Classes
References and Inheritance
Subclass references can be implicitly converted to superclass ones eg
SubClass subref = new SubClass(); SuperClass supref = subref;
Lecture 12: Access Control Specifiers Polymorphism
Access Control Specifiers
public - makes the member accessible to method definitions of its own class or to an object reference of its class via the dot operator (.) protected - an intermediate l
Lecture 13: Generics
What is "Generics"?
Generics is a new capability of Java which allows you to abstract over types introduced in version 1.5.0 (Java's answer to C+ templates)
What is Generics good for?
Generics forces compile-time type checking
Lecture 14: Class Design, Interfaces
Class Design Guidelines
1. Be sure your class models a single welldefined concept. (Define a class BruinTester instead of defining main in class Bruin.) 2. Stick to the principle of least privilege (Only define
Lecture 15: Collections
What is a collection?
A collection is object that groups multiple elements into a single unit.
Implementations of a Collection an ArrayList a Vector a LinkedList a Stack a PriorityQueue a TreeSet Note: An array is NOT a Co
Lecture 16: JFrames, JComponents, and Graphics
What is a JFrame?
a window with a title bar A content pane is a container that holds and displays swing GUI components (JComponents) according to some layout.
What a JFrame looks like
Lecture 6: Specifying Control Flow in Java Enumerated Types
What is Control Flow?
the order in which statements are to be executed in a computer program
How can we affect control flow?
via 3 types of control structures: 1. sequence 2. selection
Lecture 5: Strings and Scanners
sequences of characters String is a class in Java Java also has String literal values which are enclosed in quotation marks eg apple values (object or literal) can be concatenated by the + operator
Lecture 4: Variables, this, Number Problems, Casting, Constants, Static Methods
3 Roles for Variables
1. member variables (fields) 2. local variables 3. method parameters
Member Variables (Fields)
declared in the body of the class definition but
Lecture 19: More Swing GUI Components
a container on which JComponent objects can be placed often extended to create new components default size is 0 pixels wide, 0 pixels tall opaque by default JPanel p = new JPanel();
Creating Borders ar
Lecture 20: Inner Classes
a class defined inside another class can be defined inside a method or not can have either public, protected, private, or package access (works in the same sense as for an outer class member) the compiler tur
Lecture 21: Event Handling
an event is an interaction of the user with a GUI component events are modeled in Java by event objects Examples
pressing a button (ActionEvent) selecting a menu item (ActionEvent) pressing a key (KeyEvent) sett
Lecture 22: Exception Handling
What is an exception?
an indication that a problem occurred during the program's execution modeled in Java by Throwable and Exception objects
Examples of exceptions
out-of-bounds array subscript arithmetic overflow
Lecture 23: Files and Streams
Reading Text Files
1. Create a FileReader 2. Pass the FileReader into a Scanner constructor 3. Use the Scanner to get the data from the file as you would if it were coming from the console (System.in) or from a String
Lecture 24: Object Serialization, Threads, Multithreading, javax.swing.Timer
What is object serialization?
the process of saving objects to a stream it is called serialization because each object is assigned a serial number on the stream if the s
Lecture 25: Multithreading
has built-in multithreading or concurrency (platform dependent) includes multithreading primitives as part of the language itself
Multithreading classes and interfaces
the most primitive classes encapsulating Java
Lecture 1: Computers, Programming Languages, Introduction to Java
developed by James Gosling (Sun Microsystems) latest version: 1.6 a fully object-oriented programming language used for implementing
network based applications software for d
Lecture 2: Data Types, Variables, Classes, Methods, Objects, References
Java Data Types
primitive data types
char 'a', '3', '\n', '\uffff' 16-bit unicode boolean true,false byte -128 to 127 short -32,768 to 32,767 16-bit int -2,147,483,648 to 2,
Lecture 3: Objects, Constructors, More on Methods and Variables
What is an object?
An object is an instance of a class is data held in memory has its own attributes and behaviors as specified in its class definition is accessed by object reference
Lecture 17: Colors, Fonts, Applets
modeled by the java.awt.Color class can define a color by specifying an RGB value (Red, Green, Blue) every color can be represented uniquely as combination of these primary colors each primary color compo