25 February 2014

Arraigning Bricks In Our Game

Arrange-Bricks






import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class Bricks extends JPanel implements Runnable {

 // variables declaration for brick...............................
    //starting position of the bricks
 int brickx = 85;
 int bricky = 50;

 //You can specify length and breadth of the bricks here
 int brickBreadth = 50;
 int brickHeight = 40;
 // variables declaration for brick...............................
 // ===============================================================

 private static final String[] LEVELS_ONE = new String[] {
  "WWWWW",
  "W   W",
  "W W W",
  "W   W",
  "WWWWW"
  };
 private static final String[] LEVELS_TWO = new String[] {
  "WWWWW",
  "     ",
  "W W W",
  "     ",
  "WWWWW"
  };

 ArrayList<Rectangle> Brick = new ArrayList<Rectangle>();
 Thread t;

 Bricks() {

  setFocusable(true);
  t = new Thread(this);
  t.start();
 }

 public static void main(String[] args) {
  JFrame frame = new JFrame();
  Bricks game = new Bricks();
  JButton restart = new JButton("start");
  // JLabel lbl_startGame = new JLabel("Start Game", JLabel.LEFT);

  frame.setSize(350, 450);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  frame.add(game);

  frame.add(restart, BorderLayout.SOUTH);
  frame.setLocationRelativeTo(null);
  frame.setResizable(false);
  frame.setVisible(true);

 }

 public void paint(Graphics g) {
  g.setColor(Color.LIGHT_GRAY);
  g.fillRect(0, 0, 350, 450);
  g.setColor(Color.blue);

  g.setColor(Color.green);
  g.setColor(Color.GRAY);
  g.fillRect(0, 251, 450, 200);
  g.setColor(Color.red);
  g.drawRect(0, 0, 343, 250);
  for (int i = 0; i < Brick.size(); i++) {
   if (Brick.get(i) != null) {
    g.fill3DRect(Brick.get(i).x, Brick.get(i).y,
      Brick.get(i).width, Brick.get(i).height, true);
   }
  }

 }

 int brickscount;

 public void run() {

  int xaxis = brickx;
  int yaxis = bricky;

  for (int row = 0; row < LEVELS_ONE.length; row++) {
   for (int col = 0; col < LEVELS_ONE[row].length(); col++) {

    if (LEVELS_ONE[row].charAt(col) == 'W') {

     Brick.add(new Rectangle(xaxis, yaxis, brickBreadth, brickHeight));
     xaxis += (brickBreadth+1);

    }
    if (LEVELS_ONE[row].charAt(col) == ' ') {
     xaxis += (brickBreadth+1);

    }

   }
   yaxis += (brickHeight+2);
   xaxis = brickx;
  }

 }// while loop ends here

}

Click here for Breaking Bricks Game Code

Also see Bullet shooting game using Java.

Multiple windows in any android device.

Multitasking

  • Defined as the ability to perform many tasks at same time.
Now a days almost all phones can do multitasking.
All android phones support multitasking, this is done by placing the active tasks in a queue on ram so that they can be switched any time. But at a given time only one task can be done and cannot work on multiple tasks at same time.
Android platform offers multiple windows applications to work on multiple applications at same time. Here are some applications which help multi window tasking.

Floating Apps(Multitasking)

Floating-Apps
  • You can turn home screen widgets or any URL in to floating window using this application. 
  • Windows can be minimized or resized or moved. 
  • Many floating apps are available by default. 
  • Works on any android phone and tablet. 


Available floating apps:  

Floating Applications Floating Active windows Floating Launcher
Floating Add bookmark Floating Bookmarks Floating Search Google
Floating Browser Floating Calculator Floating Search Wikipedia
Floating Dialer Floating Flashlight Floating Stopwatch
Floating System information Floating Video player Floating Add contact
Floating Countdown Floating Facebook Floating File browser
Floating Google plus Floating Image viewer Floating Music player
Floating Notes Floating PDF viewer Floating Task Killer
Floating Translate Floating Twitter Floating Vimeo
Floating Wifi manager Floating Youtube

 Or create your own floating apps from home screen widgets or URLs!

Link to download Floating Apps  DOWNLOAD

Tiny Apps(Floating)

Tiny-apps-floating
  • Tiny Apps is a package of 7 useful floating apps that stay on top of all other apps. All windows can be moved, resized and docked to the left side of your screen to hide and show windows quickly. Use your volume buttons to change the transparency of each window!
Tiny Apps Pro enables the following features:
- dock windows to the left side of your screen
- adjust a window's transparency by using your volume buttons
- 2 additional Tiny Apps: widgets and browser
You can run several windows of the same Tiny App.

Link to download Floating Apps  DOWNLOAD

22 February 2014

History of Android

History-of-android


  • Android is an opensource operating system based on the Linux kernel and designed primarily for touchscreen mobile devices.
  • Initially developed by Android, Inc., which Google backed financially and later bought in 2005.
Google-Android

  • Unveiled in 2007 
  • The first publicly available smartphone running Android, the HTC Dream, was released on October 22, 2008

First-Android-SmartPhone-HTC-Dream

  • Android Evolution;


Android-Evolution
  • Android 0.9 is the first version(beta) and has no name.
  • Version 1.0 is named as Apple pie, and Version 1.1 as Banana Bread

21 February 2014

Play Lyrics in Windows Media Player

Windows media player can not only play songs but also display lyrics in synchronization with the song being played. All you need is windows media player and a plugin(Lyrics Plugin) for playing lyrics.
Click on download to get the plugin.
Download-Lyrics-Plugin-for-windows-media-player


Follow the slides shown;
lyrics-plugin-download-page

folder

lyrics-plugin-installation

lyrics-plugin-installation

lyrics-plugin-installation

lyrics-plugin-installation

windows-media-player


Select a song and click on play, player automatically searches for lyrics on web and displays them.
lyrics-play







19 February 2014

Coding Tools

Notepad
  • Notepad can be used to write and edit java code.
  • The notepad file must be saved with '.java' extension.
  • Name of the file must be same as that of the class being written in it.
  • This file can be accessed with command prompt and can be compiled and run.
  • cmd to compile java file : javac <space>filename.java
  • If it shows no errors then the command to run java file is : java <space> filename

 Writing java code can be made simple using IDEs. A number of java IDEs are available on internet
Some of the IDEs for programming java are:
  • Eclipse
  • Netbeans
  • BlueJ
  • JCreator
  • IntelliJ Idea
  • JBuilder
If you are a beginner in programming then it is good to start practicing with notepad or else you can go with IDEs.

Out of all these IDEs Eclipse is the most preferrable one.It is a free software.You can download Eclipse at Download Eclipse                         
     

Starting with Eclipse

  • After downloading the eclipse IDE you need to extract the .ZIP file in to a folder in which you can find eclipse loader(eclipse.exe)
  • Now click on eclipse.exe and authorize the security warning(click run). You will be asked to select a workspace where all your eclipse files will be saved. Click browse and select a new empty folder and click OK.
  • Eclipse starts with a welcome screen. now open window > open prespective > java. Now you are ready to create and work with projects.

HOW TO CREATE A NEW PROJECT AND NEW CLASS. 

  • Goto File new Java Project and give some name to your project and click ok.
    New-project

  •  You can see your project created below the package explorer window on the left.
    Package-explorer

  • To create a new class right click on the project you just created select new and again select class.
    New-class

  •  A window appears in which name of the class is given(First letter of the class in CAPITALS). Check the box as shown below and click finish.
    class-details
  • Now a java file is created with a class name same as file name. Main method is also included in it.
  • The code that is to be executed is written inside the main method.

Program to display all prime number below a user entered number

Create a new Class with name Disp_primes:

import java.util.Scanner;

public class Disp_primes {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
       
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter a number : ");
        int num = sc.nextInt();
        System.out.println("prime numbers below "+num+" are :");
        int rem=0;
        if(num==2){
            System.out.print(num+" is even prime");
        }
        else{
            for(int i=num;i>2;i--){
                int count=2;
        while(count<i){
            rem = i%count;
            if(rem==0)
                break;
            else
                count++;
                    }
        if(rem!=0)
            System.out.print(i+",");
        }
            if(num>2){
                System.out.print("2");
            }
        }
    }

}

Output:(Click on image to enlarge):
Program-to-display-all-prime-number-below-a-user-entered-number-output
(Comment if you have any doubts)
>

Program to check if a number is Prime or not

Create a new Class with name Chk_prime :

import java.util.Scanner;
 

public class Chk_prime {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int rem=0,i=2;
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter a number to check if it is prime : ");
        int num = sc.nextInt();
        System.out.println("You entered : "+num);
        if(num==2){
            System.out.print(num+" is even prime");
        }
        else{
        while(i<num){
            rem = num%i;
            if(rem==0){
                System.out.print(num+" is not prime");
            break;}
            else
                i++;
                    }
        if(rem!=0)
            System.out.print(num+" is prime");
        }
        }
    }


Output:(Click on image to enlarge)
Program-to-check-if-a number-is-Prime-or-not-output
(Comment if you have any doubts)

Program to check if a year is leap year or not

Create a new class with name Chk_leapyear

import java.util.Scanner;

public class Chk_leapyear {
   
    public static void main(String[] args) {
        // TODO Auto-generated method stub
       
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter a year to check if it is leap year : ");
        int year = sc.nextInt();
        System.out.println("You entered : "+year);
        if(year%100==0){
            if(year%400==0)
                System.out.println(year+" is a leap year");
            else
                System.out.println(year+" is not a leap year");
        }
        else{
            if(year%4==0)
                System.out.println(year+" is a leap year");
            else
                System.out.println(year+" is not a leap year");
        }
    }

}

Output:(Click on image to enlarge)

Program-to-check-if-a-year-is-leap-year-or-not-output
Enter the year you want to check in the output window as shown above.
(Comment if you have any doubts)

First Java program

A demo file to initialize and display different variables:

  • Create a new class with name VariablesDemo:
public class VariablesDemo {

    public static void main(String[] args) {
   
        /* Declaration of variables  */
         int Id;
         String name;
         char gender;
         double salary;
    
         /* Initialization of variables*/
         Id = 4348;
         name = "Employer";
         gender ='M';
         salary = 25000.0;
    
        /* Display the employee details */
         System.out.println("Id : "+ Id);
         System.out.println("Name : "+ name);
         System.out.println("Gender : "+ gender);
         System.out.println("Salary : "+ salary);

        }
}
NOTE: 
  • The text between "/* " and "*/" will not be executed.They are used to write comments.
  • For single line comments use "//
 Output:(Click on the image to enlarge)
eclipse-output

Demonstration of Continue statement

Create a new class with name ControlContinue:

class ControlContinue {
    public static void main(String args[]) {
        //boolean bool = true;
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 10; j++) {
                System.out.print(j + "\t");
                if (j > 5) {
                    System.out.println();
                    continue;
                }
            }
            System.out.println("Outer Loop");
        }
        System.out.println("End");
    }
}

Output:(Click on the image to enlarge)
Demonstration of Continue statement-output

Demonstration of break statement

create a class with name Control:

class Control {
    public static void main(String args[]) {
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 10; j++) {
                System.out.print(j + "\t");
                if (j > 5) {
                    break;
                }
            }
            System.out.println("Outer Loop :"+(i+1));
        }
        System.out.println("End");
    }
}

Output: (Click on the image to enlarge)
Demonstration-of-break-statement-output

Program to print Fibonacci numbers below 'n'

Create a new Class with name Fibonacci:

import java.io.*;
class Fibonacci {
    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("enter the value n");
        int n = Integer.parseInt(br.readLine());
        int a = 0, b = 1, c = 0;
        if (n > 0) {
            System.out.println("---------------------");
            System.out.println("\t" + a);
            System.out.println("\t" + b);
            do {
                c = a + b;
                if(c<=n)
                System.out.println("\t" + c);
                a = b;
                b = c;
            } while (c <= n);
            System.out.println("---------------------");
        } else {
            System.out.println("enter positive n value");
        }
    }
}



Output:(Click on image to enlarge):
Program-to-print-Fibonacci-numbers-output
Comment if you have any doubts.



Contact Form

Name

Email *

Message *

Smooth Graphics Java

// Arrange Bricks in Game //java brick breaker game code without flickering // added game levels 1,2,3 in the game //java paddle ball ga...