COMP 110: Introduction to Programming Tyler Johnson Apr 20, 2009 MWF 11:00AM-12:15PM Sitterson 014.

Slides:



Advertisements
Similar presentations
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 2 Getting Started with Java.
Advertisements

Chapter 13 Graphics.
COMP 110: Introduction to Programming Tyler Johnson Feb 11, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson Feb 18, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson Feb 25, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson Mar 16, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson Mar 23, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson Apr 13, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson January 26, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson Feb 23, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson January 12, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson Mar 25, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson Apr 8, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson Apr 1, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson January 28, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson Mar 2, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson Apr 27, 2009 MWF 11:00AM-12:15PM Sitterson 014.
COMP 110: Introduction to Programming Tyler Johnson Feb 4, 2009 MWF 11:00AM-12:15PM Sitterson 014.
2010 Tax Class1 Day 3 Class Participation Class Exercise – Paul Austin Publ W Exercise page 98 Advanced Section.
Applets and Graphics.
Ziehm Academy - User Guide for online registration portal Nuremberg, February 2009.
Engr 691 Special Topics in Engineering Science Software Architecture Spring Semester 2004 Lecture Notes.
Chapter 15 Graphics. To paint, you need to specify where to paint. Each component has its own coordinate system with the origin (0, 0) at the upper-left.
AŽD Praha s.r.o. CRV&AVV ATO system used on vehicles of Czech Railways Dr.Ing. Ivo Myslivec AŽD Praha, Plant Technics, R&D WG1.
Efficient Solutions For Water Supply Helix High-Pressure Vertical Multistage Pump.
1 Cathay Life Insurance Ltd. (Vietnam) 27/11/20091.
Copyright 2010 by Pearson Education Building Java Programs More Graphics reading: Supplement 3G.
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
1 Graphical User Interfaces AWT and Swing packages Frames and Panels Components Nested Panels Images Reading for this Lecture: L&L, 3.9 – 3.11.
2D Graphics Drawing Things. Graphics In your GUI, you might want to draw graphics E.g. draw lines, circles, shapes, draw strings etc The Graphics class.
Chapter 8: Arrays.
Presented by: Yaseen Ali, Suraj Bhardwaj, Rohan Shah Yaseen Ali, Suraj Bhardwaj, Rohan Shah Mechatronics Engineering Group 302 Instructor: Dr. K. Sartipi.
Made with love, by Zachary Langley Applets The Graphics Presentation.
Vault 9 Project Update 9 th September 2009 Paul Pointon – Site Project Delivery Manager LLW Repository Ltd.
30 min Scratch July min intro to Scratch A Quick-and-Dirty approach Leaving lots of exploration for the future. (5 hour lesson plan available)
Web Design & Development Lecture 19. Java Graphics 2.
1 More on Applets Overview l Changing Colors l Changing Fonts & Styles l Applet Life-Cycle l Input using Dialog Window l Input using HTML parameters l.
Frame Windows A frame object is used to create a graphical frame window. This frame is used to show information in a graphical application. The JFrame.
Lecture 2 Internet Computing Using Java Theophano Mitsa UMASS-Dartmouth.
CSE 1341 Honors Professor Mark Fontenot Southern Methodist University Note Set 21.
Graphics and event-driven programs Learning objectives By the end of this lecture you should be able to: identify and use some of the common components.
Polymorphism Method overriding Method overloading Dynamic binding 1.
Chapter 2: Using Objects Part 2. Assume you wish to test the behaviour of some method. This is accomplished by providing a tester class: Supply a main.
Java Applets:. How Applets differ from application?: They do not use main method but init(), start() and paint() methods of the applet class They can.
Object Oriented Programming one of the main reasons we now teach Java instead of C++. C++ was designed to be backwardly compatible with the original.
Laboratory Study II October, Java Programming Assignment  Write a program to calculate and output the distance traveled by a car on a tank of.
Graphics You draw on a Graphics object The Graphics object cannot directly be created by your code, instead one is generated when the method paintComponent.
Graphics Chapter 16.  If you want to draw shapes such as a bar chart, a clock, or a stop sign, how do you do it?
PHY-102 SAPIntroductory GraphicsSlide 1 Introductory Graphics In this section we will learn how about how to draw graphics on the screen in Java:  Drawing.
LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class.
Graphics CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Applets Graphical Java programs Run inside web browser Platform-neutral Easy deployment--loads when needed Secure.
Chapter 5 Programming Graphics. Chapter Goals To be able to write simple applications To display graphical shapes such as lines and ellipses To use colors.
Chapter 5 Programming Graphics. Chapter Goals To be able to write applications with simple graphical user interfaces To display graphical shapes such.
Chapter 5 Ch 1 – Introduction to Computers and Java Defining Classes and Methods 1.
GUI and Swing, part 2 The illustrated edition. Scroll bars As we have previously seen, a JTextArea has a fixed size, but the amount of text that can be.
1 Chapter 15 l Basic Figures l Colors l Fonts and Other Text Details Graphics Objects.
1 Applets Chapter 1 To understand:  why applets are used to extend the capabilities of Web pages  how an applet is executed and know about the restrictions.
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
1 Interface Types & Polymorphism & introduction to graphics programming in Java.
Learn about the types of Graphics that are available Develop a basic Graphics applet Develop a basic Graphics application Review the Java API and use.
Chapter 15Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 15 l Basic Figures l Colors l Fonts and Other Text Details.
COMP 110: Spring Announcements Quiz Wednesday No Class Friday Assignment 5 Due next Monday Q&A Review Session Monday.
Introduction to Java Simple Graphics. Objects and Methods Recall that a method is an action which can be performed by an object. –The action takes place.
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
Lec 15 Writing an Applet Class. Agenda Writing an Applet class Java Graphics class.
CPCS 391 Computer Graphics Lab One. Computer Graphics Using Java What is Computer Graphics: Computer graphics are graphics created using computers and,
Intro to Graphics from Chapter 2 of Java Software Solutions
Drawing Shapes (Graphics Class) Creating Objects Packages
Presentation transcript:

COMP 110: Introduction to Programming Tyler Johnson Apr 20, 2009 MWF 11:00AM-12:15PM Sitterson 014

COMP 110: Spring Announcements Lab 8 has been graded Milestone 1 has been graded

COMP 110: Spring Questions?

COMP 110: Spring Today in COMP 110 Go over Lab 8 Java Graphics Programming Demo

COMP 110: Spring Lab 8

COMP 110: Spring Computer Graphics Computer Graphics is about producing images with a computer This can be useful in a variety of ways User interfaces (dialog boxes, icons, windows) Special effects (movies, games, etc) Image editing (photoshop) Visualizing scientific data

COMP 110: Spring Graphics in Java Java provides some useful classes & functionality for adding graphics to your programs

COMP 110: Spring Your First Graphics Program import javax.swing.JApplet; import java.awt.Graphics; public class HappyFace extends JApplet { public void paint(Graphics canvas) { canvas.drawOval(100, 50, 200, 200); canvas.fillOval(155, 100, 10, 20); canvas.fillOval(230, 100, 10, 20); canvas.drawArc(150, 160, 100, 50, 180, 180); } Wheres the main method?

COMP 110: Spring Applets public class HappyFace extends JApplet Our HappyFace class inherits from the class JApplet This means that our program is an applet instead of a normal application An applet is program that is meant to be run in a web browser Well use it as an easy way to get some graphics capability

COMP 110: Spring Applets Applets do not have a main method They cant be run like a normal application (using the red running man icon in jGRASP We need to use the apple icon to run the applet

COMP 110: Spring Drawing to Screen public void paint(Graphics canvas) { canvas.drawOval(100, 50, 200, 200); canvas.fillOval(155, 100, 10, 20); canvas.fillOval(230, 100, 10, 20); canvas.drawArc(150, 160, 100, 50, 180, 180); } Applets use a method called paint in order to draw to screen This method is called for you automatically when you start the applet

COMP 110: Spring Screen Coordinate System (0,0) x-axis y-axis (100,50) 50 pixels 100 pixels

COMP 110: Spring Drawing Shapes //draw oval at position 100, 50, of width and height 200 canvas.drawOval(100, 50, 200, 200); //draw a filled-in oval at position 155, 100 with w=10, h=20 canvas.fillOval(155, 100, 10, 20); //draw a filled-in oval at position x=230, y=100 with w=10, h=20 canvas.fillOval(230, 100, 10, 20); //draw an arc, details in the text on pgs canvas.drawArc(150, 160, 100, 50, 180, 180);

COMP 110: Spring The Graphics Class What is the canvas object? An object of the Graphics class The graphics class knows how to draw things like shapes to the screen

COMP 110: Spring Setting the Color The Graphics class also provides the capability to change the color that shapes are drawn with Example //draw a yellow oval canvas.setColor(Color.YELLOW); canvas.drawOval(100, 50, 200, 200); //now draw a black oval canvas.setColor(Color.BLACK); canvas.drawOval(100, 50, 200, 200);

COMP 110: Spring Drawing Text to the Screen We can display text on the screen using the drawString method drawString(string, xPos, yPos) Example //print at string and position (60, 75) canvas.drawString("This will be printed to the screen", 60, 75);

COMP 110: Spring String Drawing Example import javax.swing.JApplet; import java.awt.Graphics; public class HappyFace extends JApplet { public void paint(Graphics canvas) { canvas.drawOval(100, 50, 200, 200); canvas.fillOval(155, 100, 10, 20); canvas.fillOval(230, 100, 10, 20); canvas.drawArc(150, 160, 100, 50, 180, 180); canvas.drawString("This is a happy face!", 50, 50); }

COMP 110: Spring Drawing Polygons A polygon is a closed figure made up of line segments that do NOT cross

COMP 110: Spring Drawing Polygons You can draw a polygon by giving the locations of the corners There are two functions you can use drawPolygon Draws an unfilled polygon (just the edges) fillPolygon Draw a filled polygon p1 p2 p3 p4 p5

COMP 110: Spring Drawing Polygons Syntax canvas.drawPolygon(X_Array, Y_Array, Num_Points) canvas.fillPolygon(X_Array, Y_Array, Num_Points) Example int[] xHouse = {150, 150, 200, 250, 250}; int[] yHouse = {100, 40, 20, 40, 100}; canvas.drawPolygon(xHouse, yHouse, xHouse.length);

COMP 110: Spring Creating Dialog Boxes Dialog boxes are special windows that can be used to take input from the user or to display output

COMP 110: Spring Dialog Boxes Dialog boxes can be created using the JOptionPane class import javax.swing.JOptionPane; public class JOptionPaneDemo { public static void main(String[] args) { String name = JOptionPane.showInputDialog("Enter your name:"); JOptionPane.showMessageDialog(null, "Hi " + name + "!"); System.exit(0); }

COMP 110: Spring Input Dialogs Input dialogs take input from the user in the form of a string We use the showInputDialog method of the JOptionPane class Example String name = JOptionPane.showInputDialog("Enter your name:")

COMP 110: Spring Output Dialogs Output dialogs are used to display a message to the user We use the showMessageDialog method of the JOptionPane class Example JOptionPane.showMessageDialog(null, "Hi " + name + "!");

COMP 110: Spring Methods of JOptionPane If showInputDialog and showMessage Dialog are called using the class name JOptionPane, what kind of methods must they be? Static, a JOptionPane object is never created String name = JOptionPane.showInputDialog("Enter your name:"); JOptionPane.showMessageDialog(null, "Hi " + name + "!");

COMP 110: Spring Exiting the Program public static void main(String[] args) { String name = JOptionPane.showInputDialog("Enter your name:"); JOptionPane.showMessageDialog(null, "Hi " + name + "!"); System.exit(0); } At the end of the program we called System.exit(0) This is necessary to get the program end when using things like windows/dialog boxes etc.

COMP 110: Spring Confirmation Windows We can also create dialog boxes that provide the user with the options Yes and No These are called confirmation windows

COMP 110: Spring Confirmation Windows import javax.swing.JOptionPane; public class JOptionPaneDemo2 { public static void main(String[] args) { while(true) { int answer = JOptionPane.showConfirmDialog(null, "End Program?", "Click Yes or No:", JOptionPane.YES_NO_OPTION); if(answer == JOptionPane.YES_OPTION) System.exit(0); else if(answer == JOptionPane.NO_OPTION) System.out.println("One more time"); else System.out.println("Error"); } } }

COMP 110: Spring Creating the Window int answer = JOptionPane.showConfirmDialog(null, "End Program?", "Click Yes or No:", JOptionPane.YES_NO_OPTION);

COMP 110: Spring Checking the Result if(answer == JOptionPane.YES_OPTION) System.exit(0); else if(answer == JOptionPane.NO_OPTION) System.out.println("One more time"); else System.out.println("Error");

COMP 110: Spring Programming Demo Improving our House Fill the house with a color Draw a door Draw a window

COMP 110: Spring Programming Demo (150, 100) (150, 40) (200, 20) (250, 40) (250, 100) (0,0) x-axis y-axis (175, 100) (175, 60) (200, 60) (200, 100) (220, 60) (220, 80)(240, 80) (240, 60) (150, 120)

COMP 110: Spring Programming Demo Programming

COMP 110: Spring Wednesday Begin reviewing for final