Thursday, September 30, 2010

A nice site.....

Found a nice site today::www.typealyzer.comThey analyze your blog and tell you who you are. According to them, I am:ISTP - The Mechanics The independent and problem-solving type. They are especially attuned to the demands of the moment and are highly skilled at seeing and fixing what needs to be fixed. They generally prefer to think things out for themselves and often avoid inter-personal conflicts.The Mechanics enjoy working together with other...

Intelligent Catch Block

A new Feature in jdk1.7....Use just one catch instead of two unless needed.......Suppose you are writing a program that interact with SQL and do some IO,suppose your program can throw SQLException and IOException... Now you know that,you have to keep separate catch Blocks to catch the Exception thrown by the different hierarchy Classes as in our case IOException and SQL Exception...so we have to writetry{//some code that can throw IO or SQL Exception}catch(IOException e){//so some work}catch(Exception e){//do same work}as we can see we have to...

No more equals...just switch

Just remove one restriction from your mind that only the legal argument type of a switch statement is int, or any other type that can be promoted to int: byte, short, or char.Now with the jdk1.7 it can be a String also......a big overhead of using equals have been solved by sun....OverHead with equals::String cmd="your string";if(cmd.equals("dir"))showDir();else if(cmd.equals("cls"))clearScreen();else if(cmd.equals("exit"))exitFrom();elsegoToHell();a big overhead of if/else ladder and all,a lenghty code,but now leave the clumpsy else-if ladderjust...

Friday, September 24, 2010

2 power 99999

import java.math.BigInteger;class Power{public static void main(String... s){BigInteger i1=new BigInteger("2");System.out.println(i1.pow(99999));}}Downl...

Sudoku

//By Er. Minal Bansal import java.util.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; class Logic { //to start with a random index y of array 1 to 9 Random ranobj=new Random(); int y=ranobj.nextInt(9); // this is final array int arr[][]=new int[9][9]; int myarray[]=new int[9]; // i,j -> indices of array arr //k -> index of arr upto which elements are not added int i=0,j=0,k=8; //flag1 is false if this element cannot be added boolean flag1=true; //elements to be added int next[]={1,2,3,4,5,6,7,8,9}; Logic() { firstRow(); fill(); } public...

Puzzle

import java.awt.*;import java.awt.event.*;import javax.swing.*;public class Puzzle extends JFrame implements KeyListener{ static int[][] a={{11,0,7,3},{15,6,9,8},{2,10,13,1},{4,12,5,14}}; int i,j, row=3,col=3; JTextField[][] tf=new JTextField[4][4];Puzzle(){ setTitle("puzzle"); setLayout(new GridLayout(4,4));for(i=0;i<4;i++){for(j=0;j<4;j++){ tf[i][j]=new JTextField("");tf[i][j].setText(""+a[i][j]);tf[i][j].setHorizontalAlignment(JTextField.CENTER);tf[i][j].setFont(new Font("Georgia",Font.BOLD,26));tf[i][j].setBackground(Color.black);tf[i][j].setForeground(Color.white);...

Point to Point Chat Server

import java.io.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.net.*; import java.net.*; import java.sql.*; class Client extends JFrame implements ActionListener { String name; String msg; String target=""; int index; Socket s; InputStreamReader isr; BufferedReader br; PrintWriter pw; /*login frame data*/ JFrame loginframe; JButton login,cancel1; JTextField loginid; JLabel loginlb; Icon canimg,logimg; /*chat frame data*/ JFrame chatframe; JTextArea text; JTextField datatosend; JButton send; JButton clear; JScrollPane...

MyJavap Tool

import java.lang.reflect.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; class Myjavap implements ActionListener { JFrame mainFrame; JPanel upperPanel; JPanel lowerPanel; JTextField textField; JTextArea textArea; JScrollPane sp; JLabel intro; int flag=0; String mod=""; String fields=""; String superclass=""; String interfaces=""; String constructors=""; String methods=""; String finalinf=""; Myjavap() { mainFrame=new JFrame("MyjavapTool ~~~~~Milan~~~~~"); upperPanel=new JPanel(); textField=new JTextField("java.awt.Color"); intro=new...

ExplorerPlus

ExplorerPlusimport java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.tree.*;import javax.swing.tree.DefaultMutableTreeNode;import javax.swing.tree.TreeSelectionModel;import javax.swing.event.TreeSelectionEvent;import javax.swing.event.TreeSelectionListener;import java.io.*;import java.util.*;import javax.swing.table.*;import java.net.*;class MyExplorer implements TreeSelectionListener{ImageIcon def=new ImageIcon(".\\java.jpg");static JFrame frame;JLabel label;JTextField textField;JPanel upperPanel,lowerPanel,showPanel;JTable...

Explorer

import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.tree.*;import javax.swing.tree.DefaultMutableTreeNode;import javax.swing.tree.TreeSelectionModel;import javax.swing.event.TreeSelectionEvent;import javax.swing.event.TreeSelectionListener;import java.io.*;import java.util.*;import javax.swing.table.*;import java.net.*;class MyExplorer implements TreeSelectionListener{static JFrame frame;JLabel label;JTextField textField;JPanel upperPanel,lowerPanel,showPanel;JTable table;File f;JTree tree;JScrollPane sp,sp1;JEditorPane...

DeletingTool

import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; import javax.swing.BorderFactory; class DeletingTool implements ActionListener { JFrame f; JTextField tf; JButton b1,b2,browse; JLabel label,lb; DeletingTool() { String labeltext="Enter the PATH of Folder/File to DELETE........."+"Eg.. f:/games to delete games folder in Drive f"+ "& f:/milan.txt to delete milan.txt in Drive f"; f=new JFrame("Deleting Tool"); tf=new JTextField(""); b1=new JButton("Delete"); b2=new JButton("Clear"); browse=new JButton("Browse"); lb=new...

CrazyPad

import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.io.*; import javax.swing.text.*; import java.awt.datatransfer.*; import java.util.*; import java.beans.*; public class CrazyPad extends JFrame implements ActionListener,KeyListener { boolean flag=false; String filename=""; File fname; static JFrame f; JMenuBar menubar; JMenu m1,m2,m3,m4,m5,m6; JMenuItem m1item1,m1item2,m1item3,m1item4; JMenuItem m2item1,m2item2,m2item3,m2item4,m2item5; JMenuItem m3item1,m3item2; JMenuItem m5item1; JCheckBoxMenuItem tool; Color c=new...

CalculatorPad

import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;class CalPad implements ActionListener{JFrame frame;JPanel upperPanel;JPanel lowerPanel;JPanel buttonPanel;JTextArea textArea;JTextField display;JScrollPane sp;JLabel lb;JButton button[]=new JButton[20];Icon icon[]=new Icon[20];static int count;double opr1,opr2;String lastoperator="";double result;static boolean saveflag=false;String filename="";File fname;CalPad(){frame=new JFrame("Calculator ~~milan~~");upperPanel=new JPanel();lowerPanel=new JPanel();buttonPanel=new...