I need help to draw an image and move it plz plz : )

Ok, so I have this whole code and I understand most of it but not all of it but I'm trying to make image "drop.gif" to move down the right side of the window. For each shot that is taken the image moves down ever so much and if the image hits the Entity ship "background" than notify death. PLease anyone help me !
there are 7 classes but here is the main ...
package spaceinvaderss;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferStrategy;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Main extends Canvas {
/*A Canvas component represents a blank rectangular area of the screen onto which the application can draw or from which the application can trap input events from the user.
An application must subclass the Canvas class in order to get useful functionality such as creating a custom component.
The paint method must be overridden in order to perform custom graphics on the canvas.*/
/** The stragey that allows us to use accelerate page flipping.*/
private BufferStrategy strategy;
/** True if the game is currently "running", i.e. the game loop is looping */
private boolean gameRunning = true;
/** The list of all the entities that exist in our game */
private ArrayList entities = new ArrayList();
/** The list of entities that need to be removed from the game this loop */
private ArrayList removeList = new ArrayList();
/** The entity representing the player */
private Entity ship;
/** The entity representing the alien */
private Entity alien;
/** The speed at which the player's ship should move (pixels/sec) */
private double moveSpeed = 600;
/** The time at which last fired a shot */
private long lastFire = 0;
/** The interval between our players shot (ms) */
private long firingInterval = 400;
/** timer */
private long time = 0;
/** The number of aliens left on the screen */
private int alienCount;
/** The message to display which waiting for a key press */
private String message = "";
/** True if we're holding up game play until a key has been pressed */
private boolean waitingForKeyPress = true;
/** True if the left cursor key is currently pressed */
private boolean leftPressed = false;
/** True if the right cursor key is currently pressed */
private boolean rightPressed = false;
/** True if we are firing */
private boolean firePressed = false;
/** True if game logic needs to be applied this loop, normally as a result of a game event */
private boolean logicRequiredThisLoop = false;
private static Image drop;
/** The constant for the width*/
private int DOMAIN = 800;
/** The constant fot the length*/
private int RANGE = 950;
/** The constant for the number of rows of aliens */
private int numbaofrows = 8;
/** The constant for the number of aliens per row */
private int aliensperrow = 12;
/** The constant for the percent of which the speed increases*/
private double speedincrease = 1.02;
/** Starts the variable that counts the shots*/
private int shotsfired = 0;
/** Construct our game and set it running.*/
public Main() {
// Creates a frame to contain Main.
JFrame container = new JFrame("SPACE INVADERS !!! WOOT !!! WOOT !!!");
// Gets a hold of the content of the frame and sets up the resolution of the game
// Names the inside of the "container" as panel.
JPanel panel = (JPanel) container.getContentPane();
// Stes the demensions of the panel.
panel.setPreferredSize(new Dimension(DOMAIN,RANGE));
//Sets the layout as nothing which overrides any automatic properties.
panel.setLayout(null);
// Sets up our canvas size and puts it into the content of the frame
setBounds(0, 0, DOMAIN, RANGE);
panel.add(this);
// Tell AWT not to bother repainting our canvas since we're
// going to do that our self in accelerated mode.
setIgnoreRepaint(true);
// Actually sizes the window approximately.
container.pack();
// Makes it so that the window can't be resized.
container.setResizable(false);
// Makes the window visible.
container.setVisible(true);
// Add a listener to respond to the user pressing the x.
// End the program when the window is closed.
container.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
// add a key input system (defined below) to our canvas
// so we can respond to key pressed
addKeyListener(new KeyInputHandler());
// request the focus so key events come to us
requestFocus();
// Create the buffering strategy which will allow AWT
// to manage our accelerated graphics.
createBufferStrategy(2);
strategy = getBufferStrategy();
// initialise the entities in our game so there's something
// to see at startup
initEntities();
time = System.currentTimeMillis();
* Start a fresh game, this should clear out any old data and
* create a new set.
private void startGame() {
// clear out any existing entities and intialise a new set
entities.clear();
initEntities();
// blank out any keyboard settings we might currently have
leftPressed = false;
rightPressed = false;
firePressed = false;
* Initialise the starting state of the entities (ship and aliens). Each
* entitiy will be added to the overall list of entities in the game.
private void initEntities() {
ClassLoader cloader = Main.class.getClassLoader();
drop = Toolkit.getDefaultToolkit().getImage(cloader.getResource("drop.gif"));
prepareImage(drop, this);
// create the player ship and place it in the center of the screen
ship = new ShipEntity(this,"background.gif", 0, (RANGE - 75));
entities.add(ship);
ship = new ShipEntity(this,"ship.gif", (DOMAIN / 2) - 0, (RANGE - 50));
entities.add(ship);
// create a block of aliens
alienCount = 0;
for (int row = 0; row < numbaofrows; row++) {
for (int x = 0; x < aliensperrow; x++) {
alien = new AlienEntity(this,"alien.gif", 100 + (x*50),(50)+row*30);
entities.add(alien);
alienCount++;
* Notification from a game entity that the logic of the game
* should be run at the next opportunity (normally as a result of some
* game event)
public void updateLogic() {
logicRequiredThisLoop = true;
* Remove an entity from the game. The entity removed will
* no longer move or be drawn.
* Remove the entity
public void removeEntity(Entity entity) {
removeList.add(entity);
/**Notify that the player has died.*/
public void notifyDeath() {
message = "Oh no! The aliens win, wanna try again?";
waitingForKeyPress = true;
/** Notification that the player has won since all the aliensare dead.*/
public void notifyWin() {
long time2;
time2 = (System.currentTimeMillis() - time) / 1000;
int acuracy = 1000*(aliensperrow*numbaofrows)/shotsfired;
message = "Congradulations! You win! Your time was: " + time2 + " seconds. Your acuracy was " + acuracy + "%.";
waitingForKeyPress = true;
/**Notification that an alien has been killed*/
public void notifyAlienKilled() {
// reduce the alient count, if there are none left, the player has won!
alienCount--;
if (alienCount == 0) {
notifyWin();
// if there are still some aliens left then they all need to get faster, so
// speed up all the existing aliens
for (int i = 0; i < entities.size(); i++) {
Entity entity = (Entity) entities.get(i);
if (entity instanceof AlienEntity) {
// speed up every time the aliens move down
entity.setHorizontalMovement(entity.getHorizontalMovement() * speedincrease);
/**Attempt to fire a shot from the player. Its called "try" since we must first
* check that the player can fire at this point, i.e. has he/she waited long
* enough between shots.*/
public void tryToFire() {
// check that we have been waiting long enough to fire
if (System.currentTimeMillis() - lastFire < firingInterval) {
return;
// if we waited long enough, create the shot entity, and record the time.
lastFire = System.currentTimeMillis();
ShotEntity shot = new ShotEntity(this, "bullet.gif", ship.getX() + 27, ship.getY() - 30);
entities.add(shot);
* The main game loop. This loop is running during all game
* play as is responsible for the following activities:
* - Working out the speed of the game loop to update moves
* - Moving the game entities
* - Drawing the screen contents (entities, text)
* - Updating game events
* - Checking Input
public void gameLoop() {
long lastLoopTime = System.currentTimeMillis();
// Keep looping around till the game ends.
while (gameRunning) {
// Work out how long its been since the last update, this
// will be used to calculate how far the entities should
// move this loop.
long delta = System.currentTimeMillis() - lastLoopTime;
lastLoopTime = System.currentTimeMillis();
// Get hold of a graphics context for the accelerated
// surface and black it out.
Graphics2D g = (Graphics2D) strategy.getDrawGraphics();
g.setColor(Color.black);
g.fillRect(0, 0, DOMAIN, RANGE);
// Cycle around asking for each entity to move itself.
if (!waitingForKeyPress) {
for (int i = 0; i < entities.size(); i++) {
Entity entity = (Entity) entities.get(i);
entity.move(delta);
// cycle round drawing all the entities we have in the game
for (int i = 0; i < entities.size(); i++) {
Entity entity = (Entity) entities.get(i);
entity.draw(g);
// brute force collisions, compare every entity against
// every other entity. If any of them collide notify
// both entities that the collision has occured
for (int p = 0; p < entities.size(); p++) {
for (int s = p + 1; s < entities.size(); s++) {
Entity me = (Entity) entities.get(p);
Entity him = (Entity) entities.get(s);
if (me.collidesWith(him)) {
me.collidedWith(him);
him.collidedWith(me);
// remove any entity that has been marked for clear up
entities.removeAll(removeList);
removeList.clear();
// if a game event has indicated that game logic should
// be resolved, cycle round every entity requesting that
// their personal logic should be considered.
if (logicRequiredThisLoop) {
for (int i = 0; i < entities.size(); i++) {
Entity entity = (Entity) entities.get(i);
entity.doLogic();
logicRequiredThisLoop = false;
// if we're waiting for an "any key" press then draw the
// current message
if (waitingForKeyPress) {
g.setColor(Color.green);
g.drawString(message,(DOMAIN-g.getFontMetrics().stringWidth(message)) / 2, 250);
g.drawString("TO PLAY, PRESS ANY KEY : )", (DOMAIN-g.getFontMetrics().stringWidth("TO PLAY, PRESS ANY KEY : )")) / 2, 40);
// Clear up the graphics.
g.dispose();
// Flip the buffer over.
strategy.show();
// resolve the movement of the ship. First assume the ship
// isn't moving. If either cursor key is pressed then
// update the movement appropraitely
ship.setHorizontalMovement(0);
if ((leftPressed) && (!rightPressed)) {
ship.setHorizontalMovement(-moveSpeed);
} else if ((rightPressed) && (!leftPressed)) {
ship.setHorizontalMovement(moveSpeed);
// if we're pressing fire, attempt to fire
if (firePressed) {
shotsfired++;
tryToFire();
// finally pause for a bit. Note: this should run us at about
// 100 fps but on windows this might vary each loop due to
// a bad implementation of timer
try { Thread.sleep(10); } catch (Exception e) {}
* A class to handle keyboard input from the user. The class
* handles both dynamic input during game play, i.e. left/right
* and shoot, and more static type input (i.e. press any key to
* continue)
* This has been implemented as an inner class more through
* habbit then anything else. Its perfectly normal to implement
* this as seperate class if slight less convienient.
private class KeyInputHandler extends KeyAdapter {
/** The number of key presses we've had while waiting for an "any key" press */
private int pressCount = 1;
* Notification from AWT that a key has been pressed. Note that
* a key being pressed is equal to being pushed down but NOT
* released. Thats where keyTyped() comes in.
* @param e The details of the key that was pressed
public void keyPressed(KeyEvent e) {
// if we're waiting for an "any key" typed then we don't
// want to do anything with just a "press"
if (waitingForKeyPress) {
return;
if (e.getKeyCode() == KeyEvent.VK_LEFT) {
leftPressed = true;
if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
rightPressed = true;
if (e.getKeyCode() == KeyEvent.VK_SPACE) {
firePressed = true;
* Notification from AWT that a key has been released.
* @param e The details of the key that was released
public void keyReleased(KeyEvent e) {
// if we're waiting for an "any key" typed then we don't
// want to do anything with just a "released"
if (waitingForKeyPress) {
return;
if (e.getKeyCode() == KeyEvent.VK_LEFT) {
leftPressed = false;
if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
rightPressed = false;
if (e.getKeyCode() == KeyEvent.VK_SPACE) {
firePressed = false;
* Notification from AWT that a key has been typed. Note that
* typing a key means to both press and then release it.
* @param e The details of the key that was typed.
public void keyTyped(KeyEvent e) {
// if we're waiting for a "any key" type then
// check if we've recieved any recently. We may
// have had a keyType() event from the user releasing
// the shoot or move keys, hence the use of the "pressCount"
// counter.
if (waitingForKeyPress) {
if (pressCount == 1) {
// since we've now recieved our key typed
// event we can mark it as such and start
// our new game
waitingForKeyPress = false;
startGame();
pressCount = 0;
} else {
pressCount++;
// if we hit escape, then quit the game
if (e.getKeyChar() == 27) {
System.exit(0);
* The entry point into the game. We'll simply create an
* instance of class which will start the display and game
* loop.
* @param argv The arguments that are passed into our game
public static void main(String argv[]) {
Main g = new Main();
// Starts the main game loop, this method will not return until the game has finished running. Hence we are
// using the actual main thread to run the game.
g.gameLoop();
}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Ap_Compsci_student_13 wrote:
ok sorry but doesn't sscce say to post the whole code?the first S is Short, and yes, it needs to be all the code needed to illustrate the problem and let use reproduce it. If you were developing a new Web framework, your example might be short, but for a student game it's very long.

Similar Messages

  • Need help understanding placement of images and text

    I am a beginner with contribute and as such contributing to
    our website with text and images. I may be missing something, but
    am having a frustrating time of including and arranging images on a
    page. It appears that the "drag and drop" capability is very
    limited. I am having to use spacebar, enter key, image alignment,
    resizing, and padding to arrange pictures. Production is at a
    crawl..need quidance quick!
    The following link is to our website...I am attempting to
    create a gallery of projects with each project having its own page
    of text and images. A temporary link to them is found at the bottom
    of Services page. I appreciate a pointing in the right direction.
    http://www.watsoncommercialgc.com/ProjectGalleryIndex.htm

    Glad that worked out fine.
    Dreamweaver is a development tool with lots of possibility.
    But purchasing this is an investment of course. But adding
    galleries and stuf like that will be easier to accomplish.
    Alternative is to open the page souirce of Contribute pages in an
    external app. and dive into the source and adjust that tom your
    needs.
    You can allways download a trial of Dreamweaver an try it
    out.

  • Need help moving my cs5 illustrator and photoshop to my new computer

    I need help installing my cs5 illustrator and photoshop on my new computer

    I have a macbook air...not sure what operating system....
    Kelsey West
    Kelsey West Designs
    [email protected]
    818.631.0172
    [image:
    http://www.hmcatering.com/wp-content/uploads/2013/03/AsSeenOnSMP_Blue.png][image:
    http://tobinphotography.com/wp-content/uploads/2013/02/Style_me_pretty_blog_badge.png]

  • Need help with my iPhone 5 and my Macbook Pro.

    Need help with my iPhone 5 and my Macbook Pro.  I was purchased some music on itunes at my mac. Some reason I deleted those music from both on Mac and iPhone 5.  Today, I went to my iPhone iTunes store inside of iCloud to redownload my puchased. But those song won't able to sync back to my iTunes library on my Mac.  Can anyone help me with that ??....
    iPhone 5, iOS 6.0.1

    You've posted to the iTunes Match forum, which your question does not appear to be related to. You'll get better support responses by posting to either the iTunes for Mac or iTunes for Windows forum. Which ever is more appropriate for your situation.

  • TS4268 I need help getting my face time and imessage to work.

    I need help getting my face time and imessage to work. It is saying wating for activation. I just got my iphone 5 2 days ago. I have reset it from the phone and from itunes on the computer, made sure I'm attached to wifi.

    The 3 basic troubleshooting steps are these in order: 1. Restart your iphone  2.  Reset your settings/iphone  3.  Restore your iphone.  Since your iphone is only a couple of days old, you should backup your device before restoring.  If you don't have anything on your iphone that you care to lose, then simply restoring without a backup is fine.  A quick reset of pressing the sleep/wake button (top of iphone) and your home button simultaneously and holding it until the silver Apple logo appears. 

  • I need to submit 2 photos  Image and resolution

    I need to submit 2 photos
    Image and resolution & size : 4" x  6" @ 300 dpi  ( how do I do this from iphoto)
    Is there a way to upload these so you both can see them and then we can pick out 2 from 354 pictures
    I have to complete by May 4th

    300 dpi is 300 Dots Per Inch
    So by simple math  4x6" at 300 dpi is 1200 pixels by 1800 pixels
    To do this in iPhoto your photo must be that size or larger. Crop to 4x6 and export with a custom size with the maximum dimension being 1800 pixels.
    LN

  • My old laptop crashed and I need to restore my iTunes music and movies to my new laptop from my iPod Touch. Help please. Thanks!

    My old laptop crashed and I need to restore my iTunes music and movies to my new laptop from my iPod Touch. Help please. Thanks!

    See:
    Syncing to a "New" Computer or replacing a "crashed" Hard Drive: Apple Support Communities

  • I am john and I need help downloading a progmmme yesterday and wanted to finish downloading open it and I am not told me that the program was shut down unexpectedly and restart ponia not opened and went back to download it and not opened my back probe to

    i am john and I need help downloading a progmmme yesterday and wanted to finish downloading open it and I am not told me that the program was shut down unexpectedly and restart ponia not opened and went back to download it and not opened my back probe to turn off the computer and there was no case

    i am john and I need your help yesterday bought a program called DJAY when I finish the download and got an error opened and I saw him there was no case to install and thank you for your help anyway

  • I need help i lost my ipod and found it but someone elses id is on it i trtied resoring it but i still cant go in it help

    i need help i lost my ipod and found it but someone elses id is on it i trtied resoring it but i still cant go in it help

    See this -> Find My iPhone Activation Lock: Removing a device from a previous owner’s account

  • I need help integrating Microsoft Office, Outlook and Calendar with my job and is it possible

    Ok guys I am new to the iphone 4s. I just dumped my Blackberry after 10 years. I need help integrating Microsoft Office, Outlook and Calendar with my job and is it possible? Also I need it to automatically push email and appointments to my phone? I will buy any app just need to know which is best for work environment. Here is what I am thinking about doing. http://www.groovypost.com/howto/apple/sync-iphone-or-ipod-touch-calendar-and-con tacts-with-google/ Is this the best way? For personal use I am using paid G whiz app

    I use Google Calendar Sync to sync my work Outlook calendar to a gmail account, then sync that to my iPhone.  It works well for me for the past couple of years.
    As far as mail itself, just ask your it folks for settings for remote access to your exchange account, and then set it up on the phone.
    As far as working with Office docs, to be able to actually edit them and such, look in the app store for DocsToGo or QuickOffice - they both are good but each has it's pros and cons, so on balance it's down to mere preference i think.

  • TS1646 I'v tried many times to update my applications however, my account can't do it because security code for my card is incorrect note that I'm sure my card details are correct completely so i need help to fix it as much as you can plz. Thnks

    Hi
    I'v tried many times to update my applications however, my account can't do it because security code for my card is incorrect note that I'm sure my card details are correct completely so i need help to fix it as much as you can plz. Thnks

    Look, I understand I still need a card attached to the account. The problem is, it won't accept my card because I only have 87 cents in my bank account right now.
    If I had known there would be so much trouble with the iTunes card, I would have just put the cash in my bank account in the morning instead of buying an iTunes card (I didn't expect the banks to be open on Thanksgiving of course).
    Apple will only accept cards that have a balance. The balance is so small in my account that it won't accept it as a valid card.
    I'm going to have to contact Apple anyway to reset the security questions. That's obvious. Your answers were not exactly helpful. You didn't tell me anything I don't already know, but thanks for trying to be helpful.

  • How can I save the images and movies on a  external Disk from iphoto program, to protect the images when problems occur in the laptop,

    How can I save the images and movies on a  external Disk from iphoto program, to protect the images when problems occur in the laptop,

    Most Simple Back Up:
    Drag the iPhoto Library from your Pictures Folder to another Disk. This will make a copy on that disk.
    Slightly more complex: Use an app that will do incremental back ups. This is a very good way to work. The first time you run the back up the app will make a complete copy of the Library. Thereafter it will update the back up with the changes you have made. That makes subsequent back ups much faster. Many of these apps also have scheduling capabilities: So set it up and it will do the back up automatically.
    Example of such apps: Chronosync - but there are many others. Search on MacUpdate or the App Store
    If you want to back up the Photos only:
    Export them using the File -> Export command.
    This User Tip
    https://discussions.apple.com/docs/DOC-4921
    has details of the options in the Export dialogue.

  • Need Help to Draw and Drag Triangle - URGENT

    Hi everyone - I am developing various proofs of the pythagora's theorem
    and the following code draws a triangle on screen and the proof follows -
    but i need to know how to drag the triangle such tht 1 angle is always set to 90 degrees.
    i.e. i need to resize the triangle by dragging its vertex points by which the1 angle remains at 90 no matter what the size.
    The proof has got some graphics code hardcoded in it - i.e. LINES AND POLYGONS have been hardcoded
    i need to reconfigure that such that everytime the user increases the size of the triagnle and clicks on next it draws the lines and polygons in the correct area and place
    PLEASE HELP
    the code is as follows
    MAIN CLASS
    import java.awt.BorderLayout;
    import java.awt.Container;
    import java.awt.*;
    import java.awt.event.*;
    import java.text.*;
    import javax.swing.*;
    public class TestProof {
        TestControl control;          // the controls for the visual proof
        TestView view;          // the drawing area to display proof
        // called upon class creation
        public TestProof() {
            view = new TestView();
    view.setBackground(Color.WHITE);
            control = new TestControl(view);
            Frame f = new Frame("Pythagoras");
            f.add(view,"Center");
            f.add(control,"South");
            f.setSize(600,600);
            f.setBackground(Color.lightGray);
            f.addMouseMotionListener(
            new MouseMotionListener() { //anonymous inner class
                //handle mouse drag event
                public void mouseMoved(MouseEvent e) {
                    System.out.println("Mouse  " + e.getX() +","  + e.getY());
                public void mouseDragged(MouseEvent e) {
                    System.out.println("Draggg: x=" + e.getX() + "; y=" + e.getY());
            JMenu File = new JMenu("File");
            JMenuItem Exit = new JMenuItem("Exit");
            Exit.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    ExitActionPerformed(evt);
            JMenuBar menuBar = new JMenuBar();
            menuBar.add(File);
       File.add(Exit);
            f.add(menuBar,"North");
            f.show();
        private JMenuBar getMenuBar() {
            JMenu File = new JMenu("File");
            JMenuItem Exit = new JMenuItem("Exit");
            Exit.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    ExitActionPerformed(evt);
            JMenuBar menuBar = new JMenuBar();
            menuBar.add(File);
                 File.add(Exit);   
            return menuBar;
        private void ExitActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
            System.exit(0);
        // for standalone use
        public static void main(String args[]) {
      TestProof TP = new TestProof();
    }Test VIEW
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.text.*;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class TestView extends Canvas {
        int TRANSLUCENT = 1;
        int sequence;          // sequencer that determines what should be drawn
        // notes matter
        int noteX = 100;     // note coordinates
        int noteY = 60;
        int fontSize = 11;     // font size
        int lineSpacing     // space between two consecutive lines
        = fontSize + 2;
        Font noteFaceFont;     // font used to display notes
        // objects matter
        Polygon tri;          // right-angled triangle with sides A, B, and C
        Polygon tri1;
        Polygon sqrA;          // square with side of length A
        Polygon sqrB;          // square with side of length B
        Polygon sqrC;          // square with side of length C
        Polygon parA;          // parallelogram of base A and height A
        Polygon parB;          // parallelogram of base B and height B
        Polygon poly1;
        Polygon poly2;
        Polygon poly3;
        Polygon poly4;
        Polygon poly5;
        Polygon poly6;
        int X0 = 350;          // coordinates of triangle
        int Y0 = 350;
        int A = 90;//60;          // triangle size
        int B = 120;//80;
        int C = 150;//100;
        //CORDS of 2nd triangle
        int X1 = 350;
        int Y1 = 500;
        // notes: three lines per note
        String notes[] = {
            // note 0
            // note 1
            // note 2
            // note 3
            // note 4
            // note 5
            // note 6
            // note 7
            // note 8
            // note 9
            // note 10
            // note 11
            // note 12
            // note 13
            // note 14
        // constructor
        public TestView() {
            addMouseMotionListener(
            new MouseMotionListener() { //anonymous inner class
                //handle mouse drag event
                public void mouseMoved(MouseEvent e) {
                    System.out.println("Mouse  " + e.getX() +","  + e.getY());
                public void mouseDragged(MouseEvent e) {
                    System.out.println("Draggg: x=" + e.getX() + "; y=" + e.getY());
            // set font
            noteFaceFont = new Font("TimesRoman", Font.PLAIN, fontSize);
            // (coordinates specified w.r.t. to P0, unless otherwise specified)
            // create the triangle
            tri = new Polygon();
            tri.addPoint(0, 0);                    // add P0 coordinate
            tri.addPoint(A*A/C, -A*B/C);          // add A3 coordinate
            tri.addPoint(C, 0);                    // add C1 coordinate
            tri.translate(X0, Y0);               // place triangle
            tri1 = new Polygon();
            tri1.addPoint(0,0);                    // add P0 coordinate
            tri1.addPoint(A*A/C +38, +A*B/C);          // add A3 coordinate
            tri1.addPoint(C, 0);                    // add C1 coordinate
            tri1.translate(X1, Y1);
            // create square of side A
            sqrA = new Polygon();
            sqrA.addPoint(0, 0);               // add P0 coordinate
            sqrA.addPoint(-A*B/C, -A*A/C);          // add A1 coordinate
            sqrA.addPoint(-A*(B-A)/C, -A*(A+B)/C);     // add A2 coordinate
            sqrA.addPoint(A*A/C, -A*B/C);          // add A3 coordinate
            sqrA.translate(X0, Y0);               // place square
            // create square of side B
            // warning: the coordinate of this object are specified relative to C1
            sqrB = new Polygon();
            sqrB.addPoint(0, 0);               // add C1 coordinate
            sqrB.addPoint(B*A/C, -B*B/C);          // add B1 coordinate
            sqrB.addPoint(B*(A-B)/C, -B*(A+B)/C);     // add B2 coordinate
            sqrB.addPoint(-B*B/C, -B*A/C);          // add A3 coordinate
            sqrB.translate(X0 + C, Y0);               // place square
            // create square of side C
            sqrC = new Polygon();
            sqrC.addPoint(0, 0);               // add P0 coordinate
            sqrC.addPoint(C, 0);               // add C1 coordinate
            sqrC.addPoint(C, C);               // add C2 coordinate
            sqrC.addPoint(0, C);               // add C3 coordinate
            sqrC.translate(X0, Y0);               // place square
            poly1 = new Polygon();
            poly1.addPoint(405,279);
            poly1.addPoint(413,350);
            poly1.addPoint(432,500);
            poly1.addPoint(442,571);
            poly1.addPoint(500,500);
            poly1.addPoint(500,350);
            poly2 = new Polygon();
            poly2.addPoint(279,297);
            poly2.addPoint(404,280);
            poly2.addPoint(571,254);
            poly2.addPoint(500,350);
            poly2.addPoint(350,350);
            //Polygon 3
            poly3 = new Polygon();
            poly3.addPoint(404,280);
            poly3.addPoint(350,350);
            poly3.addPoint(414,350);
            poly4 = new Polygon();
            poly4.addPoint(350,350);
            poly4.addPoint(350,500);
            poly4.addPoint(442,572);
            poly4.addPoint(433,500);
            poly4.addPoint(414,350);
            poly5 = new Polygon();
            poly5.addPoint(476,183);
            poly5.addPoint(332,225);
            poly5.addPoint(278,295);
            poly5.addPoint(404,279);
            poly5.addPoint(571,254);
            poly6= new Polygon();
            poly6.addPoint(405,278);
            poly6.addPoint(332,224);
            poly6.addPoint(476,182);
            // create parallelogram of height A
            parA = new Polygon();
            parA.addPoint(0, 0);               // add P0 coordinate
            parA.addPoint(0, C);               // add C3 coordinate
            parA.addPoint(A*A/C, C - A*B/C);          // add Q0 coordinate
            parA.addPoint(A*A/C, -A*B/C);          // add A3 coordinate
            parA.translate(X0,Y0);               // place parallelogram
            // create parallelogram of height B
            // warning: the coordinate of this object are specified from C1
            parB = new Polygon();
            parB.addPoint(0, 0);               // add C1 coordinate
            parB.addPoint(-B*B/C, -B*A/C);          // add A3 coordinate
            parB.addPoint(A*A/C - C, C - A*B/C);     // add Q0 coordinate
            parB.addPoint(0, C);               // add C2 coordinate
            parB.translate(X0 + C, Y0);
            // place parallelogram
        // depending on the sequence number we draw certain objects
        public void paint(Graphics gfx) {
            super.paint(gfx);
            Graphics2D g = (Graphics2D) gfx;
            g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
            // text first, then objects (and animation)
            // we always output some notes
            g.drawString(notes[3*sequence], noteX, noteY);
            g.drawString(notes[3*sequence + 1], noteX, noteY + lineSpacing);
            g.drawString(notes[3*sequence + 2], noteX, noteY + 2*lineSpacing);
            // the object are drawn in an order so that they are properly overlapped
            if(sequence == 13) {
                g.setColor(Color.green);
                g.fillPolygon(poly1);
                g.fillPolygon(poly2);
                g.fillPolygon(poly3);
                g.fillPolygon(poly4);
                g.fillPolygon(poly5);
                g.setColor(Color.RED);
                g.setColor(Color.GREEN);
                g.drawLine(413,351,433,499);
                g.setColor(Color.white);
                g.fillPolygon(tri);
                g.fillPolygon(tri1);
                g.fillPolygon(poly6);
            if(sequence == 12 ) {
                g.setColor(Color.green);
                g.fillPolygon(poly1);
                g.fillPolygon(poly2);
                g.fillPolygon(poly3);
                g.fillPolygon(poly4);
                g.fillPolygon(poly5);
                g.setColor(Color.BLACK);
            if(sequence == 11){
                g.setColor(Color.green);
                g.fillPolygon(poly1);
                g.fillPolygon(poly3);
                g.fillPolygon(poly4);
                g.setColor(Color.BLACK);
            if(sequence == 8 ){
                g.setColor(Color.green);
                g.fillPolygon(poly5);
                g.setColor(Color.MAGENTA);
                g.drawString("E",578,254);
                g.drawString("D",268,302);
                g.setColor(Color.black);
                g.drawArc(250,150,350,250,320,65);
            else if (sequence == 9 ){
                g.setColor(Color.green);
                g.fillPolygon(poly2);
                g.setColor(Color.MAGENTA);
                g.drawString("E",578,254);
                g.drawString("D",268,302);
                g.setColor(Color.black);
                g.drawArc(250,150,350,250,320,65);
            if( sequence == 10){
                g.setColor(Color.green);
                g.fillPolygon(poly2);
                g.fillPolygon(poly5);
                g.setColor(Color.black);
                g.setColor(Color.MAGENTA);
                g.drawString("E",578,254);
                g.drawString("D",268,302);
                g.setColor(Color.black);
                g.drawArc(250,150,350,250,320,65);
            if(sequence == 7){
                g.setColor(Color.green);
                g.fillPolygon(poly2);
                g.setColor(Color.MAGENTA);
                g.drawString("E",578,254);
                g.drawString("D",268,302);
                g.setColor(Color.black);
            if(sequence == 6){
                g.setColor(Color.yellow);
                g.fillPolygon(poly2);
                g.setColor(Color.green);
                g.fillPolygon(poly3);
                g.setColor(Color.blue);
                g.fillPolygon(poly4);
                g.setColor(Color.black);
                g.drawArc(250,175,350,275,300,65);
                //g.drawArc(250,150,350,250,320,65);
                g.drawLine( 606,309,599,299);
                g.drawLine(592,313, 599,299);
                g.drawString("+90 degrees",605,378);
            if (sequence == 5 ) {
                g.setColor(Color.yellow);
                g.fillPolygon(poly2);
                g.setColor(Color.black);
            if (sequence == 4) {
                g.setColor(Color.YELLOW);
                g.fillPolygon(poly1);
                g.setColor(Color.black);
                g.drawArc(319,310,250,195,89,-35);
                g.drawLine(499,319, 492,312);
                g.drawLine(499,319, 492,325);
                g.drawArc(200,180, 233,238,-120,-60);
                g.drawLine(200,298, 208,309);
                g.drawLine(200,298, 194,313);
                g.drawString("-90 degrees",227,347);
            if (sequence >= 3) {
                g.drawLine(404,279,442,572);
            // draw the squares
            if (sequence >= 2) {
                g.drawLine(278,296,572,254);
            // draw the squares
            if (sequence >= 1) {
                g.drawLine(333,224,476,182);
                g.drawPolygon(tri1);
            // always draw the triangle
            g.drawPolygon(tri);
            g.drawPolygon(sqrA);
            g.drawPolygon(sqrB);
            g.drawPolygon(sqrC);
            g.setColor(Color.MAGENTA);
            g.drawString("C", X0 + C/2 - fontSize/2, Y0 + lineSpacing);
            g.drawString("A",
            X0 + A*A/(2*C) - fontSize*A/B/2,
            Y0 - A*B/(2*C) - lineSpacing*A/B);
            g.drawString("B",
            X0 + C - B*B/(2*C) - fontSize*A/B/2,// the last "-" isn't log.
            Y0 - B*A/(2*C) - lineSpacing*A/B);
        public void redraw(int sequence) {
            this.sequence = sequence;
            repaint();
    }TEST CONTROL
    * TestControl.java
    * Created on 28 February 2005, 11:16
    import java.awt.*;
    import java.awt.event.*;
    import java.text.*;
    import javax.swing.JFrame;
    * @author  Kripa Bhojwani
    public class TestControl extends Panel implements ActionListener {
      TestView view;
      int sequence;                    // event sequence
      // constructor
      public TestControl(TestView view) {
        Button b = null;
        Label label = new Label("A^2 ");
        this.view = view;          // initialize drawble area
        sequence = 0;               // initialize sequence
        b = new Button("Prev");
        b.addActionListener(this);
        add(b);
        b = new Button("Next");
        b.addActionListener(this);
        add(b);
        add(label);
      // exported method
      public void actionPerformed(ActionEvent ev) {
        String label = ev.getActionCommand();
        if (label.equals("Prev")) {
          if (sequence >0) {
         --sequence;
        else {
          if (sequence < 15) {
         ++sequence;
        this.setEnabled(false);          // disable the controls
        view.redraw(sequence);
        this.setEnabled(true);          // enable the controls
    }Please help --- really need to sort this out...
    THANKS

    One of the problems you face is that it is hard to recognise which parts of your code are drawing the triangle. This is because you are writing code in a procedural way rather than an object oriented way.
    In object oriented code you would have a triangle object that could draw itself. You would create the triangle object by specifying its sizes and angles in some way. Then it should be easy to change the triangles sizes and angles and ask all the drawn objects to redraw themselves.

  • Need help with adding formatted text and images to Crystal Report?

    Here's my scenario:
    I have a customer statement that's generated as a crystal report and that has a placeholder for advertisement. The advertisement is mixture of formatted text and images. Until now we only had one advertisement that was always used on the report. The new requirement is that we would have a pool of hundreds of advertisements and would need to display one specific advertisement on the customer statement based on various marketing criteria. They key is that the advertisement content will be determined programmatically and cannot be hardcoded into the report. I'm using Crystal2008 with .net SDK.
    Here are the solutions I thought of, but I'm still rather lost and would appreciate your help/opinion.
    1) Pass HTML or RTF to the report
    Not really sure if this is possible and how to get it done. Also how would I pass in images? Would display formatting be reliable when exporting to PDF?
    2) Create each add as a subreport and append it programatically
    I actually have this working, but I only know how to append a new section to the end of the report and then load the subreport to the section. I have no other controll of the placement. Is there a way to dynamically load a subreport to a predefined section in the main report? How about adding a dummy subreport in the main report as a placeholder and then replacing it with a different subreport? How could I do this?
    3) Pass an Image to the report
    I would create each advertisement as an image and then would somehow add the image to the report. How would I load the image and control the placement? Could I somehow define a placeholder for the image in the main report-maybe a dummy image to be replaced?
    Thank you.

    Hello Pavel,
    I would got the third way.
    You can use dynamic images in your report.
    Just by changing the URL to the image the image can be changed.
    Please see the [Crystal Manual|http://help.sap.com/businessobject/product_guides/cr2008/en/xir3_cr_usergde_en.pdf] and search for images.
    or directly here
    [Setting a Dynamic Graphic Location Path on an Image Object|https://boc.sdn.sap.com/node/506]
    [Dynamic image and HTTP://|https://boc.sdn.sap.com/node/3646]
    [codesample for .NET|https://boc.sdn.sap.com/node/6000]
    Please also use
    [Crystal Reports 2008 SDK Documentation and Sample Code|https://boc.sdn.sap.com/developer/library/CR2008SDK]
    [Crystal Reports 2008 .NET SDK Tutorial Samples|https://boc.sdn.sap.com/node/6203]
    Hope this helps
    Falk

  • Need help using LabVIEW 7.1 and data socket to transfer images

    I need help transferring images across a company network using: LV 7.1, IMAQ 3.0 and a PCI 1407 image aquisition card. I am trying to use datasocket to transfer video image across a company network. I have attached sample vis. Thanks in advance for your help.
    I. Cyr
    Attachments:
    Vibration Chamber Vision_Cyr.llb ‏129 KB

    Hello –
    Something that you need to consider is the fact that when you are sending an image over Data Socket, it is not really the image what is being transferred but a pointer to the image. Please take a look into this Knowledgebase.
    Also, you might find this Example Program useful.
    Hope this helps.
    S Vences
    Applications Engineer
    National Instruments

Maybe you are looking for

  • AppleScript: Save as App Broke

    My script runs fine as a script but when I save as application and run it fails. It's a script that gets selected files of a folder and prints the folder list. When I was testing it as an application, I had the application itself selected in its own

  • Iphoe 3g power switch doesn't appear to work

    I have an older 3g.  The power switch doesn't seem to work, so I can't turn it off.  Nor can I re-boot it. Neither holding the power switch nor the home and power switches together seem to have any effect. Any ideas what to do next? Thanks

  • Proper Places to Install Applications

    Hi everyone again, It seems all I've been doing since I got the 2nd HD is asking questions. But here is another one. I'm planning to purchase Final Cut Studio, sometime in the near future (I hope) and as we all know at installation, it takes quite a

  • Captivate 4 - Issue viewing exported PDF in published file on LMS

    I'm working in Captivate 4 and have included a link to a PDF document on a particular screen. It works beautifully when I view the published file until I move the files into the LMS - at that point, the PDF won't launch. Here's what I've done and hop

  • Under Line problem

    In my report, I need to underline all fields to the end of each line. In [Sample Picture|http://www.inesc-macau.org.mo/people/sekevin/Sample.jpg], the left-hand-side is correct output, right-hand-side is actual output with problem. I have two problem