DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 15 of 43

Threaded View

  1. #1
    Join Date
    Apr 2005
    Posts
    20

    Cant get my balls to move

    I am trying to write an applet based on one of the moscow puzzles, basically i have to make a chute long in which will be housed 4 white balls and 4 black, the object of the puzzle is to manouver the black balls passed the whites and out of the chute there is a recess in one side of the chute which functions as a passing place.

    I have adapted the code i had used in an earlier project and managed to get all the components on screen but nowwhen i click on a ball and try to move it, it won't move...however it looks like the applet is trying to move the chute and everything else in it.

    here is what i have

    Thanks in advance for any help you guys can give me


    Code:
    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;
    
    public class RollThemOut extends Applet implements MouseListener, MouseMotionListener
    {
      private Point blkball1, blkball2, blkball3, blkball4,whtball1, whtball2, whtball3, whtball4, mouse;
      private int select;
    
    
    	public void init()
    	{
    	this.addMouseMotionListener(this);
    	this.addMouseListener(this);
    	select=0;
    	blkball1 = new Point(15,110);
    	blkball2 = new Point(60,110);
    	blkball3 = new Point(105,110);
    	blkball4 = new Point(150,110);
    	whtball1 = new Point(195,106);
    	whtball2 = new Point(250,106);
    	whtball3 = new Point(305,106);
    	whtball4 = new Point(360,106);
    	mouse = new Point();
    	}
    
    
    
    		public void paint(Graphics g)
    		{
    		drawBox(g);
    		g.setColor(Color.black);
    		g.fillOval(blkball1.x, blkball1.y, 45, 45);
    		g.fillOval(blkball2.x, blkball2.y, 45, 45);
    		g.fillOval(blkball3.x, blkball3.y, 45, 45);
    		g.fillOval(blkball4.x, blkball4.y, 45, 45);
    		g.drawOval(whtball1.x, whtball1.y, 55, 55);
    		g.drawOval(whtball2.x, whtball2.y, 55, 55);
    		g.drawOval(whtball3.x, whtball3.y, 55, 55);
    		g.drawOval(whtball4.x, whtball4.y, 55, 55);
    		}
    
    
    	public void mouseDragged(MouseEvent e)
    	{
    	if (select==1) blkball1 = mouse;
    	if (select==2) blkball2 = mouse;
    	if (select==3) blkball3 = mouse;
    	if (select==4) blkball4 = mouse;
    	if (select==5) whtball1 = mouse;
    	if (select==6) whtball2 = mouse;
    	if (select==7) whtball3 = mouse;
    	if (select==8) whtball4 = mouse;
    	repaint();
    	}	
    
    	public void mouseMoved(MouseEvent e){}
    	
    	public void mousePressed(MouseEvent e)
    	{
    	mouse = e.getPoint();
    	if (mouse.x > blkball1.x - 10 && mouse.x < blkball1.x + 10 && 
    		mouse.y > blkball1.y - 10 && mouse.y < blkball1.y + 10) select = 1; 
    
    	if (mouse.x > blkball2.x - 10 && mouse.x < blkball2.x + 10 && 
    		mouse.y > blkball2.y - 10 && mouse.y < blkball2.y + 10) select = 2;
    
    	if (mouse.x > blkball3.x - 10 && mouse.x < blkball3.x + 10 && 
    		mouse.y > blkball3.y - 10 && mouse.y < blkball3.y + 10) select = 3;
    
    	if (mouse.x > blkball4.x - 10 && mouse.x < blkball4.x + 10 && 
    		mouse.y > blkball4.y - 10 && mouse.y < blkball4.y + 10) select = 4;
    	
    	if (mouse.x > whtball1.x - 10 && mouse.x < whtball1.x + 10 && 
    		mouse.y > whtball1.y - 10 && mouse.y < whtball1.y + 10) select = 5;
    	
    	if (mouse.x > whtball2.x - 10 && mouse.x < whtball2.x + 10 && 
    		mouse.y > whtball2.y - 10 && mouse.y < whtball2.y + 10) select = 6;
    
    	if (mouse.x > whtball3.x - 10 && mouse.x < whtball3.x + 10 && 
    		mouse.y > whtball3.y - 10 && mouse.y < whtball3.y + 10) select = 7;
    
    	if (mouse.x > whtball4.x - 10 && mouse.x < whtball4.x + 10 && 
    		mouse.y > whtball4.y - 10 && mouse.y < whtball4.y + 10) select = 8;
    
    
    
    	}
    
    
    		public void mouseClicked(MouseEvent e){}
    		public void mouseReleased(MouseEvent e){}
    		public void mouseEntered(MouseEvent e){}
    		public void mouseExited(MouseEvent e){}
    
    public void drawBox(Graphics g)
    {
    
     g.setColor(Color.black);
     g.fillRect(10,100,685 ,68);
     g.fillOval(410, 55, 65, 65);
     g.fillRect(410, 85, 65, 25);
     g.fillRect(690, 107, 20, 55);
     
     g.setColor(Color.white);
     g.fillRect(15,105,675,58);
     g.fillOval(415, 60, 55, 55);
     g.fillRect(415, 90, 55, 20);
     g.fillRect(690, 112, 30, 45);
    
    }
    }
    Last edited by pwnedjoo; 04-14-2005 at 03:33 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links