Posts filed under 'Uncategorized'




9.11

 

.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

}

});

Add comment May 8, 2008

7.6

1.we should set up a controller in order to do that.

2.If an action listener has been added to a button. The actionlister will interface and packages the code to move the object in an actionPerformed method.

3.The roles and responsibilities of the model of a control class is to obtain a input, convert , reset , and then output the result.

 

 

 

 

Add comment May 6, 2008

6.8

1. you can set up a timer by setting up the initial position of the shape

 and at regular intervals move the object and repaint the panel.

2.the factor that affect the movement of a graphical object is position, velocity, direction. and turn.

3.Flicker is caused by the speed display medium when painting large complex images that must appear to move rapidly.We could elimiate flicker by simple display of constant motion in two dimensions.

4. A moving object has a velocity, which is the distance traveled in a given unit of time, and a direction.

 

 

 

 

 

 

 

 

 

 

 

 

 

Add comment May 1, 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

9.7

1. A table of numbers, can be implemented as a two-dimensional array.2. if an application required the variable tale references an array of four  elements. Each of these elements in turn references an array of five integers.  These application will need to use two dimensional array. 

Add comment February 25, 2008

9.6

1. Parallel arrays can be achieved by using two arrays in which corresponding elements are related.2. In this example, the parallel arrays are both full and the loops use the instance variable length. 3. String [] name = new String[50]int [] age = new int [50]int [] security = new int [50]String searchPerson;int correspondingAge = -1, correspondingSecurity = -1searchName = …for (int i = 0, i<name.length; i ++) if (searchName.equal (name[i]))correspondingAge = age [i]correpondingSecurity = security [i]break;}4.5.       array should contain the exponent and the other array should contain 2 raised to that power.

– int[] exponent = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

int[] powers = new int[10];

for (int i = 0; int < 10; i++){

power [i] = math.pow(2, exponent[i])

} ;

 

 

Add comment February 25, 2008

Previous Posts

Pages

Categories

Links

Meta

Calendar

December 2009
M T W T F S S
« May    
 123456
78910111213
14151617181920
21222324252627
28293031  

Posts by Month

Posts by Category