123 Eng

Engineering the engineers™


Latest Jobs   Forum Map

 


Home
Source Codes
Engineering Colleges

Training  Reports
Seminar Reports
Placement Papers

Forums

   Computer Science / IT
   Electronics
   Electrical
   Mechanical
   Chemical
   Civil

   CAT / MBA

   GMAT / Foreign MBA
Latest Jobs

Engineering Jobs / Technical Jobs
Management Jobs

Sitemap
Terms of use

Displaying  Source Code(s)  
 

 
Moving Ball Application Using Java Beans

--------------------------------------------------------------------------------

Description : Not Specified

//MovingBall.java//

package sunw.demo.Ball;
import java.awt.*;
import java.awt.event.*;

public class MovingBall extends Canvas {
private Color cl;
private boolean rect;
private int top;
private int left;

public MovingBall() {
addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent me) {
change();
}
});
}

public boolean getRectangular() {
return rect;
}

public void setRectangular(boolean flag) {
rect = flag;
repaint();
}

public void moveUp() {
top-=10;
repaint();
}

public void moveDown() {
top+=10;
repaint();
}

public void moveLeft() {
left+=10;
repaint();
}

public void moveRight() {
left-=10;
repaint();
}

public void change() {
cl = randomColor();
repaint();
}

public Color randomColor() {
int r = (int) (255*Math.random());
int g = (int) (255*Math.random());
int b = (int) (255*Math.random());
return new Color(r,g,b);
}

public void paint(Graphics g) {
Dimension d=getSize();
int h=d.height;
int w=d.width;
/* if (top<0 )
top=h;
if (top>=h)
top=0;

if (left<0)
left=w;
if (left>=w)
left=0;
*/
g.setColor(cl);
g.fillOval(top,left,50,50);
}
 

 

Contribute content or training reports / feedback / Comments
job placement papers
All rights reserved © copyright 123ENG