Results 1 to 3 of 3
  1. #1
    Riz
    Riz is offline Member
    Join Date
    Sep 2009
    Posts
    1
    Rep Power
    0

    Default Creating a boundary line in java

    Hi guys hopefully someone can help me. I want to create a boundary line so that when my block image reaches the bottom of my JFrame it stops and stays on the bottom while another block descends like in tetris. here is my code so far i cant get it to work. I appreciate any help. Thanks in advance.
    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    
    public class BlockAnimation extends JPanel {
    
       
       Image image; // Declare a name for the Image object.
       Image image1;
       Image image2;
       Image image3;
       Timer pptimer; 
       Rectangle rect;
       int x = 30;
       int x1 = 50;
       int y;
       int y1;
    //   Rectangle rect;
       int bounds;
    
          public BlockAnimation() {
          super();
          // Load an image file into the Image object. This file has to be in the same folder
          image =  Toolkit.getDefaultToolkit().getImage("block_yellow.png");
          image1 = Toolkit.getDefaultToolkit().getImage("block_blue.png");
          image2 = Toolkit.getDefaultToolkit().getImage("block_green.png");
          image3 = Toolkit.getDefaultToolkit().getImage("block_red.png");
    	  pptimer = new Timer(100, new TimerAction());
    	  //rect = new Rectangle(0,0,200,500);
    	  pptimer.start();
    	  
        }
        
       public void setAnimation(boolean OnandOff) {
            if (OnandOff) {
                pptimer.start();  
            } else {
                pptimer.stop();  
            }
        }
        
            public void paintComponent(Graphics g) {
        	super.paintComponent(g);
        	// Draw our Image object.
        	//g.drawImage(image,30,30,30,30, this); 
           	  g.drawImage(image,x,y,this);
          //  g.drawImage(image1,x1,y1, this);
        	//g.drawImage(image2,x,y, this);
        	//g.drawImage(image3,x,y, this);
             
        }
        
       
         class TimerAction implements ActionListener {
           
            public void actionPerformed(ActionEvent e) {
            	
           
            	 if((y + x) == JFrame.HEIGHT)
                  bounds = true;
                  repaint();
    
            
             
            }
         }
      }//endclass

  2. #2
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    7

    Default

    How does the block move at all? I don't see where x and y ever change...

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

    Default

    Cross-posted here: New To Java - How to create a boundry line

    To the original poster, welcome to the forum, and I hope your question gets answered, but I do request that if you cross-post a question you provide links to the other cross-posts. Nobody likes duplicating work that's already been done. Thanks for your cooperation.

Similar Threads

  1. Replies: 9
    Last Post: 04-07-2009, 04:51 AM
  2. How to Draw line in Java
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-23-2008, 12:08 AM
  3. Java command line
    By agouzoul in forum New To Java
    Replies: 2
    Last Post: 04-02-2008, 01:12 PM
  4. java in cmd line :(
    By Joe2003 in forum New To Java
    Replies: 2
    Last Post: 02-01-2008, 09:51 AM
  5. Reading in data from file line by line
    By bluekswing in forum New To Java
    Replies: 1
    Last Post: 10-02-2007, 01:19 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
  •