lecture19 - Administrative Issues More Applets and GUIs...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
More Applets and GUIs Lecture 19 Administrative Issues • Ongoing – Program 4 • Due Friday, June 20 th at 11pm – Homework 4 • Due Tomorrow Last Time • HTML Files • Importing Applet and AWT • Applets – The paint() method – The java.awt.Graphics class – The java.awt.Color class Extending Applet • All applets extend the java.applet.Applet class • Overrode paint() method • What other methods are inherited? • What else should we override? Applet Methods • In addition to paint() , you can override many inherited methods public void init() • Called when applet is first loaded public void destroy() • Called when the applet is unloaded (web browser closed) public void start() • Called when the applet is made active public void stop() • Called when the applet is made inactive Applet Methods • Other inherited Applet methods provide useful services public URL getCodeBase() • Returns the URL for the applet’s bytecode public URL getDocumentBase() • Returns the URL for the applet’s web page public AudioClip getAudioClip(URL url, String name) • Retrieves an audio clip from the given URL public Image getImage(URL url, String name) • Retrieves an image from the given URL
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Graphical Objects • Applets draw graphics to the screen • Useful to create Graphical Objects – An object that has a graphical representation – An object that can “draw” itself • Often done by providing a draw() method toString() vs. draw() • We already provide a method for displaying an object String toString(); – Returns a string that represents an object • We want a method to display an object graphically void draw(Graphics page); – Draws a representation of an object to screen Graphical Object Example public class Square { Color color; int length; int x,y; // NOTE: I’m skipping the constructor public void draw(Graphics page) { page.setColor(color); page.drawRect(x,y,length,length); } } Graphical Objects • Very useful for more complex objects PlayingCard • Draw method would draw a card to reflect the value and suit Car • Draw method could draw a car in the appropriate color • Displaying objects as graphical representations is as easy as printing text to the screen via toScreen() Using Graphical Objects
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/15/2009 for the course ASTRONOMY 1000 taught by Professor Kim during the Spring '01 term at Yonsei University.

Page1 / 8

lecture19 - Administrative Issues More Applets and GUIs...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online