Monday, 21 November 2011

Living organism traced in Dead Sea

Dead Sea of Israel is the most saline sea. Here everything floats on here. Due to extreme salinity it is impossible for any organism to stay alive here. But the scientists of Max Planck Institute have collected samples of certain bacteria that are present in Dead Sea. They are now wondering about that how it is possible for the bacteria to stay alive. Research is now going on to find out the reason behind it.

Friday, 18 November 2011

Java program to create a music pattern

This program is done using Java Swing to create the GUI pattern. The music pattern is developed using Java MIDI Sequemce. The user can create different music pattern by clicking related check boxes.The user can also change the tempo factor.

Click to DOWNLOAD the archive from 4shared.com

Java program to design a GUI based 15 puzzle game

It is simply a game of arranging numbers 1-15 which are placed in a 4*4 2D array with one block left blank. One will have to arrange by moving the blank block. Here a timer is included to count total time to solve it. This logic is given a GUI with help of Java Swing.Here is the code for you -->
The Screenshot shown alongside is actually the picture how the game will look like when run on Windows7. It will look same as to the code of JAVA file link given below but different from the below code only in respect with game menubar. Try writing below code and also that is written in file (link given at last). Hope you will enjoy.

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import java.text.*;

public class FifteenPuzzle2 extends JPanel {
  public static JMenuItem newItem;
  public static javax.swing.Timer t;
  JButton[][] jb = new JButton[4][4];
  static int minute, second;
  static JFrame jf;

  public FifteenPuzzle2() {
       setLayout(new GridLayout(4, 4));

       int i, j, k;
       init(true);
       for (i = 0; i < jb.length; i++)
      for (j = 0; j < jb[i].length; j++)
           jb[i][j].addActionListener(
             new ActionListener() {
               public void actionPerformed(ActionEvent e) {
              String command = e.getActionCommand();
              String[] indices = command.split(" ");
              int i = Integer.parseInt(indices[0]);
              int j = Integer.parseInt(indices[1]);
              int[] r = {i - 1, i, i + 1, i};
              int[] c = {j, j + 1, j, j - 1};
                for (int k = 0; k < 4; k++) {
                 if (r[k] >= 0 && r[k] < 4 && c[k] >= 0 && c[k] < 4){
                    JButton button = jb[r[k]][c[k]];
                    if (button.getText().equals("")) {
                      button.setText(jb[i][j].getText());
                      jb[i][j].setText("");
                    }
                 }
                }
            }
        });

        newItem.addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    init(false);
                }
            }
        );
    }
    public void init(boolean firstTime) {
        ArrayList a = new ArrayList();
        int i, j, k;
        for (i = 1; i <= 15; i++)
            a.add(new Integer(i));
        Collections.shuffle(a);
        a.add(new Integer(0));

        k = 0;
        for (i = 0; i < jb.length; i++)
            for (j = 0; j < jb[i].length; j++) {
                Integer val = (Integer)a.get(k++);
                if (firstTime) {
                    jb[i][j] = new JButton(val.intValue() + "");
                    jb[i][j].setActionCommand(i + " " + j);
                    add(jb[i][j]);
                }
                else
                    jb[i][j].setText(val.intValue() + "");
            }
        jb[3][3].setText("");
            minute = 0;
            second = 0;
    }

    public static void main(String[] args) {
        jf = new JFrame();
        jf.setDefaultCloseOperation(jf.EXIT_ON_CLOSE);

        JMenuBar jmb = new JMenuBar();
        jf.setJMenuBar(jmb);

        JMenu gameMenu = new JMenu("Game");
        jmb.add(gameMenu);
       
        newItem = new JMenuItem("New");
        gameMenu.add(newItem);

        gameMenu.addSeparator();

       
        FifteenPuzzle2 fp = new FifteenPuzzle2();
        jf.setContentPane(fp);

        final DecimalFormat dc = new DecimalFormat("00");

        t = new javax.swing.Timer(
            1000,
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    jf.setTitle(dc.format(minute) + ":" + dc.format(second));
                    second++;
                    if (second >= 60) {
                        second %= 60;
                        minute++;
                    }
                }
            }
        );
        jf.pack();
        jf.setVisible(true);
        Dimension d=Toolkit.getDefaultToolkit().getScreenSize();
        int w=(int)d.getWidth();
        int h=(int)d.getHeight();
        jf.setLocation((int)(w/2-jf.getWidth()/2),(int)(h/2-jf.getHeight()/2));
        t.start();
    }
}


You can also download the source code from following links -
DOWNLOAD the JAVA source code from MediaFire
DOWNLOAD the JAVA source file from 4shared

Java program to create a Kaun Banega Crorepati game

This one multi file application. It is done using concept of thread, Java Swing, Java2D, elementary file handling and inheritance. Its completely a fun game which is quite like a quiz. The questions are in a random manner which are initially in several text files. The text are placed according to co-ordinate systems.Images are added to give a different look.
Click to DOWNLOAD the ZIP file from 4shared.com

Wednesday, 16 November 2011

Java program to design a Minesweeper game.

This program creates a Minesweeper game as on WindowsXP. It basically uses 2 arrays to save the position of hidden mines. Every time mine position changes using random function. JButton is used and it returns a action value to check which one has been hit. A timer is also added to calculate the total time to solve it.

Click to DOWNLOAD the archive from 4shared.com

C program to perform deletion of nodes in a doubly link list

This program includes deletion of head node, last node and any node from middle. This program is not a menu driven one. The program is a memory efficient one as it releases the memory which contained the data after its deletion using free() function.

Click to DOWNLOAD the C file from 4shared.com

Java program to do simple animation

This program is a simple ball jumping animation. This one is done using concept of co-ordinates, inheritance, java2D and threading. It is displayed on frame with JPanel. After each movement of ball the background is repainted to erase the trail of ball.

Click to DOWNLOAD the JAVA file from 4shared.com

Monday, 14 November 2011

C program for insertion in a doubly link list

This program is done by using linked list. The insertion program here os not menu-driven. It inserts at head , last, middle after a particular node and in the middle before a particular node.The forward and backward links are done using structure pointers inside a structure definition.

Click to DOWNLOAD the C file from 4shared.com


Sunday, 13 November 2011

C program to convert infix to postfix

This program converts a given infix expression to its equivalent postfix. It is done using stack. It considers operators +,-,*,/,^ and also brackets, it only does not checks whether the infix expression is correct or not. Here it first checks whether operatoe or not. If operator then it is inserted into stack on priority basis. If left bracket it is pushed onto stack and if a right bracket elements are popped from stack and added to postfix till a left bracket encountered. Otherwise if operand it is added to postfix.

Click to DOWNLOAD the C file from 4shared.com

C program of implementation of stack

This program creates a stack and perforns push, pop and display operations on a stack. It is implemented using linked list. Stack is a Last In First Out (LIFO) data structure. To follow this insertion in linked list is done at head node and deletion is also done from head end. Another method can also be followed by insertion at end and deletion from the last node.

Click to DOWNLOAD the C file from 4shared.com

Neutrino travels faster than light

Click hereread the article