Programming and Problem Solving with Java

(やまだぃちぅ) #1

424


9.Do we have to get a content pane from a JPanelas we do with a JFrame?
10.What method would you use to change the value displayed in aJTextFieldobject?
11.When giving a value to a label with new, what is passed to the constructor?
12.What method do you use to change the text within an existing label?
13.What happens if you forget to include the statement
dataFrame.setVisible(true);?
14.What are the three steps needed to add a button to a content pane?
15.What are the three parts of registering an event listener?
16.What happens when a user clicks a button but no listener is registered for
the event?
17.How are normal classes and classes that implement the ActionListener
interface different?
18.actionPerformedtakes one argument of a Java class. What is the name of the class?
19.What are the parts of an event loop?
20.Why do you not have to write an event handler for window closing?
21.How do you associate a string with a button event?
22.Describe the two ways that multiple buttons can be distinguished.

Programming Warm-Up Exercises


  1. a.Declare a button variable called stop.
    b.Instantiate a button object, labeling it “Stop”, and assign its address to stop.
    c. Declare a button listener variable and instantiate a button listener object.
    d.Register the button listener with the button.
    e.Add the button to the content pane dataPane.
    f. Write the statements to declare a listener class.
    2.Provide a user interface with two buttons, Enter and Quit.
    a.Write the statements that declare variables for the buttons and a single
    listener.
    b.Write the statements that instantiate the buttons and the listener.
    c. Write the statements that add the buttons to the content pane.
    d.Write the statements that register the listener with the buttons.
    e. Write the statement that accesses a button’s name from within an event han-
    dler.
    f. Code a class that implements ActionListener. When each button is clicked,
    display its name on the screen.

Free download pdf