{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture19 - Administrative Issues More Applets and GUIs...

Info icon This 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
Image of page 1

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

View Full Document Right Arrow Icon
Graphical Objects 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
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern