Programming and Problem Solving with Java

(やまだぃちぅ) #1
425

3.Provide a user interface with two buttons, Enter and Quit.
a.Write the statements that declare the variables for the buttons and two
listeners.
b.Write the statements that instantiate the buttons and the listeners.
c. Write the statements that add the buttons to the content pane.
d.Write the statements that register the listeners with the buttons.
e.Code classes that implement ActionListenerfor each button. When each but-
ton is clicked, display its name on the screen.


  1. a.Write the statement that stores the values entered in the field dataFieldinto
    the Stringvariable dataValue.
    b.Write a statement to replace the current contents of dataFieldwith "Next
    Value".

  2. a.Write the declarations needed for a frame (exampleFrame) whose content
    pane has one label (exampleLabel), one field (exampleField), and one button
    (exampleButton).
    b.Write the statements that define a class (ExampleClass) that is an implemen-
    tation of ActionListener. When the exampleButtonis clicked, the contents of
    exampleFieldare stored into exampleValueand removed from exampleField.
    c. Write the statements that registers the button event listener exampleHandler
    with its associated event source exampleButton.
    d.Write the statements that define a class (Example2Class) that is an
    implementation of ActionListener. When the exampleButtonis clicked, the
    contents of exampleFieldare copied into exampleLabel.
    6.Write the statement that displays the number 2000 in an existing JTextField
    object, called exampleField.
    7.Write the statement that takes the string representing an integer number in
    the JTextField exampleFieldand stores it into the intvariable data.
    8.Write the field declarations for a class whose objects each contain three labels
    (a data entry prompt, count, and average), a data entry field, and a button. Each
    of the objects also keeps a total and a count of the number of values entered.
    9.Write the constructor for the class described in Exercise 8. The class is called
    Exam. The count and total should initially be zero.


10.Write the event handler for the button component of the class described in
Exercises 8 and 9. When the button is clicked, the value should be read from
the text field, the count and average labels should be updated, and the value in
the text field should be reset to 0.


11.Write the heading for a constructor for a class called Demothat takes one
parameter of the class JLabeland a second parameter of the class String.

Free download pdf