The Artima Developer Community
Sponsored Link

Java Answers Forum
help leasse

1 reply on 1 page. Most recent reply: Nov 23, 2002 8:35 AM by Joyce Ann

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
jaz

Posts: 4
Nickname: jaz
Registered: Oct, 2002

help leasse Posted: Nov 22, 2002 6:53 AM
Reply to this message Reply
Advertisement
When the program starts, the Demo window will fill ? the area of the screen, and the center of the
window will be at the center of the screen. This sizing and positioning will be based on the current
screen display mode, not on hard-coded constants. The window title will be "Event-Handling
Demonstration". When the window is closed, the program will end.

The DemoPanel class will handle keyboard events using an inner class or classes. The
isFocusTraversable method will be used to allow the DemoPanel to obtain keyboard focus.
DemoPanel will collect from the keyboard all characters that are not action keys. Each time the Enter
key is pressed, DemoPanel will set the title of the Demo window equal to the characters collected since
the last time the Enter key was pressed, not including the Enter key. If the characters entered are an
integer number greater than 0, DemoPanel will set the current drawing square size (see below) equal to
this number. To set the square size, use a code structure similar to the following, where str is the
String of collected characters:
try {
squareSize = Integer.parseInt(str);
} catch (NumberFormatException xcp) {};

The DemoPanel class will use an inner class or classes to handle mouse events. Each time the mouse is
dragged with the left button depressed (not the right), the DemoPanel will set a filled square of pixels
at the mouse position to the current drawing color. This drawing will be done such that it is not
necessary to resize the window to get the drawing displayed. The center of the square will be at the
mouse position. The size of the square will be the current drawing size. The initial drawing size will be 2
pixels (a 2 X 2 square). Each time the left mouse button is double clicked, the current drawing color will
be set to the next color, in round-robin fashion. Changing the current drawing color will not change the
color of squares already drawn. The set of drawing colors will be blue, red, and green. The initial
drawing color will be blue. If the right mouse button is double clicked, the program will remove all the
squares drawn previously, so that they no longer exist. A crosshair cursor will be displayed whenever
the cursor is on the DemoPanel.

The Square class will have all fields required to define the position of a square, its size, and its color.
Square will have the following public method plus any other methods required:
public void draw(Graphics g), that draws the square.

i need hjelp. i started on it
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class DemoWindow extends JFrame { 
  private final int WIDTH = 200, HEIGHT = 200;   
public DemoWindow() {    
  //set title     
 setTitle( "Event-Handling Demostration" );  
     //get screen size    
   Dimension d = this.getToolkit().getScreenSize();      
 //1. if u want the fram to fill the whole screen use this code     
 setLocation( 0, 0 ); 
  //may not need because it's default   
   setSize( d.width, d.height );    
  //2. if u have a custom frame size use this code to    
   //   dynamically center it (assume the given size at top)    
  setSize( WIDTH, HEIGHT );     
 setLocation( (d.width-this.getWidth()) /2,              
      (d.height-this.getHeight())/ 2 );      
//to end program when frame is closed (using anynomus inner class)      
addWindowListener( new WindowAdapter()
 {     
    public void windowClosing( WindowEvent e )
{            System.exit( 0 );         }      });
 //end of inner class   }  
 public static void main( String[] args ) 
{      DemoWindow test = new DemoWindow();      test.setVisible( true );   }} //end of DemoWindow class
 
 


Joyce Ann

Posts: 5
Nickname: newtoforum
Registered: Nov, 2002

Re: help leasse Posted: Nov 23, 2002 8:35 AM
Reply to this message Reply
i try something: but you do the rest. this program in console program. try to put it in an applet: good luck ;)


import java.util.Random;
import java.io.*;

class GuessRandom {
public int setRange(int lowerLimit, int highLimit) {
return randNumber.nextInt(highLimit - lowerLimit + 1) + lowerLimit;
}
}
public class Assignment { // begin assignment class
public static void main(String s[])throws IOException { // begin main
final int ATTEMPT_LIMIT = 10;
final int RANDOM_NUMBER_LIMIT = 1000;
// create an instance of random
GuessRandom rNumber = new GuessRandom();
BufferedReader in = new BufferedReader(
new InputStreamReader(System.in));
int numberOfAttempt = 0;
int guessNumber;
int numberToGuess= rNumber.setRange(0,1000);
System.out.println(numberToGuess);
boolean counter = true;

while (counter) { // begin while
System.out.println("Enter your guess : " );
guessNumber = Integer.parseInt(in.readLine());

if (rNumber.cheNumberIsEqual)
counter = false;
else { // begin else
if (guessNumber > numberToGuess)
System.out.println("Guess to high.");
else
System.out.println("Guess to low.");
} // end else
numberOfAttempt++;
} // end while

if(numberOfAttempt < ATTEMPT_LIMIT)
System.out.println("Congratulations. You guessed the " +
"number in " + numberOfAttempt + " guesses - either you know the " +
"secret or got lucky!");
else if (numberOfAttempt == ATTEMPT_LIMIT)
System.out.println("Congratulations. You guessed the number in 10 guesses");
else
System.out.println("You took " + numberOfAttempt+ " guesses. You should be able to do better!");
} // end main
} // end Assignment class

Flat View: This topic has 1 reply on 1 page
Topic: help!: a loop problem Previous Topic   Next Topic Topic: Can we associate Visual Age with a new JDK

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use