Tuesday, 17 July 2012

Creating Android Virtual Device(AVD)

To test and see how our application looks like we need a Android Emulator, so what we need for that is to configure our AVD .And for creating an AVD we need to set the properties for it . So lets see how to go about it:

Lets split this mission into 2 parts :

Part 1: Creating a AVD

 Go to Window in the Eclipse IDE>> Select AVD manager

or

Click on the AVD manager icon on the toolbar
Next you would see a screen like this:


Set the AVD properties >> Click Create AVD

An important thing that I would like to mention here carefully set the size of the AVD's SD card . Although you can set it to a  minimum of 9MiB but I would suggest you to allot it reasonable size to the SD card, and yes this SD card space is allotted on the computers hard drive.

Part 2: Using the AVD


Now in order to see how to use a AVD we must have a project already created and ready to be run. 

Running the application for the first time we need to do the following:

Right click on the application you wish to run >> Click run configuration >> set the name of the Configuration>> Select the application you wish to run>> Set the target (which is the Emulator on which you wish to run your project)>> click Apply >>Click run>> Emulator starts.




Exploring Eclipse

Just as always we create our new project in the Eclipse IDE .

Go to File >> New>>Project and you will see a Screen as this :

Select Android Application Project>>next>> Specify the Application name >>Specify the Project Name>>and finally specify the Package name>> Click next>>Click next>>Select Blank Activity>>specify activity name>>Click Finish


Okay so far so good !


Downloading and Installing Android

Taking the first step in the android world . lets Download the Android SDK for your operating system. To do so by visiting the official site for the download  here.

Read the instruction to install the SDK from this site.

Add the Platform and the packages.

In case if you are wondering that :
What is Eclipse ? and why do I need it for android development?

Here is the answer Eclipse is an Integrated Development Environment (IDE) for multiple languages. And the best part of it, is that it's FREE :) and open-source, also it can be extended by adding new plugins to it .So for using eclipse for android we need to add the android plugin to it.

Download Eclipse indigo from here

Install the Eclipse plugin.
Now we are good to go to the coding part of mission . :)

Say hello to the Android World



It being my summer break  time I am at home trying my hands at new technology ... and as usual trying to learn something about which  I have least idea , yeah I am talking about android .development.

Last year I got a new android phone and ever since i got it i have been wondering how amazing it is .The amazing applications available at the Google play  or the android market make my heart go boom boom ...:)

Although I have a bit knowledge about Java I had to struggle to get it going, right at the beginning few days earlier when I started with the download and installation(credits to my slow bb), but then I realized it's not that difficult to do it ... in fact I would say it is pretty easy. And I think that I was lucky to have faced all those problems, as it made me search, explore and learn more . I remember once my professor at college said that "If you are lucky you would get many errors and problems learning new technology ... but if you learn it in-spite of those thing you learn it in true meaning "

Now, having created a few applications of my own I would be ore then happy to share my learning with you .So in the coming posts we would discuss all the steps we need to follow  to create a new android application .

Friday, 22 June 2012

Mapping Java Application To Database with Login and Registration Form GUI


Main.java
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sample;

/**
 *
 * @author SunShine
 */
public class Sample {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Register rj=new Register();
        rj.setVisible(true);
     
    }
}

Register.java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sample;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.*;

/*
 * Register.java
 *
 * Created on 22 Jun, 2012, 12:07:46 PM
 */
/**
 *
 * @author SunShine
 */
public class Register extends javax.swing.JFrame {

    /** Creates new form Register */
    public Register() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        UsernameLabel = new javax.swing.JLabel();
        UserNameTextField = new javax.swing.JTextField();
        PasswordLabel = new javax.swing.JLabel();
        RegisterButton = new javax.swing.JButton();
        PasswordField = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        UsernameLabel.setText("Username:");

        PasswordLabel.setText("Password:");

        RegisterButton.setText("Register Me !");
        RegisterButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RegisterButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(28, 28, 28)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(UsernameLabel)
                            .addComponent(PasswordLabel))
                        .addGap(44, 44, 44)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(PasswordField)
                            .addComponent(UserNameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(116, 116, 116)
                        .addComponent(RegisterButton)))
                .addContainerGap(112, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(UsernameLabel)
                    .addComponent(UserNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(PasswordLabel)
                    .addComponent(PasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(97, 97, 97)
                .addComponent(RegisterButton)
                .addContainerGap(103, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>

private void RegisterButtonActionPerformed(java.awt.event.ActionEvent evt) {                                               
// TODO add your handling code here:
     
     PreparedStatement statement = null;

        try {
            Class.forName("org.sqlite.JDBC");
           Connection connection =DriverManager.getConnection("jdbc:sqlite:C:\\test.db");
            statement = (PreparedStatement) connection.prepareStatement("insert into test(username,password)values(?,?)");
            statement.setString(1,UserNameTextField.getText() );
            statement.setString(2,(PasswordField.getText()));
            

            statement.execute();

        } catch (Exception ex) {
            ex.printStackTrace();
        } 
}                                              

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Register.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Register.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Register.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Register.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Register().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify
    private javax.swing.JTextField PasswordField;
    private javax.swing.JLabel PasswordLabel;
    private javax.swing.JButton RegisterButton;
    private javax.swing.JTextField UserNameTextField;
    private javax.swing.JLabel UsernameLabel;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration
}