Hey there I am new to this game. I have to create a ball puzzle to display in a webpage it consists of a tube and 8 balls 4 black and 4 white the white balls are slightly larger than the black balls I need to be able to manipulate them to get the black balls out of the tube. I can draw them but need to get this into an array Can anyone help please?
smudge 0 Newbie Poster
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Balls extends Applet implements MouseListener,MouseMotionListener {
private Point bBall1,bBall2,bBall3,bBall4,wBall5,wBall6,wBall7,wBall8, mouse;
private int select;
public void init() {
this.addMouseMotionListener(this);
this.addMouseListener(this);
select = 0;
bBall1 = new Point(20,65);
bBall2 = new Point(50,65);
bBall3 = new Point(80,65);
bBall4 = new Point(110,65);
wBall5 = new Point(300,55);
wBall6 = new Point(440,55);
wBall7 = new Point(500,55);
wBall8 = new Point(540,55);
mouse = new Point();
}
public void paint (Graphics g) {
drawTube(g);
}
public void mouseDragged(MouseEvent e) {
mouse = e.getPoint();
// continuously change the coordinates of the selected counter
if (select == 1) bBall1 = mouse;
if (select == 2) bBall2 = mouse;
if (select == 3) bBall3 = mouse;
if (select == 4) bBall4 = mouse;
if (select == 5) wBall5 = mouse;
if (select == 6) wBall6 = mouse;
if (select == 7) wBall7 = mouse;
if (select == 8) wBall8 = mouse;
repaint();
}
public void mouseMoved(MouseEvent e) {
}
// required for the interface
public void mousePressed(MouseEvent e) {
//select a counter using the mouse
mouse = e.getPoint();
if (mouse.x > bBall1.x - 5 && mouse.x < bBall1.x + 5 &&
mouse.y > bBall1.y - 5 && mouse.y < bBall1.y + 5) select = 1;
if (mouse.x > bBall2.x - 5 && mouse.x < bBall2.x + 5 &&
mouse.y > bBall2.y - 5 && mouse.y < bBall2.y + 5) select = 2;
if (mouse.x > bBall3.x - 5 && mouse.x < bBall3.x + 5 &&
mouse.y > bBall3.y - 5 && mouse.y < bBall3.y + 5) select = 3;
if (mouse.x > bBall4.x - 20 && mouse.x < bBall4.x + 20 &&
mouse.y > bBall4.y - 20 && mouse.y < bBall4.y + 20) select = 4;
if (mouse.x > wBall5.x - 35 && mouse.x < wBall5.x + 35 &&
mouse.y > wBall5.y - 35 && mouse.y < wBall5.y + 35) select = 5;
if (mouse.x > wBall6.x - 35 && mouse.x < wBall6.x + 35 &&
mouse.y > wBall6.y - 35 && mouse.y < wBall6.y + 35) select = 6;
if (mouse.x > wBall7.x - 35 && mouse.x < wBall7.x + 35 &&
mouse.y > wBall7.y - 35 && mouse.y < wBall7.y + 35) select = 7;
if (mouse.x > wBall8.x - 35 && mouse.x < wBall8.x + 35 &&
mouse.y > wBall8.y - 35 && mouse.y < wBall8.y + 35) select = 8;
}
// required for the interface
public void mouseClicked(MouseEvent event){
}
public void mouseReleased(MouseEvent event){
}
public void mouseEntered(MouseEvent event){
}
public void mouseExited(MouseEvent event){
}
public void drawTube(Graphics g)
{
super.paint(g);
g.drawLine(15,48,190,48);
g.drawLine(15,48,15,100);
g.drawArc(190,10,80,80,180,-180);
g.drawLine(270,48,400,48);
g.drawLine(15,100,400,100);
g.fillOval(bBall1.x,bBall1.y,20,20);
g.fillOval(bBall2.x,bBall2.y,20,20);
g.fillOval(bBall3.x,bBall3.y,20,20);
g.fillOval(bBall4.x,bBall4.y,20,20);
g.drawOval(wBall5.x,wBall5.y,35,35);
g.drawOval(wBall6.x,wBall6.y,35,35);
g.drawOval(wBall7.x,wBall7.y,35,35);
g.drawOval(wBall8.x,wBall8.y,35,35);
g.drawLine(400,100,400,85);
g.drawLine(400,48,400,65);
g.drawLine(400,65,420,65);
g.drawLine(400,85,420,85);
g.drawString("Hint:Start with the black balls",10,450);
}
}
//********************************************/
/*need to make tube longer */
/*Then re-do co-ordinates for the white balls */
/*********************************************/
- 1 Contributor
- 0 Replies
- 98 Views
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.