200 likes | 218 Views
415.111 SC Introduction to Programming Lecture 1: 5 th May 2003. Course Information. Lecturer: Dr Jennifer Lennon Room 565 email: jennifer@cs.auckland.ac.nz Office hours: Mon (2-3), Wed (2-3),. Course composition. Labs 15% Test 20% Final Exam 65% Lectures Final exam
E N D
415.111 SC Introduction to Programming Lecture 1: 5th May 2003
Course Information • Lecturer: • Dr Jennifer Lennon • Room 565 • email: jennifer@cs.auckland.ac.nz • Office hours: Mon (2-3), Wed (2-3),
Course composition • Labs 15% • Test 20% • Final Exam 65% • Lectures Final exam • Homework Final exam • Labwork Final exam
. Course Information contd • Text • The Explorer’s Guide to Programming (to be collected (FREE OF CHARGE) from the Resource Centre) • Lecture notes (for revision) • Labs – as usual
This lecture: Outline • What is programming? • What is Java? • How do we run a Java program? • What is a program? • Introduction to Applets: • The coordinate system • Drawing text in the Applet window
What is programming? • Getting the computer to follow our instructions • E.g. Alice as well as all the Microsoft Office applications are programs
Why Learn programming? • To better understand how computers work • To make more intelligent guesses when they don’t work • In industry: • 80% work can be done by applications • 20% must be done by programmers
What language will we use? • Java • Why??? • It is a good teaching language • This is the Computer Science dept. • Follows through to COMPSCI.101 • It is a language for professionals • Is programming an art or a science? • Both
For Success in Learning Java • Attend all lectures • Read every word of the Explorer’s Guide • Do every exercise in the Explorer’s Guide • Attend all tutorials • Complete every assignment • You only learn by writing programs yourself
What is a program? • It is a series of statements. • For example the statement: • g.drawString("Hello Computer", 50, 100); • Displays Hello Computer on the computer screen. • What happens if we make a mistake? • The computer displays an error message, or • it does something unexpected.
Running a program Open the 111 Course folder Open the Explorer’s Guide folder Open the Sample programs folder • Copy the Chapter 1-progs to your G:drive. • Open the program of you want to run
Running a program continued: Double click on the FirstHello.java file
Running a program contd Now choose Run Java Applet from the Tools menu After a short wait the following window appears:
Painting in the Applet Window • The following line tells the Java system that we are going to draw in the Applet window: • public void paint( Graphics g ) • In Java terminology we say that we are going to "paint" in the window.
The Applet Window: a grid Pixels:
The g.drawString() Statement • g.drawString( "Hello World!", 30, 30 ); • This tells the system that we are going to draw the string "Hello World!" at position (30, 30) in the Applet window.
Positioning the text p12 (30,30) g.drawString("Zing!", 30, 30 );
Changing the font and font size p12 • g.setFont() • // * * * * * * * * * * * * * * * * * * * * * * * • // Hello Computer program revisited • g.setFont( new Font ( "TimesRoman", Font.BOLD, 18 )); • g.drawString( "Hello Computer!", 30, 30 ); • // * * * * * * * * * * * * * * * * * * * * * * *