Java Is Everywhere !

Java is a programming language and computing platform first released by Sun Microsystems in 1995. There are lots of applications and websites that will not work unless you have Java installed, and more are created every day. Java is fast, secure, and reliable. From laptops to datacenters, game consoles to scientific supercomputers, cell phones to the Internet, Java is everywhere!

What is .NET?

.NET is an integral part of many applications running on Windows and provides common functionality for those applications to run. For developers, the .NET Framework provides a comprehensive and consistent programming model for building applications that have visually stunning user experiences and seamless and secure communication.

Linux

Linux was originally developed as a free operating system for Intel x86-based personal computers. It has since been ported to more computer hardware platforms than any other operating system. It is a leading operating system on servers

Java Script and jQuery

JavaScript is a scripting language. jQuery is a library built in the JavaScript language that enabled users to write some JavaScript code faster (Mainly DOM manipulation, Animation and AJAX).

Android Technology

Android is a Linux-based operating system designed primarily for touchscreen mobile devices such as smartphones and tablet computers. Initially developed by Android, Inc., which Google backed financially and later bought in 2005

ff

Recent Posts

Friday, May 10, 2013

How to install i-Report Plugin for Netbeans IDE


Hi people.. Let's begin i-Reprot by installing it inside the NetBeans IDE.

First of all, download iReport NB plug-in files using following link.( please select your current Netbeans ide version and download.the plug-in)




Then after the download finishrd , open Net beans IDE(I'm using Net Beans 7.1.1 ) and go to 'Tools' menu  and select 'Plugin' submenu 



then you will get 'Plugin' dialog, select 'Downloaded' tab and click on "Add Plug-in" button




then browse the downloaded plug-in folder and select all and click Open

then Click on Install button
then you will get dialog box same as following image, then click 'next' button











Then you will get following welcome screen inside the Netbeans IDE .


Lets talk How to create Reports using iReport  in next tutorial





Thursday, May 9, 2013

JOptionPane How to Use (For Beginners)


Hi Java warriors.. nice to meet you again..
Today I'm gonna show you how to use JOptoinPane Class.

Basically There are 4 main methods we use often 
1.    showMessageDialog
2.    showOptionDialog
3.    confirmDialog
4.    inputDialog

showMessageDialog() method

If you want Just a display a message as some information or as an error. such situations we can use showMessageDialog.
method Definition
public static void showMessageDialog(Component parentComponent,
                     Object message,
                     String title,
                     int messageType,
                     Icon icon)
                         throws HeadlessException
Explanation of Parameters:
parentComponent - determines the Frame in which the dialog is displayed; if null, or if the parentComponent has no Frame, a default Frame is used(Most of the time default frame will be your desktop , so it will load center of your Desktop. if you use 'this' as parent object which means your current Frame then JoptionPane will load center of your Frame no matter where is it.)
message - the Message ( Object) to display
title - the title string for the dialog
messageType - the type of message to be displayed: ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE
icon - an icon to display in the dialog that helps the user identify the kind of message that is being displayed

class TestDialog{
            public static void main(String args[]){
                        JOptionPane.showMessageDialog(this, "message goes here", "this is dialog title", JOptionPane.INFORMATION_MESSAGE, null);
//I didn't set any Icon, thats why last parameter is set as 'null'
            }
}

showOptionDialog() method

we can use showJOptionDialog method when we need customize JOptionPane.
For example Lets change the text/caption of 'OK' button
JOptionPane.showOptionDialog(null,
        "Message goes Here",
        "This is title",
        JOptionPane.OK_OPTION,
        JOptionPane.INFORMATION_MESSAGE,
        null,
        new String[]{ "my new button text"}, // this is the array
        "default");


and using same way, you can add many buttons to your OptionPane. look at following code..

                String[] buttonArray = {"Button1", "Button2", "Button3"};
                int returnValue = JOptionPane.showOptionDialog(
                                null, "Message Body goes here", "Dialog title goes here", JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, buttonArray, "ddd");
                System.out.println("you selected button no"+returnValue);




if you select "Button 1" your console will display a message "you selected button no 1"
if you didnt select any button your console message will be "you selected button no -1"
this happen bcoz showOptionDialog return a integer number of your selected button
if you select first button it will return no '0' , if you select 2nd number it will return no '1' ect..
this is useful when you need to know whether user close the window or select a button

and you can also create a JOptionPane dialog with different language as following way



for do this we use a label  and button with sinhala language font and to change the  title font, I have set sinhala font to JOptionPane... check following code you will get it...

JLabel jLabel1=new JLabel();
jLabel1.setText("පණිවිඩය මෙතන ලියන්න");
jLabel1.setFont(new Font("Iskoola Pota", Font.BOLD, 14));
JOptionPane jopt = new JOptionPane();
jopt.setFont(new Font("Iskoola Pota", Font.BOLD, 14));
JButton btn1=new JButton("එකගයි");
btn1.setFont(new Font("Iskoola Pota", Font.BOLD, 14));
jopt.showOptionDialog(null,
                 jLabel1,
                "මාතෘකාව",
                 JOptionPane.OK_OPTION,
                JOptionPane.INFORMATION_MESSAGE,
                null,
                new JButton[]{btn1},
               "default");




Wednesday, May 8, 2013

Create simple Login useing Java (Part 2)



I guess you have completed the Part 1 of this login application tutorial, if not please go to Create simple Login application Java (part 1) and complete it.

When we develop Software, we need to store some data for future usage, we use Database Server for accomplish that objective. In this tutorial I Use MY SQL Server, but you can use Microsoft SQL Server also, if you like

Step 1
Type following queries on MySQL server command line

MYSQL > Create database dehanLogin;
MYSQL >use dehanLogin;
MYSQL > create table login(username varhcar(20) primary key, password varchar(20));

create new java class and name it as DB.java

public class DB {
    private static Connection con;
   public static Connection myConnection() throws ClassNotFoundException, SQLException{              
             Class.forName("com.mysql.jdbc.Driver");
              If(con !=null){
                                return con;
}else{
  con=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/dbName","root","mySQLPassword");//
     return con;
}
             
    }//end myConnection()
}// end DB.java

Add mysqlconnector jar file by right clicking Library folder and select ‘add library’ then select MYSQL JDBC driver .

Step 3
Code for login button
     

            try {
          if(txtUsername.getText().equals("")){
             JOptionPane.showMessageDialog(null,"username cannot be empty");
         }else{
             String pwd=new String(txtpwd.getPassword());
             ResultSet rs =DB.myConnection().createStatement().executeQuery("select username,password from login where username = '"+txtUsername.getText()+"'and password = '"+pwd+"'").;
            if (rs.frist()){
                new Home().setVisible(true);
            }else {
            JOptionPane.showMessageDialog(null,"Incorrect username or password");
           }


         }
        }catch (NullPointerException e){
               JOptionPane.showMessageDialog(null,"password cannot be empty");
                e.printStackTrace();
        }catch (Exception e){
        
                e.printStackTrace();
        }


Try to make the login with seperate user levels
hope your comments and the problems  you get in developing time
and also you can request any java turorial by commenting on my post or just make a e-mail for me
dehanpramoda@gmail.com :)

How to Install Java JDK and JRE on Windows


Install java JDK

I’m going to explain you step by step form the beginning, but if you already know how to install java , you can skip this part
First of all you must download java JDK form www.oracle.com site. You can use following link to download the JDK
I use JDK 7 to demonstrate you how to install JDK and JRE on your Personnel computer











After you get the “successfully instaled ” dialog box ,exit form it
Now you have successfully installed both java development kit(JDK) and java runtime environment(JRE)  on your computer.
Now you can set java path on your machine by using following steps

1. Right click on my computer icon and select properties 
2. Select "Advance settings link on left side of the given window"


3. Then you will get following window, click environment variable button


4. click on "new button " of System variables panel
and give your JDK installation path as  variable value, you can give any name for variable name, most people  use variable name as 'path' or "java home'', here I use "java home " as my environment variable name.



then click ok and exit 
to make shure about path variable you can open windows command prompt and type the word "javac"
then you can get following type of long result list environment variable create successfully.



that's all for this tutorial
hope you enjoy the tutorial .


Tuesday, May 7, 2013

Create simple Login useing Java (Part 1)

Create simple Login useing Java (Part 1)

Today I’m gonna show you how to create a Login using Java, I use Net beans IDE 7.2 for develop this application,
open the Net beans IDE and create a new java application
Go to fileànew Project or press Ctrl+Shift+N  to create new Project
Then you will appear “New Project “ dialog box,
Select “Java” from categories and then select “Java Application” from “Projects” (Figure 1.1)





Name our project as “LoginApplication”(or you can give any name you like)
Default project location is Netbeans folder located in MyDocuments but you can give you own location by click “Browse” button
Click Finish
Now your project is created



You can see your project structure in Projects window
Basically java project has divided into two main parts by considering file type
1.      Source file
2.      Library file

Source files are stored inside packages these packages are display inside “source packages” , you can create new packages by right click on source package or any relative package.
Initially NB has created you a java class which is the main java file of the project
(as soon as you run your project JVM comes to this file, this is the main gate to the enter your project GUIs  )


And there are few other windows you should know
Files window, navigator window, Services window. I’m going to explain you only the files window here, try to figure out navigator and services window ( don’t worry friends just try, I’ll explain them in my future tutorials)



Build- this file contain all the “.class” files which are created when the project compiled

Src- this file contains your all java application source files most of the time “.java” files but if you want , you can add any file as you like (ex:- images, i-report files ,etc…)

Nbproject- this file contains all the generated “ant ” and files which are relevant for open the project in Netbeans IDE , if you delete this folder you cant open the project in NB

Dist- this file has Java Archive file “.jar” file , it is a compressed file of all the class files , when ever you want to distribute your project you can use this jar file to create .exe file




Now lets start to create Login application
Right click on “loginapplication “ folder and select “New>” then select “JFrame Form”,
And name the form as “DehanLogin” or any name you like :D



Click finish
now you get a Graphical User Interface , you can shift between design view and source view using “Design and Source buttons”



Now You can design your Login window just drag and drop swing components from netbeans “palatte”
If you don’t appear NB palatte  go to Window à palatte

You can change window properties using “properties” window



try to do this , lets continue remainder on part 2