1 / 25

Using Objects

Using Objects. Java Primitive Data Types. primitive. integral. boolean. floating point. byte char short int long float double. Begin with lowercase letters. Java Reference Types. Reference types:. 1. String 2. Class name.

varick
Download Presentation

Using Objects

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Using Objects

  2. Java Primitive Data Types primitive integral boolean floating point byte char short int long float double Begin with lowercase letters

  3. Java Reference Types Reference types: 1. String 2. Class name

  4. String Methods • int n = greeting.length(); • String bigRiver = river.toUpperCase();

  5. What is: Java Syntax??

  6. data type variable name Variables int total; int count, temp, result; Multiple variables can be created in one declaration

  7. What Does a Variable Declaration Do? int ageOfDog; 4 bytes for ageOfDog

  8. Variables • initial value in the declaration int sum = 0; int base = 32, max = 149;

  9. Assignment ageOfDog = 10;

  10. Variable Declarations and Assignment of Values VARIABLE DECLARATIONS ASSIGNMENT STATEMENTS

  11. Identifiers • Rules for identifiers in Java?

  12. package movetester; import java.awt.Rectangle; public class MoveTester { public static void main(String[] args) { Rectangle box = new Rectangle(5, 10, 20, 30); // Move the rectangle where x becomes 20 and y becomes 35 box.translate(15, 25); // Print information about the moved rectangle System.out.println(box.getX()); System.out.print("y: "); System.out.println(box.getY()); System.out.println("Expected: 35"); } }

  13. Packages • package areatester;

  14. We work with Objects • A fundamental entity in Java. • Objects are “things”

  15. java.lang.Object: the root of java classes

  16. Class Object • Class encapsulates objects • work together (behavior) • Objects have properties:

  17. HomeWork P2.1 - Programming Exercise

  18. Graphical User Interfaces GUI Objects

  19. frame Graphical User Interfaces (GUI): Demonstrates the object concep0t! Content pane used to display objects in a frame

  20. 01:import javax.swing.JFrame; 02: 03:publicclass EmptyFrameViewer 04:{ 05:publicstaticvoidmain(String[] args) 06:{ 07: JFrame frame =newJFrame(); 08: 09: frame.setSize(300,400); 10: frame.setTitle("An Empty Frame"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 12: frame.setVisible(true); 14:} 15:} Example: Frame Viewer

  21. Jframe frame • Point to object frame = new JFrame (name); (creates a class instance)

  22. See Sun site for greater detail Sun.java

  23. Lab 2:Graphical Fun • Using the example in your text book on page 64; Section 2.13: • Create your own FaceViewer Class with a main method that will show a JComponent. • Adjust your Frame to be square • The frame title must contain your name. • Using the FaceComponent example as a guide (page 64; Section 2.13): • Create an Animal Viewer and draw an animal of your choice. • Draw a string that describes the animal • Set colors as desired

  24. Output • Two classes - tested • Upload to the appropriate dropbox Lab Completion

  25. Object Lessons?

More Related