Presentation is loading. Please wait.

Presentation is loading. Please wait.

Review of CIS 120 Concepts: What you said you want….

Similar presentations


Presentation on theme: "Review of CIS 120 Concepts: What you said you want…."— Presentation transcript:

1

2 Review of CIS 120 Concepts: What you said you want….

3 Applets: Using applet methods Games Applet design Applet “things to know” The basics about applets Organizing applets Initializing applets Writing applets Applications of applets Coding the HTML file Threads Drawing in applets Sounds, pictures

4 Control Structures How they work and why Nested for loops Good quick review Putting it together Practice in programs Common errors

5 Methods Calling methods How methods work How to use methods Set up Recursion Handouts Parameter passing Method overloading and overriding How to use multiple methods in programs Practice writing Using JFrame

6 Arrays Set up array Arrays of objects Syntax of arrays Handout of a program with use of an array of objects How arrays work Multidimensional arrays Practice programming using arrays Applications for arrays Arrays in loops Accessing, sorting Arrays and methods Storing and retrieving from arrays Addresses in memory Vectors Graphics in arrays

7 Applets: Chapter 3, sections: 3.1-3.4 HTLM file is executed Web browser or appletviewer needed JApplet is the superclass (“extends”) –A “template” or “blueprint” for all applets –Provides behaviors (methods) init start paint –Provides attributes (data)

8 Applet Methods Ch 3, sect: 3.1-3.4; Ch 6 sec. 6.10 public void init( ) –Called only once –Intializes “fields” or instance variables –Creates the GUI if exists public void start( ) –For animations –Returns from web links public void paint(Graphics g) –Draws graphics on the applet –Called by the applet container –First line should be: “super.paint(g);”

9 Applet example import java.awt.Graphics; // import class Graphics import javax.swing.*; // import package javax.swing public class Draw3 extends JApplet { // draw shapes on applet's background public void paint( Graphics g ) { // draw rectangle starting at (10, 10) that is 50 // pixels wide and 50 pixels tall g.drawRect( 10, 10, 50, 50 ); // draw oval starting at (10, 10) that is 50 pixels // wide and 50 pixels tall g.drawOval( 10, 10, 50, 50 ); } } // end class Draw3

10 HTML file for Draw3 applet

11 To run an applet appletviewer Draw3.hmtl Or open the html file from within a web browser

12 Control Structures Order of statements specified by algorithm This order is called program control Program control is handled by control structures: –Sequence –Selection –Repetition

13 Sequence Step-by-step In order Example: number1 = Integer.parseInt(firstNumber); number2 = Integer.parseInt(secondNumber); sum = number1 + number2; JOptionPane.showMessageDialog( null, “The sum is “ + sum, “Results”, JOptionPane.PLAIN_MESSAGE);

14 Selection If If Else Nested If Switch

15 if example if (studentGrade >= 60) System.out.println (“Passed” );

16 If-else example If (grade >= 60) System.out.println (“Passed” ); Else System.out.prinlty (“Failed” );

17 Nested if example if (studentGrade >= 90) System.out.println (“A”); else if (studentGrade >= 80) System.out.println (“B”); else if (studentGrade >= 72) System.out.println (“C”); else System.out.println (“You must retake course”);

18 Switch example (p. 183) public void paint (Graphics g) { super.paint (g); for ( int i = 0; i < 10; i++) { switch (choice) { case 1: g.drawLine (10, 10, 250, 10 + i * 10); break; case 2: g.drawRect (10 + i * 10, 10 + i * 10, 50 + i * 10, 50 + i * 10); break; case 3: g.drawOval (10 + i * 10, 10 + i * 10, 50 + i * 10, 50 + i * 10); break; default: g.drawString (“Invalid value entered”, 10, 20 + i * 15); }//end switch }//end for }//end paint

19 Repetition When to test: –Prettest (test before loop) while for –Posttest (test after loop) do-while Types of control Counter-controlled Sentinel-controlled

20 Example of while (also counter-controlled) while (counter <= 10) { g.drawLine (10, 10, 250, counter * 10); counter++; }//end while

21 Example of for (counter controlled) For (int count = 1; count <= 10; count++) g.drawLine (10, 10, 250, count * 10);

22 Example of do-while (also counter-controlled) do { g.drawLine (110 – count * 10, 110 – count * 10, count * 20, count * 20); ++count; } while (count <= 10);

23 Sentinel-controlled repetition while (grade != -1) { total = total + grade; gradeCounter = gradeCounter + 1; gradeString = JOptionPane.showInputDialog (“Enter Integer Grade or -1 to Quit:” ); grade = Integer.parseInt (gradeString); }//end while

24 Summary 3.3 is a greater review of applets AND intro to objects! Read over the chapters and these slides Ask questions! Practice!

25


Download ppt "Review of CIS 120 Concepts: What you said you want…."

Similar presentations


Ads by Google