1 / 59

Graphical User Interface Programming

Graphical User Interface Programming. Dr. Susan McKeever (not me) Email: richard.lawlor@dit.ie www.comp.dit.e/rlawlor. UI Programming. At the end of the course you will be able to: Develop GUI applications Use standard UI components Develop custom UI components And… Program in Java

galya
Download Presentation

Graphical User Interface Programming

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. Graphical User Interface Programming Dr. Susan McKeever (not me) Email: richard.lawlor@dit.ie www.comp.dit.e/rlawlor

  2. UI Programming • At the end of the course you will be able to: • Develop GUI applications • Use standard UI components • Develop custom UI components • And… Program in Java • And.. Be a better programmer

  3. Admin… • Assessment: • 1 formal exam = 50% • 1 assignment + in class test = 35% • Lab marks = 15%

  4. Admin • Contact Hours: • 1 hour lecture • 2 hour lab session • 1 hour tutorial

  5. Admin • Tutorial/Lecture/Lab • Lecture • Provide new material • Usually new Lab exercises • Lab • Work on latest Lab Sheet • Lab content will be a week behind the lecture.. • Tutorial • Discuss issues from last Lab Sheet • Review Broken Code/error messages

  6. Course.. • Topics • Java Language Basics • Hello World • Operators/Reference Types • OO Basics • Packages • Abstractions • Exceptions • Connecting to Databases JDBC • “Good” programming practices • GUIs (Java Swing) • Layout Managers • Event Handing • Graphics • Applets • GUI Design • Class structures and Model View Controller (MVC)

  7. Resources… • Resources • Web, web, web, web, web, web,……………… • JAVA API http://download.oracle.com/javase/6/docs/api/ • Textbook: UI Programming: Paul Fischer, An Intro to GUIs with Java SwingGeneral Reference: Java in a Nutshell, O’Reilly Java Swing, O’Reilly 2nd Ed. • Webcourses– www.comp.dit.ie/smckeever • CHECK YOU CAN ACCESS.. IF NOT EMAIL ME • Lecture notes • Lab Assignments & eventually Solutions • Assignments (Details and Submission) • Links to Useful References • Past Exam Papers.. Just 1 set..

  8. Important • Lecture notes are my guide to structuring lectures • They do not contain all material covered • Will do plenty of work/examples etc on the board

  9. Introduction toJava Programming

  10. Java Editions Java 2 Platform Java2 Standard Edition (J2SE™) Java2 Enterprise Edition (J2EE™) Java2 Micro Edition (J2ME™) Standard desktop & workstation applications; applets Heavy duty server Systems – mediumto large companies Small & memory constrained devices

  11. Key Benefits of Java • Java is “write once, run anywhere” • architecture neutral • portable across different platforms • Due to Java Virtual Machine (JVM) • Security features • highly configurable security levels prevent any piece of Java code doing harm to the host system

  12. Key Benefits of Java • Network-centric platform • easy to work with resources across a network and to create network based applications • Object Oriented • an interacting collection of independent software components • dynamic extensible programs

  13. Key Benefits of Java • Internationalisation • uses 16 bit Unicode characters that represents the phonetic and ideographic character sets of the entire world • Performance • although an interpreted language Java programs run almost as fast as native C, C++ programs • Simple and easy to develop • powerful & well designed set of APIs • http://download.oracle.com/javase/6/docs/api/

  14. 1001100101001 … … Interpreted by JVM class myCode { … … … …} Bytecode myCode.class myCode.java JVM Compiled by Java compiler Source Code Application runs

  15. JVM • JVM provides the run time environment for the bytecode(Java Runtime Environment JRE) • executes the bytecode and causes native machine code instructions to execute on the CPU that the JVM is on  each target platform needs an implementation of the JVM

  16. The Simplest Java Program public class HelloWorld{ // no fields // main method public static void main (String [] args){ System.out.println("Hello World.."); }}

  17. Basic Program structure • Basic class definition - remember from OO programming last year?class className { // field declarations … // method declarations … }

  18. Class versus Object?

  19. The Simplest Java Program public class HelloWorld{ // no fields // main method public static void main (String [] args){ System.out.println("Hello World.."); }} To run a java program, you need a special methods called the main method to tell the program where to start executing

  20. accessible to all classes(info hiding) Simple Java Program public class HelloWorld{ // no fields // main method public static void main (String [] args){ System.out.println("Hello World.."); }} command line args indicates class method returns nothing invoking a member Not much point in creating an object out of this class.. It doesn’t describe anything.. It just “runs”

  21. Objects • An object includes state (fields) and behaviour (methods) • A class object is the blueprint for the instance objects • All code must be included in a class • no inline functions like C++

  22. An Example Class • Want to create a class that represents a student. • Want to store a “name” for the student. • How? • Want to the class to have a way to print out the student name • How?

  23. An Example Class public class Student { // member fields private String name; // constructor public Student(String name) { this.name=name; } // methods public void printDetails(){ System.out.println("\nName: “ + name); } }

  24. An Example Class a business class predefined Java class public class Student { // member fields private String name; // constructor public Student(String name) { this.name=name; } // methods public void printDetails(){ System.out.println("\nName: “ + name); } } accessibility no return type reference to the object itself String concatenation

  25. Instantiation (i.e. creating objects out of a class) • Class definition used to create a “class object” at runtime • E.g. created a Student class.. Now want to create a “real” student object • To instantiate “instance objects” use new operator ClassNamemyInstance = new ClassName(); where ClassName() is a constructor Note: no need to allocate the memory for the object like in C++

  26. Using a Class in a Program the program control class: Contains “main” source file called myProg.java public class myProg { public static void main(String args []){ // instantiate a Student object Student student1= new Student("Joe Bloggs"); Student student2= new Student(“Liz mckeever"); // invoke printDetails methodstudent1.printDetails(); student2.printDetails(); }}

  27. Using the JDK • Each class is stored in a source file “xxx.java” • The name of source file should be the same as the name of class public class myCode { … … … …} myCode.java Source File

  28. Compiling your source code • Compile each class source file into bytecode (class files) • In DOS To compile a java source file javac myCode.java • This creates a classfile called myCode.class BUT.. This year we’re going to use Eclipse 1001101001110101011 … … … … myCode.class Class File

  29. Eclipse • An Integrated Development Environment (IDE) • Originally created by IBM (2001) • Open source community, free • Widely widely used in industry • Increases coding efficiency • Spots compile errors as you type • Allows quick fixes • Helps file organisations/packages • Imports are easy • Demo..

  30. Eclipse • Free to download • Worth doing.. • http://www.eclipse.org/

  31. To run your program • All so easy in Eclipse.. • Click the “RUN” command in Eclipse – full instructions at the lab

  32. Using a Control Class // This is in a file call myControlClass.java public class myControlClass { public static void main(String args []){ // instantiate a Student object new StudentPrinter(); } }

  33. Using a Control Class // This is in a file call StudentPrinter.java public class StudentPrinter { // Constructor - instantiate a Student object public StudentPrinter() { Student student1= new Student("Joe Bloggs"); Student student2= new Student(“Liz mckeeve"); // invoke printDetails method student1.printDetails(); student2.printDetails(); } }

  34. Using a Control Class // This is in a file call Student.java public class Student { // member fields private String name; // constructor public Student(String name) { this.name=name; } // methods public void printDetails(){ System.out.println("\nName: " + name); } }

  35. General points to note.. • 80% of the cost of software is on maintaining code • Typically not the original developer • “You cannot be good at s/w development if you don’t make it as easy as possible for someone else to maintain your code” • Dr. Susan McKeever Sept 2012

  36. How? • ??

  37. Common sense • Comment your code • Header at the top of your code • Every method explained • Use meaningful names for variables, classes, objects... • Use java conventions (see overleaf) • Many more.. To be covered.

  38. Use Conventions.. • Java is Case sensitive • Use the conventions • Classes should be nouns, capitalised first letter e.g. Student, ImagePixel • Variables mixed case starting with lower. E.g. acctBalance, line • Constant are all upper case e.g. COLOR_RED • Methods are verbs, mixed case starting with lower e.g. getBalance()

  39. Java Syntax part 1 Java Syntax Primitive data types Operators Control statements

  40. Primitive data types • Using a variable in java.. You must declare what type of data can contain.. • int, char etc.. • A primitive type is predefined by the language and is named by a reserved keyword.... 8 of them in java

  41. Primitive data types • char (16 bits) a Unicode character • byte (8 bits) • int(32 bits) a signed integer • short (16 bits) a short integer • long (64 bits) a long integer

  42. Primitive data types • float (32 bits) a real number • double (64 bits) a large real number • boolean(8 bits) • values are true or false(keywords) • Used with control statements e.g. while, do , if • e.g.while (fileEmpty)

  43. Operators • Additive+ - • Multiplicative* / % • Equality (tests)== != • Assignment operators= += -= *= /= %=

  44. Operators • Relational operators< <= > >= • Increment operators (postfix and prefix)++ -- • Conditional operator (short cut for if/else ?: e.g. max = (a > b) ? a : b; • String concatenation +

  45. Logical Operators • Not ! • Logical AND && • Logical OR ||

  46. Control Statements • Similarto C/C++ syntax: • if statement if (x != n){ …}else if { … }else { … } • for statement for (int i=0; i<max; i++){ … };

  47. Control Statements • while statement while (x==n ){ …}; • do statement do {…} while( x<=y && x!=0);

  48. Control Statements • switch statement switch (n){ case 1: … break; case 2: case 3: … break; default: break;};

  49. Java Syntax Part 2 Java Reference Types Classes Arrays

  50. Reference Types • Classes and arrays are composite types • no standard size • contain other elements • Manipulated “by reference’’ to the object or array • Primitive data types manipulated “by value”

More Related