• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
projectsgeek

ProjectsGeek

Download Mini projects with Source Code, Java projects with Source Codes

  • Home
  • Java Projects
  • C++ Projects
  • VB Projects
  • PHP projects
  • .Net Projects
  • NodeJs Projects
  • Android Projects
    • Project Ideas
      • Final Year Project Ideas
      • JSP Projects
  • Assignment Codes
    • Fundamentals of Programming Language
    • Software Design Laboratory
    • Data Structure and Files Lab
    • Computer Graphics Lab
    • Object Oriented Programming Lab
    • Assembly Codes
  • School Projects
  • Forum

Moving Balls mini project using Java Applet

April 15, 2012 by ProjectsGeek 37 Comments

Moving Balls mini project using Java Applet

Write a program to develop a application in java applet which will show balls that will move across the screen .
In  Moving Balls using Java Applet project we have two balls moving perpendicular to each other . Also balls have some sort of animation which will change it’s color a regular intervals  . The code for this applet is simple and this code can be used as applet assignment in your academics . 

Sample code for Applet Animated Balls that will move regularly across the screen :
 import java.util.*;  
 import java.applet.*;  
 import java.awt.*;  
 import java.awt.event.*;  
 //Package Declarations   
 public class balls extends Applet implements Runnable  
 {  
 Random r = new Random(); // Random number generation for Different Colours   
 int x = 10, y = 10,sang1 = 0, sang2 = 0, he = 500 , wi = 500;  
 public void init()  
 {  
 Thread t = new Thread(this); // Thread creation for animation   
 t.start();  
 }  
 public void run()  
 {  
 while(true)  
 {  
 try  
 {  
 repaint();  
 Thread.sleep(100);   // Thread time interval set to 100 mil seconds   
 if( x < wi - 100)   // Playing with position of balls on the applet screen   
 x += 5;  
 if( y < he - 100)  
 y += 5;  
 if( x > wi - 100)  
 x = wi - 100;  
 if( y > he - 100)  
 y = he - 100;  
 sang1 += 10;  
 sang2 += 10;  
 }  
 catch(Exception e)  
 { }  
 }  
 }  
 public void paint(Graphics g)  
 {  
 Dimension d = getSize();  
 he = d.height;  
 wi = d.width;  
 g.setColor(new Color(r.nextInt(255),r.nextInt(255),r.nextInt(255))); // Balls random colors sets  
 g.fillArc(x,20,100,100,sang1,90);  
 g.setColor(new Color(r.nextInt(255),r.nextInt(255),r.nextInt(255)));  
 g.fillArc(x,20,100,100,sang1 + 90,90);  
 g.setColor(new Color(r.nextInt(255),r.nextInt(255),r.nextInt(255)));  
 g.fillArc(x,20,100,100,sang1 + 180,90);  
 g.setColor(new Color(r.nextInt(255),r.nextInt(255),r.nextInt(255)));  
 g.fillArc(x,20,100,100,sang1 + 270,90);  
 g.setColor(new Color(r.nextInt(255),r.nextInt(255),r.nextInt(255)));  
 g.fillArc(10, y, 100, 100, sang2 ,90);  
 g.setColor(new Color(r.nextInt(255),r.nextInt(255),r.nextInt(255)));  
 g.fillArc(10,y,100,100, sang2 + 90,90);  
 g.setColor(new Color(r.nextInt(255),r.nextInt(255),r.nextInt(255)));  
 g.fillArc(10,y,100,100,sang2 + 180,90);  
 g.setColor(new Color(r.nextInt(255),r.nextInt(255),r.nextInt(255)));  
 g.fillArc(10,y,100,100,sang2 + 270,90);  
 }  
 }

 

Now if you want to Change the speed of the Balls moving speed just change this Line …

repaint();  
Thread.sleep(100);

 

 

Increase limit of sleep parameter for say  Thread.sleep(400) to decrease speed or for increasing speed decrease parameter value .

To set the size of screen of applet just change values of    he and wi in Above Code .

Other Projects to Try:

  1. Developing Clock In java using Multi threading
  2. Communication between applet and servlet Java Code
  3. Design an applet that displays the string “Hello College Name” moving from left to right. When it reaches to right, it scrolls back to left.
  4. Java Game mini Project
  5. Feedback Collection System Mini Project in Java

Filed Under: Java Projects Tagged With: Java Projects

Reader Interactions

Comments

  1. Neha says

    January 28, 2015 at 10:28 am

    Even running this source code in netbean it need main class please solve my problem

    Reply
    • ProjectsGeek says

      March 8, 2015 at 3:12 pm

      I request you to please give us exact error. As we know this project works fine.

  2. pooja says

    December 16, 2014 at 8:36 am

    i want some information about this moving balls using java applet

    Reply
    • ProjectsGeek says

      January 3, 2015 at 1:29 pm

      Yes, Please do ask.

  3. navya says

    December 10, 2014 at 12:40 pm

    can we run this code in jdK 1.7

    Reply
    • ProjectsGeek says

      January 3, 2015 at 12:55 pm

      Yes, you can run this project in jdK 1.7.

  4. neethu kumari says

    December 9, 2014 at 9:07 am

    i want more information about this project ,disadvantages and advantages and uses of this project

    Reply
    • ProjectsGeek says

      January 3, 2015 at 1:15 pm

      You can write those things on your own after analysing the working project. Some advantages are:

      It requires browser to run as applet.
      It works on all platforms.

      and more

  5. Bobby says

    October 4, 2014 at 1:31 pm

    it requires a main method for it to run

    Reply
    • ProjectsGeek says

      October 5, 2014 at 4:39 am

      Run this Code as Applet.

« Older Comments
Newer Comments »

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Tags

.Net Projects Download Android Project Ideas Android Projects Angular 2 Assembly Codes C # Projects C & C++ Projects C++ Projects Class Diagrams Computer Graphics Database Project Data Mining Projects DataScience Projects Datastructure Assignments Download Visual Basic Projects Electronics project Hadoop Projects Installation Guides Internet of Things Project IOS Projects Java Java Interview Questions Java Projects JavaScript JavaScript Projects java tutorial JSON JSP Projects Mechanical Projects Mongodb Networking Projects Node JS Projects OS Problems php Projects Placement Papers Project Ideas Python Projects seminar and presentation Struts

Search this Website


Footer

Download Java Project
Download Visual Basic Projects
Download .Net Projects
Download VB Projects
Download C++ Projects
Download NodeJs Projects
Download School Projects
Download School Projects
Ask Questions - Forum
Latest Projects Ideas
Assembly Codes
Datastructure Assignments
Computer Graphics Lab
Operating system Lab
australia-and-India-flag
  • Home
  • About me
  • Contact Form
  • Submit Your Work
  • Site Map
  • Privacy Policy