1 / 14

Chapter 3 Creating a window

Chapter 3 Creating a window. classes. What does it mean to say a computer runs Java? the computer has a programme called the Java Virtual Machine How to solve a problem using Java? Find a class which does what you want it to For instance create a window

perrin
Télécharger la présentation

Chapter 3 Creating a window

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. Chapter 3Creating a window A Window

  2. classes What does it mean to say a computer runs Java? the computer has a programme called the Java Virtual Machine How to solve a problem using Java? • Find a class which does what you want it to For instance create a window • Tell the JVM to create an object from the instructions contained in the class How? • Send the object a series of messages telling it to do what you want it to. Known as methods JVM A Window

  3. Finding a class How do you know if there is a class which does what you want? Java ships with many classes which provide a great deal of functionality. That is a good place to start. Java web site java.sun.com/javase/7/docs/ JVM A Window

  4. Java docs Worth downloading the documentation A web page so normal browser A Window

  5. Local docs Unzip somewhere suitable and start exploring Description of the java system A Window

  6. Sun tutorials Link to sun tutorials (now Oracle) Excellent resource Description of the java system A Window

  7. API top 3 sections package names package descriptions all classes A Window

  8. API top We have created a window with buttons respond as expected resize visible/invisible without knowing anything about the system A Window

  9. Lessons To create instantiate an object from a class new <className> e.g. new JFrame(); To refer to an object you need to define a pointer (normally on instantiation) e.g. JFramejf = new JFrame(); JFramejfAlt = jf; In this case jfAlt and jf point to the same object. To access a method of the object send it a message. <Returned object> <objectName>.<methodName>(<message>); public booleanwinState() public void title() void means nothing will be returned boolean a boolean variable create name reference A Window

  10. Syntax What if there is no class which does what you want? Modify an existing one : Object Oriented Write a new class How? Normal procedural elements Variable assignment Conditional execution loops Object creation and manipulation. Inheritance Polymorphism Collections Error handling Basic computer literacy. Not covered a =27; if ... then ... else do while for OO specific covered. Semantics more than syntax A Window

  11. Themes How to design Object Oriented Programmes Encapsulation everything about the implementation of a class is contained in the class (and is inaccessible to the outside world) Inheritance how to enhance the functionality of existing classes. Polymorphism objects are accessed by pointers of a suitable type. The object must be an example of the object type which is pointed to by the pointer. You may refer to this as “a oranutang”, “a great ape”, “a primate”, or “a mammal” Possibly “a librarian” but never “a monkey” See T. Pratchett “Lords & Ladies” A Window

  12. Isolation Programmer Efficiency compromised by meetings1 Programmer code with minimal interaction with colleagues. Start – to agree division of labour in the application – to individuals and programme units. End – to verify correct operation. Code reuse supported by modularisation. Modularisation the ability of a piece of code to run independently of the rest of the application. Code maintenance and improvement supported by modularisation Code correctness supported by modularisation 1The Mythical Man Month: Fred Brooks Heat flow application needs to solve PDEs. Solver isolation allows reuse. Improvements involve small part of app. Code shown to be correct is always correct. A Window

  13. Reuse Stand on the shoulders of Giants1 Don’t re-invent the wheel. Use existing classes. Use Patterns. Solving problems leads to common patterns of interactions between objects. Those patterns can be documented using UML Reused to produce more robust & reliable code. Ideas can be found in Design Patterns: Elements of Reusable Object-Oriented Software1 1Issac Newton 2Gamma, Helm, Johnson, Vlissides Brief introduction A Window 0-201 63361-2

  14. summary The user tells the JVM to instantiate an object from a class. The users sends messages to methods of the object. In response to which the object performs the requested actions. Find classes at Java api java.sun.com/javase/7/docs/ Inheritance Encapsulation Polymorphism Isolation modularisation A Window

More Related