Friday, April 6, 2012

Fun in Matlab (Easter Egg)

MATLAB is a programming environment for algorithm development, data analysis, visualization, and numerical computation.
View Website: Mathworks or Wiki

At the same time you can have fun with some Matlab functions. These features are called Easter Egg which are the special things that the programmers of Matlab left for us to discover. I present you with the list of such functions and their result:
1. Type image in the command window to get:


2. Type life at the command window to view a simulation of  Conway's Game of Life


3. Type spy to see a image of a spy, with pointed nose like that of my gf.

4. penny



5. toilet


6. shower


Sunday, April 1, 2012

Getting User Keyboard Input in Java

This is a sample java program, to get user input from the keyboard to our java program.


import java.io.*;
public class JavaApplication25 {
   public static void main(String[] args)throws IOException {
   InputStreamReader isr=new InputStreamReader(System.in);
   BufferedReader br=new BufferedReader(isr);
   String str=br.readLine();
   System.out.println(str);
   }
}



Copy the above code,and paste it in your Java IDE, Compile it,Run it. The console asks for input,type it,press Enter key,and the console again displays the string that you just input. 

Reference:

A Simple GUI



Creating a basic GUI in Java using NetBeans IDE 7.1
1.       Creating a Project:
In NetBeans:




Click on Next.




Do as shown and click the Finish button.

1.       Building the Front End
Now we create a Java container using JFrame component and place the container in a new package. Follow the steps:
Right Click on the SulavGUI, in the Projects window as shown below.Click New->Other…










In Categories, select “Swing GUI Forms”




In File Types, select “JFrame Form”.
Now click on Next.




Click on Finish.

See the Palette in the Right of the monitor.  If it is not available, then press [Ctrl]+[Shift]+[8] at once.
From this palette, drag and drop the following items into the container (or form, idk):
i)                    1 Panel
ii)                   3 Label
iii)                 3 TextField
                 iv)           3 Button





At first drag the Panel, and position it as shown. Now place the jLabels1, 2, 3 jTextField1,2,3 and jButton1,2 inside it. Place jButton3 outside the Panel. Make it look like image shown below:






Press the [-] sign in the title bar of the Palette to minimize the Palette window, and click the  [double-square] sign for the Properties shown by the 2 blue arrows to restore it or make it visible.
Now click on jLabel1 in the GUI Design Window,





Now in the text field in the Properties window, change jLabel1 to Number 1. Similarly change the text for jLabel2, jLabel3 to Number 2 and Solution respectively.
Also change the Text of the 3 buttons to make as shown below.





Click on the jTextField1 and delete the text in it, resize the field if it reduces in size while deleting. Do the same for jTextField2 and jTextField3.
Now your looks of GUI is ready. Now let’s give functionality to it, aka brain.

Now Right Click on the Exit Button, and do:





Events->Action->actionPerformed

Your insertion pointer reaches to the point shown below:





In the place of “//TODO add your handling code here:”, type:
               
System.exit(0);
    

Go to Design view, by pressing the Design tab as shown:



Similary, for Add button add the following lines of code:

        float
num1,num2,result;
        num1=Float.parseFloat(jTextField1.getText());
        num2=Float.parseFloat(jTextField2.getText());
        result=num1+num2;
        jTextField3.setText(String.valueOf(result));

and for Clear button add the following:
        jTextField1.setText("");
        jTextField2.setText("");
        jTextField3.setText("");

as shown below: 







Now your simple GUI is ready. Click on the Run button to run the main project. 





This is the place where your platform independent, portable, secure, standalone application is present.
Happy Coding
Sulav







Thursday, March 29, 2012

JAVA to MS Access Connection (JDBC-ODBC bridge)

This article is for those who think Java is difficult.
Today I was taught to connect a Java class file to a Access Database. But Java can't directly connect with MS-Access, it needs a middleware called DSN-Data Source Name(not sure though what its called). 
So,first of all,create a database in Access(in my case I named it db1.accdb), and create a table within it(I named it tbl_pinfos) and created 3 fields in it,viz:
1.pid---Number
2.full_name---Text
3.contact_address=Text

Saved it and closed. Now the 'thought difficult' part.
Follow the steps to connect your database with the ODBC.




Click on "Select" Button.

Find the location of the database created in Access, and in the left pane(Database Name), select the database in your database folder. Then click on OK.


Click on OK.

Monday, January 16, 2012

Keyboard Shortcuts For Facebook

I am not a great author, and won't let u read long preface and prologue. Lets directly get into what you are searching for.

The keyboard shortcut for Facebook (in Windows) are:

Alt+?: Search
Alt+m: Compose a new message
Alt+1: Home page
Alt+Home: Home Page
Alt+2: Your profile page
Alt+3: Friend requests
Alt+4: Your messages
Alt+5: Notifications
Alt+6: Account page
Alt+7: Privacy
Alt+8: Facebook's Facebook page
Alt+9: Facebook Terms/Agreement
Alt+0: Facebook help center

These shortcuts works best in Google Chrome.
In Internet Explorer, you will need to hit Enter key after each key combination.
In Firefox, you will need to add shift key to the above combination, i.e Shift+Alt+? for invoking the Search.

These are what I have discovered yet. U can still try other Function key combination to discover other shortcuts as well.