Android Hello world Example – How to write “Hello world” app in android.

Now  a days Android is a most popular operating system led by Google.
In this tutorial i will show you the list of basic android programs to get you start programming in android.

Basic Steps to Develop an Android Application :

  1. Install Android SDK
  2. Install ADT Eclipse plugin
  3. Create an Android Virtual Device (AVD)
  4. Create Android Project with Eclipse (Wizard)
  5. Code it…
  6. Start it in Android Virtual Device (AVD)

Android Hello World Example :

In core Android programming if you want to write hello world program you have to create one textview and its object (here “text”).
Now set the object value as Hello Wold,as shown in below program.

HelloWorldActivity.java :

package com.example.helloworld;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView text = new TextView(this);
text.setText("Hello World");
setContentView(text);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

Run this as a Android Application 
Here, if you press “Home” button then you can see your hello world application is successfully deployed in your AVD (Android Virtual Device). 



Draw Polygons in java applet

Hello Friends, 

Today I will explain how can we draw Polygon in java applet.
In this  program I have print simple Polygon but you can draw different shapes with different size.

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

/*


*/

public class polydemo extends Applet
{
public void paint(Graphics g)
{
int xpt[]={60,30,30,30,120};
int ypt[]={90,40,180,180,30};

int num=5;
g.drawPolygon(xpt,ypt,num);
g.setColor(Color.green);
g.fillPolygon(xpt,ypt,num);
g.setColor(Color.blue);
}
}

Draw Arc in java applet

Hello Friends, 

Today I will explain how can we draw Arc in java applet.
In this  program I have print simple Arc but you can draw different shapes with different size.
    import java.applet.*;
import java.awt.*;
import java.awt.event.*;

/*


*/

public class Arcdemo extends Applet
{
public void paint(Graphics g)
{
g.drawArc(150,60,100,100,0,90);
g.setColor(Color.blue);
g.fillArc(100,60,45,60,0,90);
}
}

Draw Oval in java applet

Hello Friends, 

Today I will explain how can we draw Oval in java applet.
In this  program I have print simple Oval but you can draw different shapes with different size.
   import java.applet.*;
import java.awt.*;
import java.awt.event.*;

/*


*/

public class oval extends Applet
{
public void paint(Graphics g)
{
g.drawOval(10,10,50,50);
g.fillOval(200,30,60,100);
g.drawString("This is circle & oval.",40,90);
}
}

Draw Round corner Rectangle in java applet

Hello Friends, 

Today I will explain how can we draw Round Rectangle in java applet.
In this  program I have print simple Round Rectangle but you can draw different shapes with different size.


import java.awt.*;
import java.applet.*;
import java.awt.event.*;

/*


*/

public class twelve extends Applet
{
public void paint(Graphics g)
{

g.drawRoundRect(190,80,60,50,30,30);

g.fillRoundRect(290,20,90,70,30,30);
}
}

Draw Rectangle in java Applet

Hello Friends, 

Today I will explain how can we draw Rectangle in java applet.
In this  program I have print simple Rectangle but you can draw different shapes with different size.
    import java.awt.*;
import java.applet.*;
import java.awt.event.*;

/*


*/

public class twelve extends Applet
{
public void paint(Graphics g)
{
g.drawRect(20,200,60,50);

setForeground(Color.red);
g.fillRect(70,400,80,30);

}
}

How to draw Line in java applet?

Hello Friends, 

Today I will explain how can we draw Line in java applet.
In this  program I have print simple lines but you can draw different lines with different size.

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

/*


*/

public class twelve extends Applet
{
public void paint(Graphics g)
{
g.drawLine(10,100,10,100);
g.drawLine(20,20,20,100);
g.drawLine(30,30,30,100);
g.drawLine(40,40,40,100);
g.drawLine(50,50,50,100);


}
}

How to use Text box in java applet?

Hello Friends, 

Today I will explain how can we use Text box in java applet.
In this  program I have print simple user name & password text box…but you can create your own text box.

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

/*


*/

public class ten extends Applet implements ActionListener
{
TextField name,pass;
public void init()
{
Label namep=new Label("NAME:",Label.LEFT);
name=new TextField(15);
System.out.println("vivek");
Label passp=new Label("PASSWORD:",Label.RIGHT);
pass=new TextField(15);

pass.setEchoChar('*');

add(name);
add(pass);
add(namep);
add(passp);

name.addActionListener(this);
pass.addActionListener(this);
}

public void actionPerformed(ActionEvent ae)
{
repaint();
}

public void paint(Graphics g)
{
g.drawString("Name:"+name.getText(),6,60);
g.drawString("Selected Text Name:"+pass.getSelectedText(),6,80);
g.drawString("Password:"+pass.getText(),6,100);
}
}

How to Add Button in java applet?

Hello Friends, 

Today I will explain how can we use Button in java applet.
In this  program I have simply changed background color when button pushed.

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

/*


*/

public class nineA extends Applet
{
Button a=new Button("Click to change the color");

boolean flag=true;

public void init()
{
add(a);
}

public void paint(Graphics g)
{
if(flag)
setBackground(Color.blue);
else
setBackground(Color.red);
}

public boolean action(Event e,Object o)
{
if(e.target==a)
{
flag =! flag;
repaint();

return true;
}
return false;
}
}