Chapter 7-6

1.)Write a code segment that obtains an input from a text field called inputField, converts the input to an integer, and outputs the square root of the integer to a text field called outputField.

2.)Assume that an action listener has been added to button. Which method runs when the user clicks the button.

3.)Describe the roles and responsibilities of the model, view, and controller classes in a GUI program.

Published in: on April 30, 2008 at 4:09 pm  Leave a Comment  

Chapter 6-8

1.)Describe how to set up a timer and explain what it does.
When the timer is sent the start message, its clock starts ticking, when each interval of time passes, the listener’s actionPerformed method is triggered. This method runs the operations to move the object and repaint the panel, because the timer uses the computer’s clock to measure the intervals, they will not vary with the execution speed of the computer.
2.)Describe the factors that affect our perception of the movement of a graphical object.

3.)What causes flicker? How can flicker be eliminated.

4.)How do the direction and velocity of an object determine where it will be placed after a given unit of time

Published in: on April 30, 2008 at 3:58 pm  Leave a Comment  

Chapter 4-10

1.)write a code segment that uses an I/O dialog box to prompt the user for her name.

2.)write a code segment that display your name and address in a message box, name an address should be formatted on separate lines by using the “\n” character.

3.)why we need to used the methods Integer.parseInt and Double.parseDouble when receiving numeric input from an I/O dialog box.

4.)give an example of a situation where you would want a panel to set its preferred size, rather than allow the size of the main window to determine that.

Published in: on April 23, 2008 at 2:39 pm  Leave a Comment  

Chapter 3-7

1-a.)a filled rectangle with corner point(45, 20) and size 100 by 50
-g.drawRectangle(45, 20, 100, 50)
b.)a line segment with end points(20, 20) and (100, 100)
-g.drawSegment(20, 20, 100, 100)
c.)a circle with center point(100, 100) and radius 50
-g.drawCircle(150, 150, 50, 50)
d.)a triangle with vertices (100, 100), (50, 50), and (200, 200)
-g.drawTriangle(100, 100, 50, 50, 200, 200)
2.)describe the design of a program that displays a filled blue rectangle on a red background
-The program uses a modified version of the have added a paintComponent method that draws a blue regtangle containing a red text message when the window opens and whenever it is refreshed. The paintComponent methid first calls the same method in the superclass, using the reserved word super. The reason is that the method in the superclass paints the background of the panel.
3.)how does one compute the center point of a panel
-The method getWidth() and getHight() return the current width and hight of a panel, respectively. It will compute the center point of a panel. If the methods are called before the window is opened, they return a default value of 0.
4.)list the three properties of a text font
-color, font size, font style

Published in: on April 23, 2008 at 2:31 pm  Leave a Comment  

Chapter 2-7

1-a.)White-new Color(255, 255, 255)
b.)Black-new Color(0, 0, 0)
c.)Highest Intensity Blue-new Color(200, 200, 255)
d.)Medium Gray-new Color(128, 128, 128)
2.)A frame is a class which the code for application windows in Java is located. A panel is a flat, rectangular area suitable for displaying other objects such as geometric shapes and images. A layout manager is an object which a frame or a panel uses in container object in Java.
3.)When we have more than one penal or other objects to display in a window, we have to be concern about how they are organized or laid out.
4.)write a code used to set the layout for adding panels to a 5-by-5 grid in a window
import javax.swing.*;
import java.awt.*;
public class GUIWindow{
public static void main(String[] args){
JFrame theGUI = new JFrame ();
theGUI.setTitle(“Fourth GUI Progrgam”);
theGUI.setSize(300, 200);
theGUI. setDefaultCloseOperation(JFrame.EXIT_OM_CLOSE_);
JPanel.panel1 = new JPanel();
panel1.setBackground(Color.white);
JPanel.panel2 = new JPanel();
panel2.setBackground(Color.black);
JPanel.panel3 = new JPanel();
panel3.setBackground(Color.gray);
JPanel.panel4 = new JPanel();
panel4.setBackground(Color.white);
Container pane = theGUI.getContentPane ();
pane.setLayout(new GridLayout (5, 5));
pane.add(panel1);
pane.add(panel2);
pane.add(panel3);
pane.add(panel4);
theGUI.setVisible(true);
}
}

Published in: on April 22, 2008 at 3:35 pm  Leave a Comment  

Chapter 12-1

EX 12-1
1.)what keeps a recursive definition from being circular
-The fact that sum(1) is defined to be 1 without making reference to further invocations of sum saves the process from going on forever and the definition fro being circular.
2.)what are two parts of any recursive method
-A method is said to be recursive if it calls itself. First, some function f(n) is expressed in term of f(n-1) and perhaps f(n-2) and so no. Second, to prevent the definition from being circular, f(1) and perhaps f(2) and so on are defined explicitly.
3.)why is recursion more expensive than iteration
-
4.)what are the benefits of using recursion
-

Published in: on April 18, 2008 at 5:10 pm  Leave a Comment  
Follow

Get every new post delivered to your Inbox.