You are here:

Java/Java assignment help

Advertisement


Question
Hello,
Not looking for complete answers. Just help. But I am completely stumped. It's a miracle I've made it half way through the semester. I really don't know how to do any of these 3 questions.

Any help is appreciated. Thanks.

Here is the code we are given:
https://gist.github.com/anonymous/2c363e6715db2cab4cb9


Here were the instructions:
"The Reset button does nothing currently in the program. Implement additional code so that when the Reset button is clicked, the game level is reset back to the initial level, and the
number of hits and misses is reset to zero.

2.
In the current program the Duke does not move when the mouse is dragged while the button is being held down. Modify the program so that the Duke would move as the mouse is
dragged also, in the same way as when the mouse is moved.

3.
Currently when the Duke is caught, a different Duke image with a waving hand is shown. There is no change to the image for a miss
Modify the program so that when a missoccurs a new Duke image
with hands down is displayed
Once the Duke moves to a new location, the image should return to the original as done
currently in the program
. "

Answer
For 1, you need to add an action listener to the button like:

reset.addActionListener(new ActionListener() {
  @Override
  public void actionPerformed(ActionEvent e) {
     //code here
  }
});

For 2, just implement the mouseDragged method.

For 3, you need a variable to track if duke is waving or not. Set it true when duke is hit, set false when duke moves. Then when you paint duke (in the paint method) use an if statement to decide what image to paint.

Java

All Answers


Answers by Expert:


Ask Experts

Volunteer


Artemus Harper

Expertise

I have a Masters in computer science. I can answer questions on core J2SE, swing and graphics. Please no questions about JSP or J2ME.

Experience

I have experience in Core Java, good background in Java swing/gui, some experience with JNI, Java reflection. Some experience in bio-informatics. Basics in c++ and c#

Organizations
Washington State University

Education/Credentials
MS in Computer Science from Washington State University and a BS in Mathematics and Computer Science from Central Washington University.

©2016 About.com. All rights reserved.