Lab 5: Java applets

Assignment due on Tuesday, June 10

Today, we will work on Java applets. As we have learned in class, writing applets is very similar to writing java applications. Translating a java application to a java applet is even easier, especially with a correctly formatted code.

In this assignment you will be required to translate your "lab 3 - monetary change" java program into an applet. Here are the steps to complete the assignment (Please reference Lecture 12 if you have any trouble):

  1. Create a new java project
  2. Import your lab3 code or add a new class to the project and copy paste the lab3 code
  3. If your class variables and methods contain keyword "static" remove all the "static" keywords
  4. Import java.applet.*, java.awt.*, and javax.swing.* to your project
  5. Add the following line to your class declaration: extends JApplet
  6. Rename your constructor method to init()
    e.g. public lab3() becomes public init()
  7. Rename your main method to paint(Graphics g).
    e.g. public static void main(String args[]) becomes public void paint(Graphics g)
  8. Cut and paste all your code in the paint method to the end of the init method. Note: after this step your paint method should have become empty
  9. Now we are finished with the cosmetic changes. So let's start adding applet features
  10. We are finished coding. Now let's try to run it. Go to the menu Run -- Run as -- Java applet
  11. If you have successfully ran your applet from Eclipse, it's time to add the applet into your web page.
Submission: Name your program "your name"_applet.java, where you will need to replace "your name" with your name. Email me your solutions before the deadline.