Sample Programs for Class 3

Several sample programs are provided relating to the material covered in class 3. Click here to download the zip file containing these programs.

Panel1.java

The Panel1 program demonstrates simple user controls with a default layout manager.
  • Compile (javac Panel1.java)
  • Execute - applet panel1.html
  • View Source

    Panel2.java

    The Panel2 program demonstrates more complex user controls and some of the other layout manager types. To use it:
  • Compile - javac Panel2.java
  • Execute - applet panel2.html
  • View Source

    Panel3.java

    The Panel3 demonstrates construction and use of menus, frames and card layout. To use it:
  • Compile - javac Panel3.java
  • Execute - applet panel3.html
  • View Source
  • View menu frame source

    Event1.java

    The Event1 demonstrates mouse movement events. When the program is running, you can click and hold down the mouse button (either left or right) and move the mouse. When you release the mouse button, the program will display text indicating your start and end points. To use it:
  • Compile - javac Event1.java
  • Execute - applet event1.html
  • View Source

    Event2.java

    The Event2 demonstrates mouse drag events. When the program is running, if you click and hold down the right mouse button and then move it, the program will track your movement with text. To use it:
  • Compile - javac Event2.java
  • Execute - applet event2.html
  • View Source

    Event3.java

    The Event3 demonstrates mouse drag events. When the program is running, if you click and hold down the left mouse button you will draw a rectangle based on where you release the mouse button. Then, if you move the mouse cursor inside this rectangle and click and hold the left button and then move the mouse the rectangle will follow. If you position the mouse cursor inside but very close to one of the rectangle edges, you can size the rectangle. To use it:
  • Compile - javac Event3.java
  • Execute - applet event3.html
  • View Source