DOC PREVIEW
UVA CS 101 - Classes

This preview shows page 1-2-3-4-24-25-26-50-51-52-53 out of 53 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 53 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 53 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 53 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 53 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 53 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 53 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 53 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 53 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 53 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 53 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 53 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 53 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

ClassesAnnouncementsPreparationObject-oriented programmingFirst class – ColoredRectangleBackgroundSome Java Swing componentsExampleSlide 9Class ColoredRectangle – initial versionColoredRectangle in actionSlide 12ColoredRectangle.java outlineInstance variables and attributesSlide 15ColoredRectangle default constructorSlide 17Color constantsSlide 19Another possible ConstructorSlide 21Graphical contextJava coordinate systemMethod invocationSlide 25The Ig Nobel PrizesWednesday, 6 October, 2004Improving ColoredRectangleSlide 29A mutator methodMutator setWidth() evaluationA bit of humor…Java parameter passingSlide 34Slide 35Slide 36Slide 37Slide 38SubtletiesOther mutatorsSlide 41Mutator usageAccessorsAccessor usageSpecific constructionSlide 46Seeing doubleSlide 48An optical illusionCastingCasting, take 2Casting, take 3Casting, take 41ClassesCS 101-EChapter 4Aaron Bloomfield2AnnouncementsHWs are being renumberedJ1, J2, etc., for Java programming assignmentsC1, C2, etc., for CodeLab assignmentsHW1 = J1, HW2 = C1, HW3 = C2, etc.HWs J2 and J3 assigned this Wednesday (6 Oct)J2 due next Thursday (14 Oct)J3 due following Thursday (21 Oct)HW J4 will be assigned 18 Oct, and due 29 OctSome CodeLab HWs in there as wellSecond midterm on 27 OctNo labs this SundayCan go to another lab with permissionLab quiz grades will be entered by the end of this week3PreparationScene so far has been background material and experienceComputing systems and problem solvingVariablesTypesInput and outputExpressions AssignmentsObjectsStandard classes and methodsNow: Experience what Java is really aboutDesign and implement objects representing information and physical world objects4Object-oriented programmingBasisCreate and manipulate objects with attributes and behaviors that the programmer can specifyMechanismClassesBenefitsAn information type is design and implemented onceReused as neededNo need reanalysis and re-justification of the representation5First class – ColoredRectangle PurposeRepresent a colored rectangle in a windowIntroduce the basics of object design and implementation6BackgroundJFramePrincipal Java class for representing a titled, bordered graphical window.Standard classPart of the swing libraryimport javax.swing.* ;7Some Java Swing components8ExampleConsiderJFrame w1 = new JFrame("Bigger");JFrame w2 = new JFrame("Smaller");w1.setSize(200, 125);w2.setSize(150, 100);w1.setVisible(true);w2.setVisible(true);ConsiderJFrame w1 = new JFrame("Bigger");JFrame w2 = new JFrame("Smaller");w1.setSize(200, 125);w2.setSize(150, 100);w1.setVisible(true);w2.setVisible(true);ConsiderJFrame w1 = new JFrame("Bigger");JFrame w2 = new JFrame("Smaller");w1.setSize(200, 125);w2.setSize(150, 100);w1.setVisible(true);w2.setVisible(true);200 pixels 150 pixels125pixels100pixels// Purpose: Displays two different windows.import javax.swing.*;public class TwoWindows {// main(): application entry pointpublic static void main (String[] args) {JFrame w1 = new JFrame("Bigger");JFrame w2 = new JFrame("Smaller");w1.setSize(200, 125);w2.setSize(150, 100);w1.setVisible(true);w2.setVisible(true);}}10Class ColoredRectangle – initial versionPurposeSupport the display of square window containing a blue filled-in rectangleWindow has side length of 200 pixelsRectangle is 40 pixels wide and 20 pixels highUpper left hand corner of rectangle is at (80, 90)Limitations are temporaryRemember BMI.java preceded BMICalculator.javaLots of concepts to introduce11ColoredRectangle in actionConsiderColoredRectangle r1 = new ColoredRectangle();ColoredRectangle r2 = new ColoredRectangle();System.out.println("Enter when ready");Scanner stdin = new Scanner (System.in);stdin.nextLine();r1.paint(); // draw the window associated with r1r2.paint(); // draw the window associated with r2ConsiderColoredRectangle r1 = new ColoredRectangle();ColoredRectangle r2 = new ColoredRectangle();System.out.println("Enter when ready");Scanner stdin = new Scanner (System.in);stdin.nextLine();r1.paint(); // draw the window associated with r1r2.paint(); // draw the window associated with r2ConsiderColoredRectangle r1 = new ColoredRectangle();ColoredRectangle r2 = new ColoredRectangle();System.out.println("Enter when ready");Scanner stdin = new Scanner (System.in);stdin.nextLine();r1.paint(); // draw the window associated with r1r2.paint(); // draw the window associated with r2ConsiderColoredRectangle r1 = new ColoredRectangle();ColoredRectangle r2 = new ColoredRectangle();System.out.println("Enter when ready");Scanner stdin = new Scanner (System.in);stdin.nextLine();r1.paint(); // draw the window associated with r1r2.paint(); // draw the window associated with r2r1.paint()The messages instruct the objects to display themselvesr2.paint()ColoredRectangle object referenced by r1 is being sent a messageColoredRectangle object referenced by r2 is being sent a message// Purpose: Create two windows containing colored rectangles.import java.util.*;public class BoxFun {//main(): application entry pointpublic static void main (String[] args) {ColoredRectangle r1 = new ColoredRectangle();ColoredRectangle r2 = new ColoredRectangle();System.out.println("Enter when ready");Scanner stdin = new Scanner (System.in);stdin.nextLine();r1.paint(); // draw the window associated with r1r2.paint(); // draw the window associated with r2}}13ColoredRectangle.java outlineimport javax.swing.*;import java.awt.*;public class ColoredRectangle {// instance variables for holding object attributesprivate int width; private int height; private int x;private int y;private JFrame window;private Color color;// ColoredRectangle(): default constructorpublic ColoredRectangle() { // ...}// paint(): display the rectangle in its windowpublic void paint() { // ...}}14Instance variables and attributesData fieldJava term for an object attributeInstance variableSymbolic name for a data fieldUsually has private accessAssists in information hiding by encapsulating the object’s attributesDefault initializationNumeric instance variables initialized to 0Logical instance variables initialized to falseObject instance variables initialized to nullpublic class ColoredRectangle {// instance variables for holding object attributesprivate int width; private int x;private int height;


View Full Document

UVA CS 101 - Classes

Documents in this Course
Recursion

Recursion

15 pages

Iteration

Iteration

88 pages

PLEDGED

PLEDGED

6 pages

Objects

Objects

33 pages

PLEDGED

PLEDGED

11 pages

CS 101

CS 101

42 pages

Classes

Classes

83 pages

Iteration

Iteration

92 pages

Classes

Classes

186 pages

Classes

Classes

208 pages

Hardware

Hardware

21 pages

Arrays

Arrays

70 pages

Load more
Download Classes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Classes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Classes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?