Results 1 to 20 of 20
Like Tree2Likes
  • 1 Post By yellowledbet
  • 1 Post By pbrockway2

Thread: Need help!!

  1. #1
    Samir4021 is offline Member
    Join Date
    Dec 2011
    Posts
    16
    Rep Power
    0

    Default Need help!!

    So I have to create a java program that is the beginning of a small game. I am completely LOST and need help badly! I will do anything for someone who can write it for me? I know im here to learn but in class I got as far as learning JButton. Im confused how implements and all that work. I am still studying but it is a blur to me. And it is due tomorrow at 9am so it has to be done. I dont have paypal but i could ail you money or something. Please help me for my grade! Thanks for your help. Heres directions

    CSC 1301 Lab 10

    1) In this lab you will write the beginnings of a simple game. In particular
    you will write a program that can control the motion of a spaceship displayed on the screen. For the spaceship you may use the image ship.gif located on the webpage. Your ship should move across the screen without bouncing and should be controlled using a KeyListener.

    Need help!!-ship.gif

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,784
    Rep Power
    7

    Default Re: Need help!!

    Quote Originally Posted by Samir4021 View Post
    I will do anything for someone who can write it for me?
    That would be academic dishonesty. Please tell me who your teacher is so I can let them know.

  3. #3
    Samir4021 is offline Member
    Join Date
    Dec 2011
    Posts
    16
    Rep Power
    0

    Default Re: Need help!!

    So what am I supposed to do? I have no one to help me or i wouldnt be asking for help. My partner is completely useless and my teacher sucks.

  4. #4
    yellowledbet is offline Senior Member
    Join Date
    Feb 2011
    Location
    Georgia, USA
    Posts
    122
    Rep Power
    0

    Default Re: Need help!!

    I will do it for 1 Million Dollars
    Need help!!-evil-ceo.jpg
    sunde887 likes this.

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Need help!!

    Columbus State? How big are the classes?

    What I'm wondering is, how many people named Samir are enrolled in 1301. There's Samir Surani... I suppose I could email and ask...
    Dark likes this.

  6. #6
    Samir4021 is offline Member
    Join Date
    Dec 2011
    Posts
    16
    Rep Power
    0

    Default Re: Need help!!

    well ok. So i got what I could done. I have these 2 files but my rebound panel wont show the ship on my frame when executed. any help?

    PANEL
    Java Code:
    import javax.swing.*;
    import java.awt.*;
    public class Frame
    {
      public static void main(String args[])
      {
        ReboundPanel panel = new ReboundPanel();
        panel.setVisible(true);
      }
    }
    reboundpanel
    Java Code:
    //********************************************************************
    //  ReboundPanel.java       Java Foundations
    //
    //  Represents the primary panel for the Rebound program.
    //********************************************************************
    
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class ReboundPanel extends JFrame
    {
       private final int WIDTH = 600, HEIGHT = 600;
       private final int DELAY = 20, IMAGE_SIZE = 35;
    
       public ImageIcon image;
       private Timer timer;
       private int x, y, moveX, moveY;
    
       //-----------------------------------------------------------------
       //  Sets up the panel, including the timer for the animation.
       //-----------------------------------------------------------------
       public ReboundPanel()
       {
          timer = new Timer(DELAY, new ReboundListener());
    
          image = new ImageIcon ("ship.gif");
    
          x = 0;
          y = 40;
          moveX = moveY = 3;
    
          setPreferredSize (new Dimension(WIDTH, HEIGHT));
          setBackground (Color.black);
          timer.start();
       }
    
       //-----------------------------------------------------------------
       //  Draws the image in the current location.
       //-----------------------------------------------------------------
       public void paintComponent (Graphics page)
       {
          //super.paintComponent (page);
          image.paintIcon (this, page, x, y);
       }
    
       //*****************************************************************
       //  Represents the action listener for the timer.
       //*****************************************************************
       private class ReboundListener implements ActionListener
       {
          //--------------------------------------------------------------
          //  Updates the position of the image and possibly the direction
          //  of movement whenever the timer fires an action event.
          //--------------------------------------------------------------
          public void actionPerformed (ActionEvent event)
          {
             x += moveX;
             y += moveY;
    
      /*       if (x <= 0 || x >= WIDTH-IMAGE_SIZE)
                moveX = moveX * -1;
    
             if (y <= 0 || y >= HEIGHT-IMAGE_SIZE)
                moveY = moveY * -1;
       */
             x = x%(WIDTH-IMAGE_SIZE);
             y = y%(HEIGHT-IMAGE_SIZE);
             repaint();
          }
       }
    }
    Last edited by pbrockway2; 12-03-2011 at 12:17 AM. Reason: code tags corrected

  7. #7
    Samir4021 is offline Member
    Join Date
    Dec 2011
    Posts
    16
    Rep Power
    0

    Default Re: Need help!!

    Oh yes I am Samir Surani. Please dont tell my teacher he will murder me!

  8. #8
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default Re: Need help!!

    Then ask for help, not a hand out.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  9. #9
    Samir4021 is offline Member
    Join Date
    Dec 2011
    Posts
    16
    Rep Power
    0

    Default Re: Need help!!

    Ok so I am asking for help now. Can someone help me?

  10. #10
    dru36 is offline Member
    Join Date
    Nov 2011
    Location
    New Hampshire
    Posts
    29
    Rep Power
    0

    Default Re: Need help!!

    You know my professor once told me a story about a girl in a similar position to yours. She walked up to her professor and said "I'll do anything for an A in your class" he said to her, "Will you study?"

    Pretty much sums it up chief!

    After you posted your code you didn't say what type of help you needed. I've posted a few questions on these forums and you need to be very specific with the questions you ask so that people don't waste time trying to do everything for you.

  11. #11
    Rewry is offline Member
    Join Date
    Dec 2011
    Posts
    19
    Rep Power
    0

    Default Re: Need help!!

    I dont have much experience in programming games with Java, as I program games with another language. However, one key concept which even small games require is threading....(two sequences happening concurrently)

  12. #12
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default Re: Need help!!

    You attempted some code, but you didn't ask a question. What is happening in your code, what is not happening that should. Does it compile? What do you SPECIFICALLY need help with? Did you put it in an Short, Self Contained, Correct Example ? We are only humans here, well except for JosAH... (I think he's a martian!)
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  13. #13
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Need help!!

    I have corrected your "code" tags. Use square brackets rather than angle brackets: [code]...[/code].

    -----

    my rebound panel wont show the ship on my frame when executed
    If the panel doesn't show the ship, one thing to check is whether paintComponent() ever gets called.

    Java Code:
    public void paintComponent (Graphics page)
    {
        //super.paintComponent (page);
        System.out.println("paintComponent() called x=" + x + ",y=" + y);
        image.paintIcon (this, page, x, y);
    }
    -----

    Why did you make the rebound panel an instance of JFrame? The name suggests it might be a JPanel instance that is added to a frame.

    You might want to check your notes/textbook etc for examples of a frame's paintComponent() ever being overridden. If you can't find any, that might be a sign that a better setup would be:

    * Make frame (with possibly size, title and other framey things)
    * Make panel (to hold content)
    * Add panel to frame

    -----

    There are some basic Swing usages that are missing here: like the code used to display a frame, and how a program displaying a frame might possibly end. Again your textbook and notes will be a help in getting the basic structure of the program before you start adding ships and their behaviour.

  14. #14
    zFader is offline Member
    Join Date
    Dec 2011
    Posts
    5
    Rep Power
    0

    Default Re: Need help!!

    Well.. make your image, add it to your panel using the paint method, set it's x and y coordinates to variables x, y so that we could change them with the keyPressed method. You'll need a timer and a speed changer to go along with it.. but I don't know if I'm allowed to give it all away for you.

  15. #15
    Samir4021 is offline Member
    Join Date
    Dec 2011
    Posts
    16
    Rep Power
    0

    Default Re: Need help!!

    so adding the panel to the frame is implementing or extending? Gahh im so confused. My book is of no help. :(

    Everything I am writing in the frame shows up but nothing from my reboundpanel is showing up. Any reason why?

  16. #16
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Need help!!

    so adding the panel to the frame is implementing or extending?
    Neither. The rebound panel might extend JPanel, but adding it is just a case of calling the frame's add() method.

    nothing from my reboundpanel is showing up. Any reason why?
    Did you check whether paintComponent() was ever being called? (see #13) What happened?

  17. #17
    Samir4021 is offline Member
    Join Date
    Dec 2011
    Posts
    16
    Rep Power
    0

    Default Re: Need help!!

    I couldnt get the super.paintcomponent(page) it gave me an error when i uncommented out. Any reason why? Heres my new code I tried but I get everything except the ship image.

    frame.java:

    import javax.swing.*;
    import java.awt.*;

    public class Frame extends ReboundPanel
    {
    public static void main(String args[])
    {
    ReboundPanel panel = new ReboundPanel();
    panel.setVisible(true);
    panel.setSize(600,500);
    panel.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    panel.setTitle("Spaceship");

    }
    }

    reboundpanel:

    //************************************************** ******************
    // ReboundPanel.java Java Foundations
    //
    // Represents the primary panel for the Rebound program.
    //************************************************** ******************

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;

    public class ReboundPanel extends JFrame
    {
    private final int WIDTH = 600, HEIGHT = 600;
    private final int DELAY = 20, IMAGE_SIZE = 35;

    public ImageIcon image;
    private Timer timer;
    private int x, y, moveX, moveY;

    //-----------------------------------------------------------------
    // Sets up the panel, including the timer for the animation.
    //-----------------------------------------------------------------
    public ReboundPanel()
    {
    timer = new Timer(DELAY, new ReboundListener());

    image = new ImageIcon ("ship.gif");

    x = 0;
    y = 40;
    moveX = moveY = 3;

    setPreferredSize (new Dimension(WIDTH, HEIGHT));
    setBackground (Color.BLACK);
    timer.start();
    }

    //-----------------------------------------------------------------
    // Draws the image in the current location.
    //-----------------------------------------------------------------
    public void paintComponent (Graphics page)
    {
    //super.paintComponent (page);
    image.paintIcon (this, page, x, y);
    }

    //************************************************** ***************
    // Represents the action listener for the timer.
    //************************************************** ***************
    private class ReboundListener implements ActionListener
    {
    //--------------------------------------------------------------
    // Updates the position of the image and possibly the direction
    // of movement whenever the timer fires an action event.
    //--------------------------------------------------------------
    public void actionPerformed (ActionEvent event)
    {
    x += moveX;
    y += moveY;

    /* if (x <= 0 || x >= WIDTH-IMAGE_SIZE)
    moveX = moveX * -1;

    if (y <= 0 || y >= HEIGHT-IMAGE_SIZE)
    moveY = moveY * -1;
    */
    x = x%(WIDTH-IMAGE_SIZE);
    y = y%(HEIGHT-IMAGE_SIZE);
    repaint();
    }
    }
    }

  18. #18
    Samir4021 is offline Member
    Join Date
    Dec 2011
    Posts
    16
    Rep Power
    0

    Default Re: Need help!!

    frame.java

    Java Code:
    import javax.swing.*;
    import java.awt.*;
    
    public class Frame
    {
      public static void main(String[] args)
      {
        JFrame f = new JFrame("Spaceship");
        ReboundPanel s = new ReboundPanel();
        f.add(s);
        f.setVisible(true);
        f.setSize(600,500);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
      }
    }
    reboundpanel:

    Java Code:
    //********************************************************************
    //  ReboundPanel.java       Java Foundations
    //
    //  Represents the primary panel for the Rebound program.
    //********************************************************************
    
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class ReboundPanel extends JFrame
    {
       private final int WIDTH = 600, HEIGHT = 600;
       private final int DELAY = 20, IMAGE_SIZE = 35;
    
       private ImageIcon image;
       private Timer timer;
       private int x, y, moveX, moveY;
    
       //-----------------------------------------------------------------
       //  Sets up the panel, including the timer for the animation.
       //-----------------------------------------------------------------
       public ReboundPanel()
       {
          timer = new Timer(DELAY, new ReboundListener());
    
          image = new ImageIcon ("ship.gif");
    
          x = 0;
          y = 40;
          moveX = moveY = 3;
    
          setPreferredSize (new Dimension(WIDTH, HEIGHT));
          setBackground (Color.BLACK);
          timer.start();
       }
    
       //-----------------------------------------------------------------
       //  Draws the image in the current location.
       //-----------------------------------------------------------------
       public void paintComponent (Graphics page)
       {
          //super.paintComponent (page);
          image.paintIcon (this, page, x, y);
       }
    
       //*****************************************************************
       //  Represents the action listener for the timer.
       //*****************************************************************
       private class ReboundListener implements ActionListener
       {
          //--------------------------------------------------------------
          //  Updates the position of the image and possibly the direction
          //  of movement whenever the timer fires an action event.
          //--------------------------------------------------------------
          public void actionPerformed (ActionEvent event)
          {
             x += moveX;
             y += moveY;
    
      /*       if (x <= 0 || x >= WIDTH-IMAGE_SIZE)
                moveX = moveX * -1;
    
             if (y <= 0 || y >= HEIGHT-IMAGE_SIZE)
                moveY = moveY * -1;
       */
             x = x%(WIDTH-IMAGE_SIZE);
             y = y%(HEIGHT-IMAGE_SIZE);
             repaint();
          }
       }
    }
    So I am still confused with the super.paintcomponent? If i uncomment it, it gives me this error:
    Java Code:
    File: /Users/sami40211/Documents/DrJava/ReboundPanel.java  [line: 43]
    Error: /Users/sami40211/Documents/DrJava/ReboundPanel.java:43: cannot find symbol
    symbol  : method paintComponent(java.awt.Graphics)
    location: class javax.swing.JFrame
    if I comment it out, I get this error:
    Java Code:
    java.lang.IllegalArgumentException: adding a window to a container
    	at java.awt.Container.checkNotAWindow(Container.java:431)
    	at java.awt.Container.addImpl(Container.java:1039)
    	at java.awt.Container.add(Container.java:959)
    	at javax.swing.JFrame.addImpl(JFrame.java:540)
    	at java.awt.Container.add(Container.java:365)
    	at Frame.main(Frame.java:10)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:271)
    Help please? THanks :)

  19. #19
    Samir4021 is offline Member
    Join Date
    Dec 2011
    Posts
    16
    Rep Power
    0

    Default Re: Need help!!

    and..... noone?

  20. #20
    Samir4021 is offline Member
    Join Date
    Dec 2011
    Posts
    16
    Rep Power
    0

    Default Re: Need help!!

    Nevermind so I figured it out and I see the ship moving. ANy idea on how to control the ship using my arrow keys?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •