Examples of Java Applets

Here are some simple applet examples. For each applet there is a list of things you can learn by looking at the applet source or the source of this document.
The First Applet
Error!
Graphics with Java (Graph.java)

  • Including an applet in different subdirectory (parameter CODEBASE).
  • Getting parameters from a HTML tag (getParameter).
  • There is a useful Math class (see p.316 of the book).
  • More about HTML tags.
  • Using basic colors (Color.white, Color.blue, ...)
  • setBackground(Color.red).

Error!
Bouncing Ball (Ball.java)

  • Writing a Runnable applet.
  • Running a new thread, sleeping in a thread.
  • Converting a number to a string (String.valueOf).


MouseListener Demo (MouseDemo.java)
  • Using MouseListener interface.
  • Example of how Class Fields (static modifier) can be useful.


MouseListener Demo, older version (OldMouseDemo.java)
  • Unlike the previous demo, this demo works in older versions of Netscape.



Error!
Bouncing Ball (Ball2.java)

  • Using double buffering technique (reduces flickering).


Error!
Drawing example (Draw.java)

  • Use of Buttons.
  • Using MouseMotionListener interface.



Error!
Bouncing Ball (FocusBall.java)


  • Using a FocusListener
  • Suspending a thread

Error!
BreakOut (BreakOut.java)

  • Using a KeyListener