All Matches
Solution Library
Expert Answer
Textbooks
Search Textbook questions, tutors and Books
Oops, something went wrong!
Change your search query and then try again
Toggle navigation
FREE Trial
S
Books
FREE
Tutors
Study Help
Expert Questions
Accounting
General Management
Mathematics
Finance
Organizational Behaviour
Law
Physics
Operating System
Management Leadership
Sociology
Programming
Marketing
Database
Computer Network
Economics
Textbooks Solutions
Accounting
Managerial Accounting
Management Leadership
Cost Accounting
Statistics
Business Law
Corporate Finance
Finance
Economics
Auditing
Ask a Question
Search
Search
Sign In
Register
study help
computer science
introduction to programming with java a problem solving approach
Questions and Answers of
Introduction To Programming With Java A Problem Solving Approach
Can an Image object be a node in a scene graph?
Provide a statement that registers a lambda expression that assigns an Image object named SCARED to an ImageView object named face when the user clicks on face.
Provide a Slider constructor call with minimum value of 0, maximum value of 50, and initial value of 10.
In the following code fragment, replace with code that implements an animation that moves the passed-in circle parameter from the left side of its pane container to the right side of that container
Suppose you’re given a window with two TextArea components, named msg1 and msg2, and a Button component. When clicked, the button swaps the contents of the two text areas. Provide the code that
Given the following program skeleton. Replace with a createContents method such that the resulting window matches the customer feedback window shown earlier in this chapter, in the TextArea Control
Write a statement that creates a check box named bold. The check box should be unselected, and it should have a label that says “boldface type”.
How can your code determine whether a check box is selected or not?
Given a gender.css file with the following contents:And the following desired initial display:Finish the skeleton program below so that the female and male radio buttons behave in the normal
The CheckBox, RadioButton, and ComboBox components are defined in what package(s)?
Provide a createContents method and a style sheet for a program that initially displays this window:After the user clicks the Select a day down arrow and selects Thursday and clicks the Select a
Using JavaFX’s API website, look up the MouseEvent class and list all of its static constant EventType values.
Modify the text’s slider-driven LunarEclipse program to make it simulate a solar eclipse. The main change will be adding a corona shape on top of the sun shape. The sun’s corona is the atmosphere
Implement a program that animates the solar eclipse described in the previous exercise. Omit the previous exercise’s slider.Exercise 19.9:Modify the text’s slider-driven LunarEclipse program to
What is a listener?
Write a statement that adds functionality to a program’s close-window button such that when the close-window button is clicked, it causes the program to terminate.
What is the name of the superclass for classes that contain components?
What package are JButton and many other J-prefixed components defined in?
Provide an initialization statement that declares a JLabel reference variable named hello and assigns “Hello World” to the reference variable.
Provide an initialization statement that instantiates a 10-character-wide text box object. As part of the initialization, assign the text box object to a reference variable named input.
Write a statement that registers a listener reference variable named responder with a component named component.
If you want a class to handle an event, what clause must be added to the right side of the class’s heading?
What is the heading of the one method specified by the ActionListener interface?
If a class is limited in scope such that it is only needed internally within another class, you should define the class to be an inner class.
If you want to implement an event handler with an anonymous inner class, what argument do you give to the addActionListener method to register the listener?
In the createContents method of the FactorialButton program in Figure 17.8a, what type of object calls the add methods?Figure 17.8a: /********************************** * Factorial Button.java * Dean
In the FactorialButton program in Figures 17.8a and 17.8b, what component fires the event that the listener handles?Figures 17.8a:Figures 17.8b: /********************************** *
What package contains the JOptionPane class?
Write a statement that displays a dialog in the center of the screen. The dialog should display “This is only a test.” in the message area, “TEST” in the title area, and no icon.
Suppose that you have several components registered with the same listener, and the components and listener are defined within the same class. Within the listener, what ActionEvent method should you
Assume there’s a listener that’s been registered for several different buttons. Assume the listener uses an actionPerformed method with an ActionEvent parameter named action. Assume the user
Write a statement that sets the text color to blue for a JButton object named button1.
How do you get a reference to the container that surrounds all of the components in a JFrame object?
If your program needs the java.awt.event subpackage, you can implicitly import it by importing the java.awt package. (T / F)
Give three examples of how a user might cause an event to be fired.
For each of the following, what Java API package must you import?a) JFrame and JLabel b) FlowLayout.
For our previous GUI programs, we’ve done setup work (setting the title, adding components, and so on) within a constructor. That’s generally preferred, but it’s not a compiler requirement. For
Provide a complete program that displays this Hello World message:Note these label characteristics: (1) a raised bevel border, (2) italics, (3) a large font size (30 points),(4) a tool tip that
The width parameter in the JTextField constructor specifies the width of the text box in pixels. (T / F)
What can you do to prevent users from updating a JTextField component?
Write the heading for the method you must define in a class that implements an ActionListener.
The ActionListener interface and the ActionEvent class are in what Java API package?
An interface is a class-like thing whose methods are all empty. If an interface is applied to a class, then the interface acts like a template that the class must conform to. (T / F)
An inner class can access its enclosing class’s instance variables directly. (T / F)
It’s appropriate to use an anonymous inner class if you are going to use the class only once. In the Factorial program in Figures 17.8a and 17.8b, we use the listener object twice, so that listener
Do you have to create a JFrame window to use a JOptionPane dialog box?
To answer this question, you may need to look up JOptionPane’s showInputDialog and showConfirmDialog methods on Oracle’s Java API website. What does this program do? import javax.swing.JOption
By calling setEnabled(false), you can disable a button and give it a muted appearance and make its listener unresponsive to clicks on it. Modify Figure 17.12’s program so that the factorial button
To set a JFrame’s background color, what method should you call before calling setBackground?
What do the letters in “awt” stand for?
Layout managers adapt automatically to changes in the size of a container 0.or one of its components. (T / F)
Which package contains layout managers?
How does the FlowLayout manager arrange components?
Write a single statement that gives the current container a flow layout with right alignment.
Write a statement that gives a Frame object called frame a BoxLayout manager that aligns elements in a column.
What are the five regions established by the BorderLayout manager?
The sizes of the five regions in a border layout are determined at runtime based on the contents of the four outer regions. (T / F)
By default, how many components can you put in any one region of a border layout?
Write a single statement that adds a new JLabel with the text “Stop” to the center region of a BorderLayout manager. The label should be centered within the center region.
When you instantiate a GridLayout manager, you should always specify both the number of rows and the number of columns. (T / F)
In a grid layout, all cells are the same size. (T / F)
What happens to the xTurn variable in the Tic-Tac-Toe program if you click the same cell twice?
Why are JPanel containers particularly useful with GridLayout and BorderLayout windows (as opposed to FlowLayout windows)?
In the MathCalculator program’s createContents method, indicate the purpose of the statement: add(new JLabel());
JTextArea components are editable by default. (T / F).
JTextArea components employ line wrap by default. (T / F).
What happens if you click a check box that’s already selected?
Provide a statement that creates a check box named attendance. The check box should be preselected, and it should have an “I will attend” label.
What happens if you click a radio button that is already selected?
What happens if you click an initially unselected radio button that is a member of a RadioGroup?
How are combo boxes and radio button groups similar?
What two methods can be called to determine the current selection for a combo box?
The JobApplication program contains the following code fragment. What happens to the program if the code fragment is omitted?radioGroup = new
Provide a statement that adds a 20-pixel blank margin to a JPanel container named panel.
Provide a JSlider constructor call where the minimum value is 0, the maximum value is 50, and the initial value is 10.
What is the default layout manager for a JFrame window?
With a FlowLayout manager, a button component expands so that it completely fills the size of the region in which it is placed. (T / F)
Provide a complete program that is a modification of Greeting program. Your new program should use a BorderLayout manager (instead of a FlowLayout manager), and it should generate the following
With a BorderLayout, what happens if the east region is empty? Said another way, which region(s), if any, expand(s) if the east region is empty?
Assume you have this program:a) Specify the changes you would make to the above code to produce this output:b) Specify the changes you would make to the above code to produce this output: import
If a JButton component is directly added to a GridLayout cell, it expands so that it completely fills the size of its cell. (T / F)
Given the following code fragment, draw a picture that illustrates the buttons’ positions within the program’s window.setLayout(new GridLayout(0, 3)); add(new JButton("1"));add(new
What kind of container should you put into an individual grid layout cell or an individual border layout region to allow that cell or region to contain more than one component?
Suppose you’re given a window with two JTextArea components, msg1 and msg2, and a JButton component. When clicked, the button swaps the contents of the two text areas. Provide the code that
Provide a statement that creates a check box named bold. The check box should be unselected, and it should have a “boldface type” label.
How can your code determine whether a check box is selected or not?
Provide a createContents method for a program that displays this window:The male and female radio buttons should behave in the normal fashion— when one is selected, the other is unselected. Note
The JCheckBox, JRadioButton, and JComboBox components are defined in what package?
Provide a createContents method for a program that initially displays this window:When the user clicks the left combo box, this displays:When the user clicks the right combo box, this displays:Your
What does the ArrayList’s set method do?
A floating-point number can be thought of as a fraction. Provide a single statement (an initialization statement) that declares an ArrayList named fractions and assigns a newly instantiated empty
Using the fractions ArrayList created in the previous exercise, provide a code fragment that assigns eight random numbers (generated by Math.random) into fractions. Use a standard for loop for this
Provide a more compact (but functionally equivalent) version of this code fragment: ArrayList students = new ArrayList (); Student student1 = new Student ("Alex Trotsky", "History");
Suppose you have the ArrayList named students in Exercise 4, and assume the Student class has a getName method. Provide a for-each loop that prints all student names, one name per line.Exercise
Sort program using an ArrayList instead of an ordinary array. Instead of swapping, use ArrayList’s remove and add methods. Using nested for loops in the sort method makes the indexOfNextSmallest
Assume a Customer class has a constructor with a name parameter that initializes a name instance variable, and assume this class includes a getName method. A driver for this class includes this
Given the Customer class and driver described in the previous exercise, add code that removes from the customers list the discouraged customer who has been standing immediately behind (after) the
The main method in the ListExecutionTimes program contains this local variable initialization statement:ArrayList list = new ArrayList();After determining ArrayList execution times, we modified the
The times measured by the ListExecutionTimes program includes not only the time required to perform the targeted get and set operations. It also includes time required to perform the for loop
Assume that a stack has been declared and instantiated with the ArrayDeque class. Show the output produced by the following code fragment:You should be able to do this by just thinking about it, but
Showing 100 - 200
of 717
1
2
3
4
5
6
7
8