4.10

April 24, 2008 at 1:42 pm (Uncategorized)

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 ou would want a panel to set its preferred size, rather thant allow the size of the main window to determine that

Permalink Leave a Comment

3.7

April 24, 2008 at 1:13 pm (Uncategorized)

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

Permalink Leave a Comment

12.1

April 24, 2008 at 1:11 pm (Uncategorized)

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

Permalink Leave a Comment

2.7

April 24, 2008 at 1:11 pm (Uncategorized)

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, 12 8)
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);

Permalink Leave a Comment