Answer all numbered and bulleted questions. Upload your answers and program files to the VikingWeb coursework section. Besides uploading your written answers to the VikingWeb, please turn in a printed copy either in class on the due date or leave a copy in the box outside my door later on during the day. (You may turn in the printed copies later than 5PM on the due date, but the files must be uploaded to VikingWeb at or before 5PM.)
Download the following files and run the TextFieldTest
program that we went over in class: [TextFieldFrame.java,
TextFieldTest.java]. As we
saw in class, when you press
We mentioned in class that the TextFieldHandler class is
an inner class because it is defined inside of the
TextFieldFrame class. Thus, as an inner class, the
TextFieldHandler class has access to the TextFieldFrame
object with which it is associated. The expression
Download the following files and run the ButtonTest
program: [ButtonFrame.java,
ButtonTest.java,
bug1.gif,
bug2.gif].
Download the following files and run the CheckBoxTest
program: [CheckBoxFrame.java,
CheckBoxTest.java]. Check
boxes generate different types of events than buttons or
textfields.
Download the following files and run the ListTest program:
[ListFrame.java,
ListTest.java]. You should see a
list of colors in a frame.
This code uses an example of an anonymous inner
class. We will discuss more about this in class, or
you may ask me about it.
Mouse events are handled through MouseListener and
MouseMotionListener interfaces. Mouse events can be trapped
and handled for any AWT or Swing component if an
appropriate event-listener object is registered with the
component.
Each of the mouse event-handling methods takes a
MouseEvent object as its argument. A MouseEvent object
contains information about the mouse event that occurred,
including the x- and y-coordinates of the location where the
event (such as a mouse click) occurred. Also, the methods
and fields of the InputEvent class (the superclass of
MouseEvent) allow you to determine which mouse button was
pressed (if applicable).
Download and run the following MouseTracker program:
[MouseTrackerFrame.java,
MouseTracker.java]. Examine
the code and ask me if there is anything which you do not
understand in it.
Based on material from Deitel & Deitel, Java How
to Program, 6e.
null
argument to the
showMessageDialog
method call to:
TextFieldFrame.this
. What effect does this
have on where the dialog box pops up? Why? (You may resize the
frame to a large size in order to see the difference in
behavior.)
TextFieldFrame.this
refers to
the TextFieldFrame object. (Notice, also that the inner
class can directly refer to the fields of the outer level
object -- textField1, textField2, etc.)
2. The JButton class
3. The JCheckBox class
4. JList
5. Mouse Event Handling
6. Programming Exercises (complete for homework)
getGraphics
method
of the JComponent class (the superclass of JPanel).
(This should
allow you to draw freehand scribbles on the window using
the mouse. However, what happens if you resize the window
or minimize it and restore it? You do not have to handle
this properly for this assignment but you should have an
idea of how it could be corrected.)
Last modified: Thu Jan 27 09:26:32 EST 2005