Tuesday, 28 February 2017

How to use java code for type casting

//********************************Start**************************

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javaapplication1;

/**
 *
 * @author HP
 */
public class Java_Type_Casting {
 public static void main(String args[])
    {

        byte b;
        int i = 257;
        double d = 323.142;

        System.out.println("Conversion of int to byte.");
        b = (byte) i;
        System.out.println("i is " + i + " and b is " + b);

        System.out.println("\nConversion of double to int.");
        i = (int) d;
        System.out.println("d is " + d + " and i is " + i);

        System.out.println("\nConversion of double to byte.");
        b = (byte) d;
        System.out.println("d is " + d + " and b is " + b);

    }
}

//********************************End***************************

How to use Java Code for Login Form design

//*****************************Start************************

import java.awt.*;
import javax.swing.*;
/**
 *
 * @author HP
 */
public class AWT_Login_From {
    JFrame f;
    JPanel jp;
    JLabel heading,username,password,forgetpass;
    JTextField tuser;
    JPasswordField pass;
    JButton login,reset;

    public AWT_Login_From()
    {
        f=new JFrame("Login Form");
        f.setSize(400,300);
        f.setVisible(true);
        f.setLocation(500, 250);
        f.setResizable(false);
        jp=new JPanel();
        jp.setLayout(null);
        f.add(jp);


        heading=new JLabel("Login Form");
        heading.setBounds(150, 20, 150, 50);
        jp.add(heading);

        username=new JLabel("USER NAME");
        username.setBounds(60, 100, 80, 10);
        jp.add(username);

        password=new JLabel("PASSWORD");
        password.setBounds(60, 150, 80, 10);
        jp.add(password);

        forgetpass=new JLabel("Forget Password");
        forgetpass.setBounds(210, 170, 100, 10);
        jp.add(forgetpass);

        tuser=new JTextField("");
        tuser.setBounds(140,95,170,25);
        jp.add(tuser);

        pass=new JPasswordField();
        pass.setBounds(140,145,170,25);
        jp.add(pass);

        login=new JButton("Login");
        login.setBounds(60,205,100,25);
        jp.add(login);

        reset=new JButton("Reset");
        reset.setBounds(240,205,100,25);
        jp.add(reset);

     
    }
public static void main(String args[])
    {
    AWT_Login_From lf=new AWT_Login_From();


}
}


//*****************************End*************************

How to use Java Code to Print 1 to 45 In Triangle Shape...

//*************************Start**************************

public class Print_1_TO_45_In_Triangle
{
    public static void main(String args[])
    {
        int n=1, i, j;
        for(i=0; i<10; i++)
        {
            for(j=0; j<i; j++)
            {
                if(0<n&&n<10)
                {
                   System.out.print("0");
                }

                System.out.print(n + "  ");
                n++;
            }
            System.out.println();
        }
    }
}


//*************************ENd**************************

How to use Java for ShutDown Computer From using Code

//******************Start**************************

import java.io.*;

/**
 *
 * @author HP
 */
public class Shut_Down_Computer {
public static void main(String args[]) throws IOException
    {
        Runtime runtime = Runtime.getRuntime();
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        System.out.print("Enter No. of Seconds after which You want your Computer to Shutdown :");
        long a=Long.parseLong(br.readLine());

        Process proc = runtime.exec("shutdown -s -t " +a);

        System.exit(0);
    }
}


//******************End***************************

How to use Java Code Example for Try-Catch Function to Get Exception Error

//**************************Start***************************

import java.util.*;

/**
 *
 * @author HP
 */
public class try_catch {

    public static void main(String args[]) {
        int i, j;
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter any 2 no.");
        i = sc.nextInt();
        j = sc.nextInt();
        try {
            int result = i / j;
            System.out.println("Result= " + result);
        }

        catch (Exception es) {
            System.err.println(es.getMessage());
        }
    }
}


//**************************End***************************

Tuesday, 14 February 2017

How to use java code for grid program


#  Grid Demo Program



//***********************Start********************

import java.awt.*;
public class grid extends Frame {

    Button b1, b2, b3, b4,b5,b6;
    public grid() {
        setLayout(new GridLayout(3,2,5,5));
        b1 = new Button("b1");
        b2 = new Button("b2");
        b3 = new Button("b3");
        b4 = new Button("b4");
        b5 = new Button("b5");
        b6 = new Button("b6");
     
        add(b1);
        add(b2);
        add(b3);
        add(b4);
        add(b5);
        add(b6);

pack();
 setVisible(true);
   
    }
    public static void main(String arsg[]) {
        grid obj = new grid();
    }
 
}
//*************************End*****************************

How to use java code for Tree program

#  Tree Demo Program

//**************************  Start ********************

import javax.swing.*;
import java.awt.*;
import javax.swing.tree.*;

public class tree extends JFrame {

    JTree t;
    DefaultMutableTreeNode r, fy, sy, ty, s1, s2, s3, sub1;

    public tree() {
        Container c = getContentPane();
        c.setLayout(new FlowLayout());
        r = new DefaultMutableTreeNode("BSCIT");
        fy = new DefaultMutableTreeNode("FYIT");
        sy = new DefaultMutableTreeNode("SYIT");
        ty = new DefaultMutableTreeNode("TYIT");
        s1 = new DefaultMutableTreeNode("SEM 1");
        s2 = new DefaultMutableTreeNode("SEM 2");
        s3 = new DefaultMutableTreeNode("SEM 3");
        sub1 = new DefaultMutableTreeNode("C++");
        fy.add(s1);
        fy.add(s2);
        sy.add(s3);
        s1.add(sub1);
        r.add(fy);
        r.add(sy);
        r.add(ty);
      t = new JTree();
DefaultTreeCellRenderer d=(DefaultTreeCellRenderer)t.getCellRenderer();
d.setLeafIcon(new ImageIcon("MS.JPG"));
d.setOpenIcon(new ImageIcon("MS.JPG"));
d.setClosedIcon(new ImageIcon("MS.JPG"));

c.add(t);
        setSize(300,300);
        setVisible(true);


    }
     public static void main(String arsg[]) {
        tree obj = new tree();
    }
}


//**************************End**********************

How to use table demo program

#  Table Demo Program


//*************************Start**********************

import javax.swing.*;
import java.awt.*;

public class tabledemo extends JFrame {

    JTable t1;

    public tabledemo() {
        Container c = getContentPane();
        c.setLayout(new GridLayout(2, 1));
        String col[] = {"Rollno", "Name", "Class"};
        String data[][] = {{"1", "ajay", "fyit"}, {"2", "kunal", "syit"}, {"1", "sanjay", "fyit"}};
        t1 = new JTable(data, col);
        c.add(t1.getTableHeader());
        c.add(t1);
        pack();
        setVisible(true);
    }
     public static void main(String arsg[]) {
        tabledemo obj = new tabledemo();
    }
}


//*************************End***********************

How to use java tabbed pane program jsp

#   Tabbed Pane Demo program


//****************************Start******************

import javax.swing.*;
import java.awt.*;
import javax.swing.tree.*;

public class tabbed_pane extends JFrame {

    JTabbedPane t;
    JPanel p1, p2;
    JButton b1, b2;

    public tabbed_pane() {
        Container c = getContentPane();
        c.setLayout(new BorderLayout());
        t = new JTabbedPane();
        p1 = new JPanel();
        p2 = new JPanel();
        b1 = new JButton("OK");
        b2 = new JButton("Cancel");
        p1.add(b1);
        p2.add(b2);
        t.add("Tab 1", p1);
        t.add("Tab 2", p2);
        c.add(t);
        setSize(300, 300);
        setVisible(true);
    }

    public static void main(String arsg[]) {
        tabbed_pane obj = new tabbed_pane();
    }
}

//******************************End***************

How to use java swing program in jsp


#  Swingbook Demo program

//********************Start***********************


import javax.swing.*;
import java.awt.*;
public class Swingbook extends JFrame
{
    JButton b1,b2;
    public Swingbook()
    {
     
        Container c = getContentPane();
        c.setLayout(new FlowLayout());
        b1=new JButton("OK");
        b2=new JButton();
        c.add(b1);
        c.add(b2);
        b1.setText("Cancel");
       // b2.setBackground(Color.RED);
        setSize(300,300);
        setVisible(true);
 
    }


    public static void main(String[] args) {
       Swingbook aw=new Swingbook();

    }

}

//*******************************************End



How to use SQL java program in java jsp

19. SQL Demo Program

//************************Start************************
f
import java.sql.*;

public class select_st {

    public static void main(String arsg[]) {
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection con = DriverManager.getConnection("jdbc:odbc:select");
            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery("Select * from student");
            ResultSetMetaData rsmd = rs.getMetaData();
            String c1 = rsmd.getColumnName(1);
            String c2 = rsmd.getColumnName(2);
            String c3 = rsmd.getColumnName(3);
            System.out.println(c1 + "\t" + c2 + "\t" + c3);
            while (rs.next()) {
                int r = rs.getInt("rollno");
                String n = rs.getString("name");
                String c = rs.getString("class");
                System.out.println(r + "\t" + n + "\t" + c);

            }
            con.close();

        } catch (Exception e) {
            System.out.println(e);
        }
    }
}

//************************End************************


20. Split Pane Demo Program

//***********************Start************************

import javax.swing.*;
import java.awt.*;
import javax.swing.tree.*;
public class split_pane  extends JFrame  {
    JSplitPane sp;
     JButton b1, b2;
     public split_pane()
     {
          Container c = getContentPane();
        c.setLayout(new BorderLayout());
         b1 = new JButton("ok");
        b2 = new JButton("cancel");
        sp=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,b1,b2);
        c.add(sp);
         setSize(300, 300);
        setVisible(true);
     }
     public static void main(String arsg[]) {
        split_pane obj = new split_pane();
}
}

//***********************End*************************

How to use registration form in java jsp


18. Registration Form Demo In JAVA
Steps:
1.Copy program below in a text file.
2.Give File Name As "registrationform.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.

//***************************Start*******************************
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;

public class registrationform implements ActionListener {
    JFrame jf;
    JPanel jp;
    JLabel l1,l2,l3,l4,l5;
    JButton b1,b2,b3,b4;
    JTextField jf1,jf2,jf3,jf4;
    public registrationform()
    {
    jf=new JFrame("Registration Form");
    jf.setSize(400,350);
    jf.setLocation(500 ,100);
    jf.setVisible(true);
    jf.setResizable(true);

    jp=new JPanel();
    jp.setLayout(null);

    jf.add(jp);

    l1=new JLabel("First Name");
    l2=new JLabel("last Name");
    l3=new JLabel("city Name");
    l4=new JLabel("contact no");
 l5=new JLabel("Registration Form");
 l5.setFont(new Font("",Font.BOLD,20));
     l1.setBounds(50, 40, 100,50);
      l2.setBounds(50, 80, 100,50);
        l5.setBounds(110, 5, 200 ,50);
       l3.setBounds(50, 120, 100,50);
        l4.setBounds(50, 160, 100,50);
    jp.add(l1);
    jp.add(l2);
    jp.add(l3);
    jp.add(l4);
    jp.add(l5);

    jf1=new JTextField();
    jf2=new JTextField();
    jf3=new JTextField();
    jf4=new JTextField();
    jf1.setBounds(200,65,100,25);
    jf2.setBounds(200,100,100,25);
    jf3.setBounds(200,135,100,25);
    jf4.setBounds(200,170,100,25);
    jp.add(jf1);
    jp.add(jf2);
    jp.add(jf3);
    jp.add(jf4);
    b1=new JButton("sign up");
    b1.addActionListener(this);
    b1.setActionCommand("sign up");
    b1.setBounds(50,235,80,25);
    jp.add(b1);

     b3=new JButton("Update");
    b3.addActionListener(this);
    b3.setActionCommand("Update");
    b3.setBounds(140,235,80,25);
    jp.add(b3);

     b4=new JButton("Delete");
    b4.addActionListener(this);
    b4.setActionCommand("Delete");
    b4.setBounds(50,270,80,25);
    jp.add(b4);
     b2=new JButton("reset");
       b2.addActionListener(this);
    b2.setActionCommand("reset");
    b2.setBounds(235,235,80,25);
    jp.add(b2);

    }

    void reset()
    {
    jf1.setText("");
    jf2.setText("");
    jf3.setText("");
    jf4.setText("");

    }
public static void main(String arsg[])
    {
registrationform reg=new registrationform();
}

    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getActionCommand()=="sign up")
     {
    try
{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = null;

conn = (Connection)DriverManager.getConnection("jdbc:odbc:p");
conn.setAutoCommit(false);

PreparedStatement stmt=conn.prepareStatement("insert into login values('"+jf1.getText()+"','"+jf2.getText()+"','"+jf3.getText()+"','"+jf4.getText()+"');");

int result=stmt.executeUpdate();
if(result>0)
{
System.out.println("recored inserted");

}
 else
{
System.out.println("not inserted");
 }
}
catch(Exception ex){
       JOptionPane jp=new JOptionPane();
     jp.showMessageDialog(null,ex.getMessage());;
}
     JOptionPane jp=new JOptionPane();
     jp.showMessageDialog(null,"hi bro how r u");
     }

         if(e.getActionCommand()=="Update")
     {
    try
{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = null;

conn = (Connection)DriverManager.getConnection("jdbc:odbc:p");
conn.setAutoCommit(false);

PreparedStatement stmt=conn.prepareStatement("update login set firstname='"+jf1.getText()+"',lastname='"+jf2.getText()+"',city='"+jf3.getText()+"' where contact='"+jf4.getText()+"'");

int result=stmt.executeUpdate();
if(result>0)
{
System.out.println("recored updated");
}
 else
{
System.out.println("not updated");
 }
}
catch(Exception ex){
       JOptionPane jp=new JOptionPane();
     jp.showMessageDialog(null,ex.getMessage());;
}
     JOptionPane jp=new JOptionPane();
     jp.showMessageDialog(null,"hi bro how r u");
     }


         if(e.getActionCommand()=="Delete")
     {
    try
{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = null;

conn = (Connection)DriverManager.getConnection("jdbc:odbc:p");
conn.setAutoCommit(false);

PreparedStatement stmt=conn.prepareStatement("delete from login where contact='"+jf4.getText()+"'");

int result=stmt.executeUpdate();
if(result>0)
{
System.out.println("recored Deleted");
}
 else
{
System.out.println("not Deleted");
 }
}
catch(Exception ex){
       JOptionPane jp=new JOptionPane();
     jp.showMessageDialog(null,ex.getMessage());;
}
     JOptionPane jp=new JOptionPane();
     jp.showMessageDialog(null,"hi bro how r u");
     }
      if(e.getActionCommand()=="reset")
     {
    reset();
     }
    }
    }

//*****************************End******************************

How to use text field in java jsp program




14 Text Field Demo In JAVA
Steps:
1.Copy program below in a text file.
2.Give File Name As "jtextfield.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.

//***************************Start*******************************

import javax.swing.*;
import java.awt.*;
public class jtextfield extends JFrame
{
 


  TextField t1,t2,t3,t4;

public jtextfield()
{
    Container c =getContentPane();
     c.setLayout(new FlowLayout());
   t1=new TextField();
   t2=new TextField("Enter here");
   t3=new TextField(20);
   t4=new TextField("Enter here",10);
  c.add(t1);
   c.add(t2);
   c.add(t3);
   c.add(t4);
   t3.setEchoChar('*');
   setSize(300,300);
    setVisible(true);
   
 
}
public static void main(String[] args)
{
       jtextfield jt=new jtextfield();
}
}

//*****************************End******************************





15. Toolbar Demo In JAVA
Steps:
1.Copy program below in a text file.
2.Give File Name As "jtoolbar.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.

//***************************Start*******************************
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class jtoolbar extends JFrame

{
JToolBar tb;
   public jtoolbar()
   {
    Container c = new Container();
        c.setLayout(new FlowLayout());
        tb=new JToolBar();
        tb.setFloatable(false);
        tb.add(new JButton("OK"));
        tb.add(new JButton("Cancel"));
        c.add(tb,"North");
        setSize(200,200);
        setVisible(true);
   }
    public static void main(String[] args) throws Exception
    {
        jtoolbar jt=new jtoolbar();
    }
 
}
//*****************************End******************************


16. List Demo In JAVA
Steps:
1.Copy program below in a text file.
2.Give File Name As "List.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.

//***************************Start*******************************
import javax.swing.*;
import java.awt.*;

public class list extends JFrame{
    JList l;
    public list()
    {
         Container c = getContentPane();
        c.setLayout(new FlowLayout());
        String n[] = {"linux", "java", "ns"};
        l=new JList(n);
        c.add(l);
             pack();
        setVisible(true);
    }
         
    public static void main(String arsg[]) {
        list obj = new list();
    }
}

//*****************************End******************************



17. Progress Bar Demo In JAVA
Steps:
1.Copy program below in a text file.
2.Give File Name As "progress_bar.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.

//***************************Start*******************************

import javax.swing.*;
import java.awt.*;

public class progress_bar extends JFrame {

    JProgressBar pb;

    public progress_bar() {
        Container c = getContentPane();
        c.setLayout(new FlowLayout());
        pb = new JProgressBar(0, 100);
        //pb.setIndeterminate(true);
        pb.setStringPainted(true);
        pb.setBorderPainted(false);
        // pb.setString("Progress");
        c.add(pb);
        pack();
        setVisible(true);
        for (int i = 0; i <= 100; i = i + 5) {
            pb.setValue(i);
            try {
                Thread.sleep(1000);


            } catch (Exception e) {
                System.out.println(e);
            }
        }
    }

    public static void main(String arsg[]) throws Exception {
        new progress_bar();

    }
}

//*****************************End******************************

How to use RADIO Button in java jsp program




9. RadioButtonDemo Program  in Java
Steps:
1.Copy program below in a text file.
2.Give File Name As "jradiobutton.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.


//*****************************Start***********************************
import java.awt.*;
import javax.swing.*;
public class jradiobutton extends JFrame
{
   JRadioButton c1,c2,c3;
  ButtonGroup bg;
   public jradiobutton()
   {
        Container c = getContentPane();
       c.setLayout(new FlowLayout());

       bg=new ButtonGroup();
       c1=new  JRadioButton();
       c2=new  JRadioButton("B");
       c3=new  JRadioButton("c",true);
       bg.add(c1);
       bg.add(c2);
      bg.add(c3);
   
       setSize(300,300);
       setVisible(true);

    }
        public static void main(String[] args)
{
    jradiobutton rd=new jradiobutton();
}
     
}

//****************************End*************************************

10. RadioButton & MenuItem Demo Program  in Java
Steps:
1.Copy program below in a text file.
2.Give File Name As "jradiobuttonmenuitem.java"
3.Open This file Through Netbeans or JDK


4. Run File and check output.


//*****************************Start***********************************

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class jradiobuttonmenuitem extends JFrame
{
JMenuBar mb;
JMenu f,e;
JMenuItem o,s;
public jradiobuttonmenuitem()
{
mb=new JMenuBar();
f=new JMenu();
f.setMnemonic('f');
f.setText("File");
e=new JMenu("Edit");
o=new JMenuItem("Open",'o');
s=new JMenuItem("Save",'s');
f.add(o);
f.addSeparator();
f.add("OK");
e.add(s);
mb.add(f);
mb.add(e);
    setJMenuBar(mb);
    setSize(200,200);
    setVisible(true);

}
 public static void main(String[] args) {
 jradiobuttonmenuitem jm=new jradiobuttonmenuitem();

 }
 }

//****************************End*************************************


11. ScrollPane Demo In JAVA
Steps:
1.Copy program below in a text file.
2.Give File Name As "jscrollpane.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.


//*******************************Start****************************

import javax.swing.*;
import java.awt.*;
import javax.swing.tree.*;
public class jscrollpane extends JFrame
{
    JTable t;
    JScrollPane sp;
   public jscrollpane()
    {
     
        Container c = getContentPane();
        c.setLayout(new FlowLayout());
       String col[]={"Rollno","Name","Class"};
       String data[][]={{"1","ABC","FY"},{"2","XYZ","SY"},{"3","PQR","TY"}};
       t=new JTable(data,col);
       sp=new JScrollPane(t);
       c.add(sp);
        setSize(300,300);
        setVisible(true);
    }

    public static void main(String[] args) {
    jscrollpane js=new jscrollpane();

    }

}

//************************************End***************************

12. Saperator Demo In JAVA
Steps:
1.Copy program below in a text file.
2.Give File Name As "jseperator.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.


//*******************************Start****************************

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class jseperator extends JFrame

{
    public jseperator()
    {
     Container c = getContentPane();
        c.setLayout(new FlowLayout());
        JButton b1=new JButton("OK");
        JButton b2=new JButton("Cancel");
        JSeparator sp=new JSeparator(JSeparator.VERTICAL);
        sp.setPreferredSize(new Dimension(1,50));
        c.add(b1);
        c.add(sp);
        //pack();
        setSize(200,200);
        setVisible(true);

 
 
    }
     public static void main(String[] args) throws Exception
     {
     new jseperator();
     }
}

//*************************End***************************



13. Text Area Demo In JAVA
Steps:
1.Copy program below in a text file.
2.Give File Name As "jtextarea.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.


//*******************************Start****************************
import javax.swing.*;
import java.awt.*;

public class jtextarea  extends JFrame
{
 


  JTextArea t1,t2,t3,t4;

public jtextarea()
{
    Container c = getContentPane();
     c.setLayout(new FlowLayout());
   t1=new JTextArea();
   t2=new JTextArea("Enter here");
   t3=new JTextArea(10,20);
   t4=new JTextArea("java",10,10);
  c.add(t1);
   c.add(t2);
   c.add(t3);
   c.add(t4);

   setSize(300,300);
    setVisible(true);
   
 
}
public static void main(String[] args)
{
       jtextarea ja=new jtextarea();
}

}

//*************************End***************************

Monday, 13 February 2017

How to use button in java jsp code

1. Button Demo Program in Java
Steps:
1.Copy program below in a text file.
2.Give File Name As "Button_Demo.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.

//****************************Start***********************
import javax.swing.*;
import java.awt.*;

public class Button_Demo extends JFrame {

    JButton b1, b2;

    public Button_Demo() {
        Container c = getContentPane();
        c.setLayout(new FlowLayout());
        b1 = new JButton("Exit");
        b2 = new JButton("Click");
        c.add(b1);
        c.add(b2);
       // b1.setHorizontalAlignment(SwingConstants.LEFT);
               // b2.setHorizontalAlignment(SwingConstants.RIGHT);
        //b1.setHorizontalAlignment(SwingConstants.LEADING);
        b1.setVerticalAlignment(SwingConstants.BOTTOM);
        pack();
        setVisible(true);
        //b1.isVisible(false);
    }
    public static void main(String arsg[]) {
        Button_Demo obj = new Button_Demo();
    }

}


//***************************End*********************************

2. Combo Box Demo Program  in Java
Steps:
1.Copy program below in a text file.
2.Give File Name As "combobox.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.


//****************************Start*******************************
import javax.swing.*;
import java.awt.*;

public class combobox extends JFrame {

    JComboBox c1;

    public combobox() {
        Container c = getContentPane();
        c.setLayout(new FlowLayout());
        String n[] = {"X", "Y", "z"};
        c1 = new JComboBox(n);
        c1.addItem("A");
        c1.addItem("B");
        c1.addItem("C");
        c.add(c1);
        pack();
        setVisible(true);
    }

    public static void main(String arsg[]) {
        combobox obj = new combobox();
    }
}

//****************************End*******************************

3. Event Demo Program  in Java
Steps:
1.Copy program below in a text file.
2.Give File Name As "event.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.

//****************************Start*******************************
import java.awt.*;
import java.awt.event.*;

public class event extends Frame implements ActionListener {

    Button b1, b2, b3;
    Label l1;

    public event() {
        setLayout(new FlowLayout());
        b1 = new Button("Ok");
        b2 = new Button("Cancel");
        b3 = new Button("Exit");
        l1 = new Label();
        l1.setPreferredSize(new Dimension(1000,1000));
        add(b1);
        add(b2);
        add(b3);
        add(l1);

        b1.addActionListener(this);
        b2.addActionListener(this);
        b3.addActionListener(this);

        pack();
        //setSize(400, 500);
        setVisible(true);

    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource()==b1)
        {
            l1.setText("You Clicked"+b1.getLabel());
        }
        else if(e.getSource()==b2)
        {
            l1.setText("You Clicked"+b2.getLabel());
        }
          else
        {
            System.exit(0);
        }
    }
    public static void main(String arsg[]) {
         event e = new event ();
    }

}


//***************************End********************************

4. Grid Demo Program  in Java
Steps:
1.Copy program below in a text file.
2.Give File Name As "grid .java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.

//***************************Start*********************************
import java.awt.*;
public class grid extends Frame {

    Button b1, b2, b3, b4,b5,b6;
    public grid() {
        setLayout(new GridLayout(3,2,5,5));
        b1 = new Button("b1");
        b2 = new Button("b2");
        b3 = new Button("b3");
        b4 = new Button("b4");
        b5 = new Button("b5");
        b6 = new Button("b6");
     
        add(b1);
        add(b2);
        add(b3);
        add(b4);
        add(b5);
        add(b6);

pack();
 setVisible(true);
   
    }
    public static void main(String arsg[]) {
        grid obj = new grid();
    }
 
}


//*****************************End**********************************

5. Check Box Demo Program  in Java
Steps:
1.Copy program below in a text file.
2.Give File Name As "jcheckbox.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.

//*****************************Start***********************************
import javax.swing.*;
import java.awt.*;
public class jcheckbox extends JFrame
{
   JCheckBox c1,c2,c3;
   public jcheckbox()
   {
        Container c = getContentPane();
       c.setLayout(new FlowLayout());
       c1=new JCheckBox();
       c2=new JCheckBox("A");
       c3=new JCheckBox("B",true);
       c.add(c1);
       c.add(c2);
       c.add(c3);
       setSize(300,300);
       setVisible(true);
 

   }
 
 
    public static void main(String[] args)
{
       jcheckbox ch=new jcheckbox();
}
 
 
}

//******************************End**********************************


6. Editor Pane Demo Program  in Java
Steps:
1.Copy program below in a text file.
2.Give File Name As "jeditorpane.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.




//******************************Start*********************************
import javax.swing.*;
import java.awt.*;
import javax.swing.tree.*;
public class jeditorpane extends JFrame
{
   JEditorPane e;
   public jeditorpane()
    {
try
{
    e=new JEditorPane();
     add(e);
     pack();
     setVisible(true);
}
catch(Exception e)
{
    System.out.println(e);
}  
    }

 public static void main(String[] args) {
     jscrollpane jp= new jscrollpane();
 }

}

//******************************End**********************************



7. Label Demo Program  in Java
Steps:
1.Copy program below in a text file.
2.Give File Name As "jlabel.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.

//*****************************Start**********************************

import javax.swing.*;
import java.awt.*;
public class jlabel extends JFrame
{
    JLabel l1;
  public jlabel()
  {
   Container c = getContentPane();
        c.setLayout(new FlowLayout());
        l1=new JLabel("Label is used to print the message");
        c.add(l1);
        setSize(300,300);
        setVisible(true);


  }
   public static void main(String[] args) {
       jlabel jl =new jlabel();
}
}

//*****************************End***********************************

8. Panel Demo Program  in Java
Steps:
1.Copy program below in a text file.
2.Give File Name As "jpanel.java"
3.Open This file Through Netbeans or JDK
4. Run File and check output.



//*****************************Start***********************************

import javax.swing.*;
import java.awt.*;
public class jpanel {
    JPanel jp1,jp2;
    public jpanel()
    {
        jp1=new JPanel();
        jp2=new JPanel(new FlowLayout());
     
    }
     public static void main(String[] args) {
      jpanel aw=new jpanel();

    }
}

//****************************End*************************************

Charactor_At_Position

public class Char_At_Position { public static void main(String[] args) { String str = "Wankhede"; String rev=""...