Results 1 to 3 of 3
  1. #1
    MonDo021 is offline Member
    Join Date
    Apr 2011
    Posts
    1
    Rep Power
    0

    Post how i could make this play ,please?!!

    Hi! i really need help please .. i am doing a program that kinda of a game .... i am tying to import some images that is make an animation game ....
    i am making a Snow man kick a ball trying to hit a tree ... when it came in the right place .... the tree vanishes ... and thats the code ... but there is no images displayed ... is it right when i put the pic. in the same package ?!
    and if u guyz help and that will be awesome .... i need a slope (a math method that i don't know how it could be :D) in this game to make the game depend on the slope .... "like rocket man if someone know it"

    that's the code ::::

    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package javaapplication17;
    
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.FlowLayout;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.io.File;
    import java.io.IOException;
    import javax.imageio.ImageIO;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    
    /**
     *
     * @author MonDo
     */
    class Main
    {
      public static void main( String[] args ) {
    
        JFrame frame = new JFrame( "Harbin Game" );
    
    
        frame.add(new HarbinComponent(),BorderLayout.CENTER);
    
        frame.setSize( 500, 500 );
    
       frame.setLocationRelativeTo(null);
    
        frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
    
       frame.setVisible( true );
    
         }
    // Inner Class: Displaying a String
    
      static class HarbinComponent extends JPanel  {
    
        private String message;
    
      Image tree;
    
      Image snowman;
    
    
          public HarbinComponent(){
    
           message="Welcome to Harbin!";
    
             try {
    
            tree = ImageIO.read(new File("harbin.jpg"));
    
           }
    catch (IOException e) {
          }
    
     try {
    
            snowman = ImageIO.read(new File("snowman.jpg"));
    
           }
     catch (IOException e) {
           }
    
    
            this.setLayout(new BorderLayout());
    
            JPanel p1=new JPanel(new FlowLayout());
    
    
            JTextField jtfTest= new JTextField("Enter the slope here");
    
         p1.add(jtfTest);
    
           JButton jbtTest= new JButton("Play");
    
            p1.add(jbtTest);
    
          JButton jbtTest1= new JButton("New Game");
    
          p1.add(jbtTest1);
    
    
           this.add(p1,BorderLayout.SOUTH);
    
        }
    
    
    
    
        public void paintComponent( Graphics g ) {
    
            super.paintComponent(g);
    
                 g.setColor(Color.WHITE);
    
                  g.fillRect(0, 0, this.getWidth(), this.getHeight());
    
                 g.drawImage(tree, 0, 0, this);
    
                    g.drawImage(snowman, 0, 580, this);
    
                    g.drawString( message, 10,330 );
    
    
    	  }
    
        }
    
    
    }

    and there is pic to understand more ... thanks alot for just reading , sorry abt long speech





    game explanation:

    first the ball roll over the black bar and falls in front of the snow man then it kicks the ball and hit the tree to be vanished ..

    and thx again
    Attached Thumbnails Attached Thumbnails how i could make this play ,please?!!-untitled.jpg  
    Last edited by Fubarable; 04-30-2011 at 02:56 PM. Reason: code tags added

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Moderation:
    • Code tags added so that posted code will retain its formatting and be readable
    • Moved from Applets forum to Swing forum as this question has nothing to do with applets.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    I suggest that you start simpler just to figure out each component. For instance, I would first try to create an Image, place it in an ImageIcon, place that in a JLabel and display the JLabel perhaps simply in a JOptionPane. If you get that to work, then work on the next step, perhaps multiple images in a GUI, and then only when that works, work on the animation.

    Also your random code indentation makes your code very hard to read and makes it less likely that folks will want to read it and offer you specific advice. So please fix your code indentation so that its uniform, usually 3-4 space indentation will do.

Similar Threads

  1. To play wav or mp3
    By jomla in forum Java Applets
    Replies: 2
    Last Post: 03-07-2011, 08:19 PM
  2. Come play gp latale
    By Blinger in forum Reviews / Advertising
    Replies: 0
    Last Post: 06-10-2010, 02:56 AM
  3. Play avi file in JMF
    By ramkumarm in forum AWT / Swing
    Replies: 0
    Last Post: 04-15-2009, 01:49 PM
  4. play() and mp3
    By willemjav in forum Advanced Java
    Replies: 3
    Last Post: 12-23-2007, 02:50 PM
  5. Make sound play in a java application
    By lenny in forum AWT / Swing
    Replies: 2
    Last Post: 08-13-2007, 11:45 AM

Posting Permissions

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