Archive for April, 2008




5.6

1. The method getIconWidth() and getIconehight () return the width and height, respectively, of an image in pixels. These method of the panel class to compute the position of the image relative to the center of the panel. 

2. Set the shape’s position to the new position.

Refresh the panel, which has the effect of clearing the panel and redrawing the shape at its new position

 

 

 

3. A program can detect and response to mouse events by attaching listener objects to a panel. When a particular type of mouse event occurs in a panel, its listen informed.

 

 

 

Add comment April 30, 2008

4.10

1.import javax.swing .JOptionPane;

public class Name 

public static void main (String[ ] args){

    string inputStr = JOptionPane.ShowInputDialog (“Enter your name, ” ” ” )

if (inputStr == null)

 return;

2.

 

3.If the expected input is a number, one other thing must be done before it can be processed. The dialog box returns a string of digits, which must be converted to an int or a double. THe methods Integer.parseInt(aString) and Double.parseDouble (a String) accomplish this for intergers and floating number points.

 

 

4.This alternative is useful when we want the size of each panel to be exactly the size we want.

 

 

 

 

 

Add comment April 23, 2008

3.7

1.a)g.drawRect (45, 20, 100, 50) 

   b)g.drawLine (20, 20, 100, 100)

   c)g.drawCir (100,100,50)

   d)g.drawTri (100,100,50,50,200,200)

2. The program uses a modified version of the code for the ColorPanel class. Then added a paintComponent method that draws a blue rectangle containing a red text message when the window opens and whenever it is refreshed.

3. The method getWidth() and getHeight () return the current width and height of a panel. If these methods are called before  the window is opened, they return a default value of 0.

4. Color, Font style , Font size and Font name.

Add comment April 23, 2008

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, 0)
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.)where are panels displayed when a border layout is used to control their placement in a window
 When we have more than one panel 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[ ] arg){

theGUI. setTitle(” Fourth GUI Program”);

the GUI.setSize(300, 200);

the GUI.setDefaultCloseOperation(JFrame. EXIT_ON_Close);

JPanel panell = new Jpanel(); 

panel1.setBackground(Color.White);

JPanel panel2 = new Jpanel(); 

panel1.setBackground(Color.black);

JPanel panel3 = new Jpanel(); 

panel1.setBackground(Color.gray);

JPanel panel4 = new Jpanel(); 

panel1.setBackground(Color.white)

container pane = theGUI.get Content Pane( );

pane.setLayout(new GridLayout(5,5));

pane.add(Panel1);

pane.add(Panel2);

pane.add(Panel3);

pane.add(Panel4);

theGUI.setVisible(true);

 

 

 

Add comment April 22, 2008

12.1.

1. What keeps a recursive definition from being circular?     

a recursive definition is one that refers to itself by name in a manner that appears to be circular. the iterative definition keeps recursive definition from 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
-Recursive is more expensive than iteration because it has two costs: Extra time and extra memory are required to manage recursive function calls.
4.)what are the benefits of using recursion

it could calculate sequence numbers.

 

 

 
-

Add comment April 15, 2008

Pages

Categories

Links

Meta

Calendar

April 2008
M T W T F S S
« Feb   May »
 123456
78910111213
14151617181920
21222324252627
282930  

Posts by Month

Posts by Category