19 February 2014

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.



24 June 2013

capture webview andriod.xamarin

using System;
using Android.App;
using Android.OS;
using Android.Widget;
using System.IO;
using Android.Webkit;
using Android.Graphics;
using Android.Graphics.Drawables;
using Android.Util;
using Java.IO;
using System.Diagnostics;

namespace test
{
[Activity (Label = "test", MainLauncher = true)]
public class Activity1 : Activity
{


protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);

// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);

// Get our button from the layout resource,
// and attach an event to it
            Button button = FindViewById<Button>(Resource.Id.myButton);
            WebView webview = FindViewById<WebView>(Resource.Id.webView1);
            string id = "103230006";
            webview.LoadUrl("www.google.com");
            button.Click += delegate
            {
           
                Picture picture = webview.CapturePicture();    
                Bitmap bmp = Bitmap.CreateBitmap(picture.Width , picture.Height
                                                    , Bitmap.Config.Argb8888);
                Canvas canvas = new Canvas(bmp);
             
                picture.Draw(canvas);
                FileStream fs = new FileStream("/storage/sdcard0/file.jpg", FileMode.Create, FileAccess.Write);
                bmp.Compress(Bitmap.CompressFormat.Jpeg, 80, fs);
             
                    fs.Close();
            };
}
}
}

==========================LAYOUT================================
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:p1="http://schemas.android.com/apk/res/android"
    p1:orientation="vertical"
    p1:minWidth="25px"
    p1:minHeight="25px"
    p1:layout_width="fill_parent"
    p1:layout_height="fill_parent"
    p1:id="@+id/linearLayout1">
    <WebView
        p1:layout_width="fill_parent"
        p1:layout_height="wrap_content"
        p1:id="@+id/webView1"
        p1:layout_marginBottom="30dp" />
    <Button
        p1:text="Button"
        p1:layout_width="fill_parent"
        p1:layout_height="wrap_content"
        p1:id="@+id/myButton" />
</LinearLayout>

06 December 2012

Brick Breaker java game source code


Brickbreaker-game


import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

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

public class BrickBreaker extends JPanel implements KeyListener, ActionListener, Runnable {
private static final long serialVersionUID = 1L;
// movement keys..
private static boolean right = false;
private static boolean left = false;

private static final int brickBreadth = 30;
private static final int brickHeight = 20;
// variables declaration for brick...............................
// ===============================================================
// declaring ball, paddle,bricks
private Rectangle Ball;//
private Rectangle Bat;//
private Rectangle[] Brick;
private Rectangle background = new Rectangle(0, 0, 350, 450);

//reverses......==>
private int movex = -1;
private int movey = -1;
private boolean ballFallDown = false;
private boolean bricksOver = false;
private int count = 0;
private String status;
private JButton button;

private static enum STATUS {
START, PAUSE, RESUME, STOP
}

private static boolean PAUSE = false;
private static boolean RUNNING = false;

BrickBreaker() {
initializeVariables();
JFrame frame = new JFrame();
button = new JButton(STATUS.START.name());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

// using this as parent layout exists (JFrame)
this.setPreferredSize(new Dimension(background.width, background.height));
frame.getContentPane().add(this);
frame.pack();

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

button.addActionListener(this);

this.addKeyListener(this);
this.setFocusable(true);
}

public static void main(String[] args) {
new BrickBreaker();

}

// declaring ball, paddle,bricks

public void paint(Graphics g) {
g.setColor(Color.LIGHT_GRAY);
g.fillRect(background.x, background.y, background.width, background.height);
g.setColor(Color.blue);
g.fillOval(Ball.x, Ball.y, Ball.width, Ball.height);
g.setColor(Color.green);
g.fill3DRect(Bat.x, Bat.y, Bat.width, Bat.height, true);

// this will paint below the peddle
g.setColor(Color.GRAY);
g.fillRect(0, 251, background.width, 200);

// this will draw border line
g.setColor(Color.RED);
g.drawRect(0, 0, background.width - 1, 250);
for (int i = 0; i < Brick.length; i++) {
if (Brick[i] != null) {
g.fill3DRect(Brick[i].x, Brick[i].y, Brick[i].width, Brick[i].height, true);
}
}

if (ballFallDown == true || bricksOver == true) {
Font f = new Font("Arial", Font.BOLD, 20);
g.setFont(f);
g.drawString(status, 70, 120);
ballFallDown = false;
bricksOver = false;
}

}

// /...Game Loop

public void run() {

// == ball reverses when touches the brick=======
//ballFallDown == false && bricksOver == false
while (RUNNING) {
if (PAUSE) {
sleep();
continue;
}

//   if(gameOver == true){return;}
for (int i = 0; i < Brick.length; i++) {
if (Brick[i] != null) {
if (Brick[i].intersects(Ball)) {
Brick[i] = null;
// movex = -movex;
movey = -movey;
count++;
} // end of 2nd if..
} // end of 1st if..
} // end of for loop..

// /////////// =================================

if (count == Brick.length) {// check if ball hits all bricks
bricksOver = true;
status = "YOU WON THE GAME";
repaint();
}
// /////////// =================================
repaint();
Ball.x += movex;
Ball.y += movey;

if (left == true) {

Bat.x -= 3;
right = false;
}
if (right == true) {
Bat.x += 3;
left = false;
}
if (Bat.x <= 4) {
Bat.x = 4;
} else if (Bat.x >= 298) {
Bat.x = 298;
}
// /===== Ball reverses when strikes the bat
if (Ball.intersects(Bat)) {
movey = -movey;
// if(Ball.y + Ball.width >=Bat.y)
}
// //=====================================
// ....ball reverses when touches left and right boundary
if (Ball.x <= 0 || background.width - Ball.width <= Ball.x) {
movex = -movex;
} // if ends here
if (Ball.y <= 0) {// ////////////////|| bally + Ball.height >= 250
movey = -movey;
} // if ends here.....
if (Ball.y >= 250) {// when ball falls below bat game is over...
ballFallDown = true;
status = "YOU LOST THE GAME";
repaint();
button.setText(STATUS.START.toString());
break;
}

sleep();
} // while loop ends here

}
private void sleep() {
try {
Thread.sleep(10);
} catch (Exception ex) {
} // try catch ends here
}

// loop ends here

// ///////..... HANDLING KEY EVENTS................//
@Override
public void keyPressed(KeyEvent e) {
int keyCode = e.getKeyCode();
if (keyCode == KeyEvent.VK_LEFT) {
left = true;
// System.out.print("left");
}

if (keyCode == KeyEvent.VK_RIGHT) {
right = true;
// System.out.print("right");
}
}

@Override
public void keyReleased(KeyEvent e) {
int keyCode = e.getKeyCode();
if (keyCode == KeyEvent.VK_LEFT) {
left = false;
}

if (keyCode == KeyEvent.VK_RIGHT) {
right = false;
}
}

@Override
public void keyTyped(KeyEvent arg0) {

}

@Override
public void actionPerformed(ActionEvent e) {
String str = e.getActionCommand();
if (str.equals(STATUS.START.toString())) {
button.setText(STATUS.PAUSE.toString());
this.startGame();
}
if (str.equals(STATUS.PAUSE.toString())) {
PAUSE = true;
button.setText(STATUS.RESUME.toString());
}
if (str.equals(STATUS.RESUME.toString())) {
PAUSE = false;
button.setText(STATUS.PAUSE.toString());
}

// if (str.equals(STATUS.STOP.toString())) {
// RUNNING = false;
// button.setText(STATUS.START.toString());
// }

}

public void startGame() {
requestFocus(true);
initializeVariables();
Thread t = new Thread(this);
t.start();
}

public void initializeVariables() {
// default size of a brick...............................
int brickx = 70;
int bricky = 50;
RUNNING = true;
// x = 160, y = 218, width = 5, height = 5
Ball = new Rectangle(160, 218, 5, 5);
// x = 160, y = 245, width = 40, height = 5

Bat = new Rectangle(160, 245, 40, 5);

Brick = new Rectangle[12];
// //////////// =====Creating bricks for the game===>.....
createBricks(brickx, bricky);
// ===========BRICKS created for the game new ready to use===
movex = -1;
movey = -1;
ballFallDown = false;
bricksOver = false;
count = 0;
status = null;

}

public void createBricks(int brickx, int bricky) {
// //////////// =====Creating bricks for the game===>.....
/*
* creating bricks again because this for loop is out of while loop in run
* method
*/
for (int i = 0; i < Brick.length; i++) {
Brick[i] = new Rectangle(brickx, bricky, brickBreadth, brickHeight);
if (i == 5) {
brickx = 70;
bricky = (bricky + brickHeight + 2);

}
if (i == 9) {
brickx = 100;
bricky = (bricky + brickHeight + 2);

}
brickx += (brickBreadth + 1);
}
}

}

Help improve my way to approach you by commenting. PLZ do comment.
Thank you.

 How To Arrainge Bricks In Game

GitHub Link

21 May 2011

Amazing GooGle Tricks U have ever Known

Many Tricks about GOOGLE !!

I have already written some here and there tricks about google but today i am going to tell you most of the tricks !!

1] Google gravity page
Open google.com & type “google gravity” & then press the “I’m Feeling Lucky” button .
That’s it there will be high gravity on that page , everthing will be lying on the ground .
Try it & then thank me later !

2] Google 1337 (Hacked page)
Many people around the globe who saw this page called in an hacked page (Even i dont know why,I think
it because it just looks like a hacked page).
Ok here it is.Open google.com & type “Google 1337″ & press  the “I’m Feeling Lucky” button .
You will se the page but will not understand anything , (as i did).

3] Meaning Of Search For Google

Goto Google.com & type “Search” in search box & press  the “I’m Feeling Lucky” button .

4] Loneliest Number .Goto Google.com & Enter the following line in search box “ the loneliest number” & Press enter and see which is the loneliest number.

5]Meaning Of Recursion

Goto Google.com & Enter the following word in search box “Recursion” Press Enter.On top of results you will See “Did You Mean: Recursion”

6]Google Loco

Goto Google.com & Type Google loco in search box & Press I’m Feeling Lucky Button

7]The number of horns on a unicorn

Goto Google.com & Enter the following line in search box the number of horns on a unicorn & Press Enter key

8]Chuck Norris

Goto Google.com & Enter the following line in search box Find Chuck Norris & Press I’m Feeling Lucky Button

9]French military Victories

Goto  Google.com & Type in French Military Victories & Press I’m feeling lucky button

9 Tips to SPEED UP U R PC

Nine Tips To Improve System Speed
1. At first let your PC boot up completely before opening any applications.
2. Then, refresh your desktop after closing any application and  this will remove your any unused and misused files from your RAM.
3. If your PC have less than 64MB Ram space then do not keep wallpaper at all and do not set large file size image as a wallpaper.
4. Do not cover or fill your desktop with a lot of shortcuts because each shortcut of your desktop uses up to 500 bytes of your RAM, which has great roll to make your system slow.
5. Remove all files and folder from your Recycle bin or empty the Recycle bin because until you empty the Recycle bin, the files are not really deleted from your hard drive.
6. Always use disk cleanup and also reove your latest restore backup if not needed.
7. There are much unused space on your hard drive so, Defragment your hard drive once every two or three moths. This will free up a lot space on you hard drive and rearrange all files.
8. Never make only one partition of your hard disk. Always make two or three partition of your hard disk and install all large software in second partition. Windows uses all the empty space as a virtual memory when your RAM is full.
9. Always protect your PC from dust because dust is the main problem to make jam CPU cooling fan. Use compressed airto clean your PC, never use vacuum.
10]And always use a good antivirus i recommend avast if you dont like to spend money on it

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...