Saturday, November 27, 2010

Microsoft Generation 4 Data Centerseo

You need Microsoft Silverlight Plugin to watch this video.If you don't have plugin installed then click on video to download and install plugin.


Get Microsoft Silverlight

Microsoft's Data Center ITPAC

You need Microsoft Silverlight Plugin to watch this video.If you don't have plugin installed then click on video to download and install plugin.


Get Microsoft Silverlight

Wednesday, November 24, 2010

Program to demonstrate different types of borders to use on different components


/* Program : 4
   Program to demonstrate different types of borders to use on different components
   Development Status : Completed and Tested
   Developed by : Malhar Vora
   Developed on : 20-11-2010
   Email        : vbmade2000@gmail.com
   WebSite   : www.malhar2010.blogspot.com
 *********************************************************************************/
import javax.swing.*;
import java.awt.*;
import javax.swing.border.*;

public class P4 extends JFrame
{
 //LineBorder
 JPanel paneLine = null;
 JLabel lblLine = null;
 JTextField txtLine = null;
 JButton btnLine = null;
 
 //BevelBorder
 JPanel paneBevel = null;
 JLabel lblBevel = null;
 JTextField txtBevel = null;
 JButton btnBevel = null;
 
 //EtchedBorder
 JPanel paneEtched = null;
 JLabel lblEtched = null;
 JTextField txtEtched = null;
 JButton btnEtched = null;
 
 //MatteBorder
 JPanel paneMatte = null;
 JLabel lblMatte = null;
 JTextField txtMatte = null;
 JButton btnMatte = null;
 
 //SoftBevelBorder
 JPanel paneSoftBevel = null;
 JLabel lblSoftBevel = null;
 JTextField txtSoftBevel = null;
 JButton btnSoftBevel = null;
 
 //TitledBorder
 JPanel paneTitled = null;
 JLabel lblTitled = null;
 JTextField txtTitled = null;
 JButton btnTitled = null;
 
 
 
 JTabbedPane tabMain = null;
 
 P4()
 { 
  tabMain = new JTabbedPane();
  
  //LineBorder
  paneLine = new JPanel();
  lblLine = new JLabel("Line Border");
  txtLine = new JTextField("Line Border");
  btnLine = new JButton("Line Border");
  
  //BevelBorder
  paneBevel = new JPanel();
  lblBevel = new JLabel("Bevel Border");
  txtBevel = new JTextField("Bevel Border");
  btnBevel = new JButton("Bevel Border");
  
  //EtchedBorder
  paneEtched = new JPanel();
  lblEtched = new JLabel("Etched Border");
  txtEtched = new JTextField("Etched Border");
  btnEtched = new JButton("Etched Border");
  
  //MatteBorder
  paneMatte = new JPanel();
  lblMatte = new JLabel("Matte Border");
  txtMatte = new JTextField("Matte Border");
  btnMatte = new JButton("Matte Border");
  
  //SoftBevelBorder
  paneSoftBevel = new JPanel();
  lblSoftBevel = new JLabel("SoftBevel Border");
  txtSoftBevel = new JTextField("SoftBevel Border");
  btnSoftBevel = new JButton("SoftBevel Border");
  
  //TitledBorder
  paneTitled = new JPanel();
  lblTitled = new JLabel("Titled Border");
  txtTitled = new JTextField("Titled Border");
  btnTitled = new JButton("Titled Border");
  
  //===============================================================
  //LineBorder
  paneLine.setLayout(null);
  lblLine.setBorder(new LineBorder(Color.RED,3));
  txtLine.setBorder(new LineBorder(Color.RED,3));
  btnLine.setBorder(new LineBorder(Color.RED,3));
  lblLine.setBounds(10,10,100,30);
  txtLine.setBounds(10,50,100,30);
  btnLine.setBounds(10,90,100,30);
  paneLine.add(lblLine);  
  paneLine.add(txtLine);
  paneLine.add(btnLine);
  
  //BevelBorder
  paneBevel.setLayout(null);
  lblBevel.setBorder(new BevelBorder(BevelBorder.RAISED));
  txtBevel.setBorder(new BevelBorder(BevelBorder.RAISED));
  btnBevel.setBorder(new BevelBorder(BevelBorder.RAISED));
  lblBevel.setBounds(10,10,100,30);
  txtBevel.setBounds(10,50,100,30);
  btnBevel.setBounds(10,90,100,30);
  paneBevel.add(lblBevel);  
  paneBevel.add(txtBevel);
  paneBevel.add(btnBevel);
  
  //EtchedBorder
  paneEtched.setLayout(null);
  lblEtched.setBorder(new EtchedBorder(EtchedBorder.RAISED));
  txtEtched.setBorder(new EtchedBorder(EtchedBorder.RAISED));
  btnEtched.setBorder(new EtchedBorder(EtchedBorder.RAISED));
  lblEtched.setBounds(10,10,100,30);
  txtEtched.setBounds(10,50,100,30);
  btnEtched.setBounds(10,90,100,30);
  paneEtched.add(lblEtched);  
  paneEtched.add(txtEtched);
  paneEtched.add(btnEtched);
  
  //MatteBorder
  paneMatte.setLayout(null);
  lblMatte.setBorder(new MatteBorder(5, 10, 5, 10, Color.GREEN));
  txtMatte.setBorder(new MatteBorder(5, 10, 5, 10, Color.GREEN));
  btnMatte.setBorder(new MatteBorder(5, 10, 5, 10, Color.GREEN));
  lblMatte.setBounds(10,10,100,30);
  txtMatte.setBounds(10,50,100,30);
  btnMatte.setBounds(10,90,100,30);
  paneMatte.add(lblMatte);  
  paneMatte.add(txtMatte);
  paneMatte.add(btnMatte);
  
  //SoftBevelBorder
  paneSoftBevel.setLayout(null);
  lblSoftBevel.setBorder(new SoftBevelBorder(SoftBevelBorder.RAISED));
  txtSoftBevel.setBorder(new SoftBevelBorder(SoftBevelBorder.RAISED));
  btnSoftBevel.setBorder(new SoftBevelBorder(SoftBevelBorder.RAISED));
  lblSoftBevel.setBounds(10,10,100,30);
  txtSoftBevel.setBounds(10,50,100,30);
  btnSoftBevel.setBounds(10,90,100,30);
  paneSoftBevel.add(lblSoftBevel);  
  paneSoftBevel.add(txtSoftBevel);
  paneSoftBevel.add(btnSoftBevel);
  
  //TitledBorder
  paneTitled.setLayout(null);
  lblTitled.setBorder(new TitledBorder("Label with Titled Border"));
  txtTitled.setBorder(new TitledBorder("TextField with  Border"));
  btnTitled.setBorder(new TitledBorder("Button with Titled Border"));
  lblTitled.setBounds(10,10,150,60);
  txtTitled.setBounds(10,80,150,60);
  btnTitled.setBounds(10,160,150,60);
  paneTitled.add(lblTitled);  
  paneTitled.add(txtTitled);
  paneTitled.add(btnTitled);
  
  //===============================================================================
  
  tabMain.addTab("Line Border",paneLine);
  tabMain.addTab("Bevel Border",paneBevel);
  tabMain.addTab("Etched Border",paneEtched);
  tabMain.addTab("Matte Border",paneMatte);
  tabMain.addTab("SoftBevel Border",paneSoftBevel);
  tabMain.addTab("Titled Border",paneTitled);
  
  //===============================================================================
  getContentPane().add(tabMain); 
  setTitle("Program 4 - Developed by Malhar Vora");
  setSize(400,500);
  setVisible(true);
  setDefaultCloseOperation(EXIT_ON_CLOSE);
  
 } 
 
 public static void main(String []str)
 {
   P4 p = new P4();
 }

}


Tuesday, November 23, 2010

Program to perform numerical operations like calculator using Swing components

/* Program : 15
   Program to perform numerical operations like calculator using Swing components
   Development Status : Completed and Tested
   Developed by : Malhar Vora
   Developed on : 20-11-2010
   Email        : vbmade2000@gmail.com
   WebSite  : www.malhar2010.blogspot.com
 *****************************************************************/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class P15 extends JFrame implements ActionListener
{

 
 JLabel lblFirst = null;
 JLabel lblSecond = null;
 JLabel lblResult=null;
 JTextField txtFirst =null;
 JTextField txtSecond =null;
 JTextField txtResult=null;
 JButton btnAdd=null;
 JButton btnSub=null;
 JButton btnMul=null;
 JButton btnDiv=null; 
 
 
 P15()
 {
 
  lblFirst = new JLabel("First Value");
  lblSecond = new JLabel("Second Value");
  lblResult = new JLabel("Result");
  txtFirst = new JTextField();
  txtSecond = new JTextField();
  txtResult = new JTextField();
  btnAdd = new JButton("+");
  btnSub = new JButton("--");
  btnMul = new JButton("X");
  btnDiv = new JButton("/");
  
  
  setTitle("Program 15 - Developed by Malhar Vora");
  setSize(280,250);
  setVisible(true);
  setDefaultCloseOperation(EXIT_ON_CLOSE);
  setLayout(null);
  
  lblFirst.setBounds(20,10,100,50);
  txtFirst.setBounds(110,20,100,30);
  lblSecond.setBounds(20,50,100,50);
  txtSecond.setBounds(110,60,100,30);
  lblResult.setBounds(20,90,100,50);
  txtResult.setBounds(110,100,100,30);
  btnAdd.setBounds(20,150,50,50);
  btnSub.setBounds(80,150,50,50);
  btnMul.setBounds(140,150,50,50);
  btnDiv.setBounds(200,150,50,50);
  txtResult.setEditable(false);
  
  
  
  getContentPane().add(lblFirst);
  getContentPane().add(txtFirst);
  getContentPane().add(lblSecond);
  getContentPane().add(txtSecond);
  getContentPane().add(lblResult);
  getContentPane().add(txtResult);
  getContentPane().add(btnAdd);
  getContentPane().add(btnSub);
  getContentPane().add(btnMul);
  getContentPane().add(btnDiv);
  
  
  btnAdd.addActionListener(this);
  btnSub.addActionListener(this);
  btnMul.addActionListener(this);
  btnDiv.addActionListener(this);
  
  
      
 }
 
 public void actionPerformed(ActionEvent ae)
 {
  String cmd = ae.getActionCommand();
  
  if(cmd.equals("+"))
  {
    int a,b,c;
    a = Integer.parseInt(txtFirst.getText());
    b = Integer.parseInt(txtSecond.getText());
    c = a+b;
    txtResult.setText("" + c);    
  }
  else if(cmd.equals("--"))
  {
    int a,b,c;
    a = Integer.parseInt(txtFirst.getText());
    b = Integer.parseInt(txtSecond.getText());
    c = a-b;
    txtResult.setText("" + c);  
  }
  else if(cmd.equals("X"))
  {
    int a,b,c;
    a = Integer.parseInt(txtFirst.getText());
    b = Integer.parseInt(txtSecond.getText());
    c = a*b;
    txtResult.setText("" + c);  
  }
  else if(cmd.equals("/"))
  {
    int a,b,c;
    try
    {
      a = Integer.parseInt(txtFirst.getText());
      b = Integer.parseInt(txtSecond.getText());
      c = a/b;
      txtResult.setText("" + c);  
    }
    catch(Exception e)
    {
      txtResult.setText("Error in division");
    }
  }
 }
 
 
 
 public static void main(String []str)
 {
  P15 p = new P15();
 }
}

Saturday, November 20, 2010

Program to implement the concept of creating Treeview



/* Program : 13
   Program to implement the concept of creating Treeview according to your marks of each subject of each semester under Gujarat Technological University,Ahmedabad
   Development Status : Completed and Tested
   Developed by : Malhar Vora
   Developed on : 20-11-2010
   Email        : vbmade2000@gmail.com
   WebSite  : www.malhar2010.blogspot.com
 ***********************************************************************************************************************************************/
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.tree.*;
import java.awt.*;
import java.awt.event.*;

public class P13 extends JFrame 
{
 
 
 JTree mainTree = null;
 
 //GTU Node
 DefaultMutableTreeNode rootNode=null;
 
 //Semester Nodes
 DefaultMutableTreeNode nodeSem1=null;
 DefaultMutableTreeNode nodeSem2=null;
 DefaultMutableTreeNode nodeSem3=null;
 
 //First Sem Subjects
 DefaultMutableTreeNode nodePlSql=null;
 DefaultMutableTreeNode nodeAccount=null;
 DefaultMutableTreeNode nodeCPractical=null;
 DefaultMutableTreeNode nodeFop=null;
 DefaultMutableTreeNode nodeFco=null;
 DefaultMutableTreeNode nodeDm=null;
 DefaultMutableTreeNode nodeDbms=null;
 
 //Second Sem Subjects
 DefaultMutableTreeNode nodeToc=null;
 DefaultMutableTreeNode nodeConm=null;
 DefaultMutableTreeNode nodeCpp=null;
 DefaultMutableTreeNode nodeCppPractical=null;
 DefaultMutableTreeNode nodeDBMS2=null;
 DefaultMutableTreeNode nodeDs=null;
 DefaultMutableTreeNode nodeDsPractical=null;
 
 //Third Sem Subjects
 DefaultMutableTreeNode nodeJava=null;
 DefaultMutableTreeNode nodeJavaPractical=null;
 DefaultMutableTreeNode nodeConsm=null;
 DefaultMutableTreeNode nodeSs=null;
 DefaultMutableTreeNode nodeOs=null;
 DefaultMutableTreeNode nodeOsPractical=null;
 DefaultMutableTreeNode nodeSoodam=null;
 
 
 
 P13()
 {
 
  rootNode = new DefaultMutableTreeNode ("Gujarat Technological University");
  
  nodeSem1 = new DefaultMutableTreeNode ("Semester 1");
  nodeSem2 = new DefaultMutableTreeNode ("Semester 2");
  nodeSem3 = new DefaultMutableTreeNode ("Semester 3");
  
  //First Sem Nodes
  nodePlSql = new DefaultMutableTreeNode ("PLSQL");
  nodeAccount = new DefaultMutableTreeNode ("Account and ERP");
  nodeCPractical = new DefaultMutableTreeNode ("C Practical");
  nodeFop = new DefaultMutableTreeNode ("FOP");
  nodeFco = new DefaultMutableTreeNode ("FCO");
  nodeDm = new DefaultMutableTreeNode ("Discrete Mathematics");
  nodeDbms = new DefaultMutableTreeNode ("DBMS");
  
  
  //Second Sem Nodes
  nodeToc = new DefaultMutableTreeNode ("TOC");
  nodeConm = new DefaultMutableTreeNode ("CONM");
  nodeCpp= new DefaultMutableTreeNode ("C++");
  nodeCppPractical = new DefaultMutableTreeNode ("CPP Practical");
  nodeDBMS2 = new DefaultMutableTreeNode ("DBMS");
  nodeDs = new DefaultMutableTreeNode ("Data Structures");
  nodeDsPractical= new DefaultMutableTreeNode ("Data Structures Practical");
  
  //Third Sem Nodes
  nodeJava = new DefaultMutableTreeNode ("Java");
  nodeJavaPractical= new DefaultMutableTreeNode ("Java Practical");
  nodeConsm= new DefaultMutableTreeNode ("CONSM");
  nodeSs = new DefaultMutableTreeNode ("System Software");
  nodeOs = new DefaultMutableTreeNode ("Operating System");
  nodeOsPractical = new DefaultMutableTreeNode ("OS Practical");
  nodeSoodam = new DefaultMutableTreeNode ("SOODAM");
  
  
  //Adding first sem nodes to 1st sem main node
  nodePlSql.add(new DefaultMutableTreeNode("40"));
  nodeSem1.add(nodePlSql);
  
  nodeAccount.add(new DefaultMutableTreeNode("40"));
  nodeSem1.add(nodeAccount);
  
  nodeCPractical.add(new DefaultMutableTreeNode("70"));
  nodeSem1.add(nodeCPractical);
  
  nodeFop.add(new DefaultMutableTreeNode("45"));
  nodeSem1.add(nodeFop);
  
  nodeFco.add(new DefaultMutableTreeNode("50"));
  nodeSem1.add(nodeFco);
  
  nodeDm.add(new DefaultMutableTreeNode("30"));
  nodeSem1.add(nodeDm );
  
  nodeDbms.add(new DefaultMutableTreeNode("20"));
  nodeSem1.add(nodeDbms);
  
  
  
  //Adding second sem nodes to 2nd sem main node
  nodeToc.add(new DefaultMutableTreeNode("20"));
  nodeSem2.add(nodeToc);
  
  nodeConm.add(new DefaultMutableTreeNode("50"));
  nodeSem2.add(nodeConm );
  
  nodeCpp.add(new DefaultMutableTreeNode("57"));
  nodeSem2.add(nodeCpp);
  
  nodeCppPractical.add(new DefaultMutableTreeNode("37"));
  nodeSem2.add(nodeCppPractical);
  
  nodeDBMS2.add(new DefaultMutableTreeNode("35"));
  nodeSem2.add(nodeDBMS2);
  
  nodeDs.add(new DefaultMutableTreeNode("10"));
  nodeSem2.add(nodeDs);
  
  nodeDsPractical.add(new DefaultMutableTreeNode("20"));
  nodeSem2.add(nodeDsPractical);
  
  
  
  //Adding third sem nodes to 3rd sem main node
  nodeJava.add(new DefaultMutableTreeNode("35"));
  nodeSem3.add(nodeJava);
  
  nodeJavaPractical.add(new DefaultMutableTreeNode("35"));
  nodeSem3.add(nodeJavaPractical);
  
  nodeConsm.add(new DefaultMutableTreeNode("35"));
  nodeSem3.add(nodeConsm);
  
  nodeSs.add(new DefaultMutableTreeNode("35"));
  nodeSem3.add(nodeSs);
  
  nodeOs.add(new DefaultMutableTreeNode("35"));
  nodeSem3.add(nodeOs);
  
  nodeOsPractical.add(new DefaultMutableTreeNode("35"));
  nodeSem3.add(nodeOsPractical);
  
  nodeSoodam.add(new DefaultMutableTreeNode("35"));
  nodeSem3.add(nodeSoodam);
  
  
  
  rootNode.add(nodeSem1);
  rootNode.add(nodeSem2);
  rootNode.add(nodeSem3);
  
  mainTree = new JTree(rootNode);
  
  setSize(400,500);
  setDefaultCloseOperation(EXIT_ON_CLOSE);
  setTitle("Program 13 - Developed by Malhar Vora");
  setVisible(true);
  
  this.getContentPane().add(mainTree);
    
 }
 
 
 public static void main(String []str)
 {
  P13 p = new P13(); 
 }

 
}



Program to demonstrate the concept of ListBox and ComboBox

/* Program : 11
   Program to demonstrate the concept of ListBox and ComboBox
   Development Status : Completed and Tested
   Developed by : Malhar Vora
   Developed on : 20-11-2010
   Email        : vbmade2000@gmail.com
   WebSite  : www.malhar2010.blogspot.com
 *****************************************************************/
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;

public class P11 extends JFrame implements ListSelectionListener
{
 
 JList lstCountry = null;
 JComboBox cboCity = null;
 JScrollPane listPane=null;
 String[] strCountry={ "India","USA","UK"};

 String[] strIndia={"Bombay","Ahmedabad"};
 String[] strUsa={"Chikago","Washington DC"};
 String[] strUk={"London","Manchester"};
    
 DefaultListModel model = null;
 DefaultComboBoxModel modelIndia = null;
 DefaultComboBoxModel modelUsa = null;
 DefaultComboBoxModel modelUk = null;
 
 P11()
 {
  
  
  lstCountry = new JList();
  cboCity  = new JComboBox();
  listPane = new JScrollPane(lstCountry);
  model = new DefaultListModel();
  
  modelIndia = new DefaultComboBoxModel(strIndia);
  modelUsa = new DefaultComboBoxModel(strUsa);
  modelUk = new DefaultComboBoxModel(strUk);
  
    
  setTitle("Program 11 - Developed by Malhar Vora");
  setSize(250,300);
  setDefaultCloseOperation(EXIT_ON_CLOSE);
  setVisible(true);
  setLayout(null);
  
  listPane.setBounds(10,50,200,100);
  cboCity.setBounds(10,170,200,30);
    
  this.getContentPane().add(listPane);
  this.getContentPane().add(cboCity);
    
  model.addElement("India");
  model.addElement("USA");
  model.addElement("UK");
    
  lstCountry.setModel(model);
  lstCountry.setSelectionMode(0);
  lstCountry.addListSelectionListener(this);
  
     
 }
 
 public void valueChanged(ListSelectionEvent e)
 {
  String selectedCountry = (String)lstCountry.getSelectedValue();
  
  if(selectedCountry.equals("India"))
  {
   cboCity.setModel(modelIndia);
  }
  else if(selectedCountry.equals("USA"))
  {
   cboCity.setModel(modelUsa);
  }
  else if(selectedCountry.equals("UK"))
  {
   cboCity.setModel(modelUk);
  }
  else
  {
   cboCity.setModel(null);
  }
 }
 
 public static void main(String []str)
 {
  P11 p = new P11();    
 }


}



Thursday, November 18, 2010

Develop a Java application to demonstrate the use of adapter classes


/* Program : 22 
   Develop a Java application to demonstrate the use of adapter classes  
   Developed by : Malhar Vora
   Developed on : 11-11-2010
   Development Status : Completed and tested
   Email     : vbmade2000@gmail.com
   WebSite   : www.malhar2010.blogspot.com
*******************************************************************************************************************/
import javax.swing.*;
import java.awt.event.*;

public class P22 extends JFrame
{
 
 JLabel lblMsg=null;
 P22()
 {
  setSize(400,300);
  setTitle("Prorgam 22 - Developed by Malhar Vora");
  setDefaultCloseOperation(EXIT_ON_CLOSE);
  setVisible(true);
  setLayout(null);
  
  lblMsg = new JLabel("Message will be displayed here");
  
  lblMsg.setBounds(10,10,300,100);
  
  this.getContentPane().add(lblMsg); 
  
  MouseHandler mHandle = new MouseHandler();
  addMouseListener(mHandle);
  
 }
 
 class MouseHandler extends MouseAdapter
 {
  public void mousePressed(MouseEvent me)
  {
   lblMsg.setText("Mouse Pressed");
  }
  
  public void mouseReleased(MouseEvent me)
  {
   lblMsg.setText("Mouse Released");
  }
 }
 
 public static void main(String []str)
 {
  P23 p = new P23();
 }

}


Wednesday, November 17, 2010

Develop a Java application to demonstrate the use WindowEvent class


/* Program : 21 
   Develop a Java application to demonstrate the use WindowEvent class  
   Developed by : Malhar Vora
   Developed on : 5-11-2010
   Development Status : Completed and tested
   Email     : vbmade2000@gmail.com
   WebSite   : http://technojungle.co.cc
*******************************************************************************************************************/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


public class P21 extends JFrame implements WindowListener
{
 
  JLabel lblStatus=null;
 
  P21()
  {
   
   lblStatus = new JLabel("Message will be printed here");
   
   setSize(400,500);
   setVisible(true);
   setLayout(null);
   setDefaultCloseOperation(EXIT_ON_CLOSE);
   
   lblStatus.setBounds(50,50,200,50);
   this.getContentPane().add(lblStatus);
   
   addWindowListener(this);
  }
  
  public void windowActivated(WindowEvent we)
  {
   lblStatus.setText("Window Activated");
  }
  
  public void windowDeactivated(WindowEvent we)
  {
   lblStatus.setText("Window Deactivated");
  }
  
  public void windowOpened(WindowEvent we)
  {
   lblStatus.setText("Window Opened");
  }
  
  public void windowClosed(WindowEvent we)
  {
   lblStatus.setText("Window Closed");
  }
  
  public void windowIconified(WindowEvent we)
  {
   lblStatus.setText("Window Iconified");
  }
  
  public void windowDeiconified(WindowEvent we)
  {
   lblStatus.setText("Window Deiconified");
  }
  
  public void windowClosing(WindowEvent we)
  {
   lblStatus.setText("Window Closing");
  }
  public static void main(String []str)
  {
   P21 p = new P21();
  }
   
}

Monday, November 15, 2010

A Java application to display a moving banner "Wel-Come to SVICS"

/* Program : 14 
   Develop a Java application to display a moving banner "Wel-Come to SVICS"
   Developed by : Malhar Vora
   Developed on : 5-11-2010
   Development Status : Completed and tested
   Email     : vbmade2000@gmail.com
   WebSite   : www.malhar2010.blogspot.com
*************************************************************/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class P14 extends JFrame 
{
 
 JLabel lblMsg=null;
    
 P14()
 {
   lblMsg = new JLabel("Wel-Come to SVICS");
   setSize(1000,150);
   setVisible(true);
   setTitle("Program 14 - Developed by Malhar Vora");
   setResizable(false);
   setLayout(null);
   setDefaultCloseOperation(EXIT_ON_CLOSE);
   
   lblMsg.setBounds(5,10,400,100); 
   lblMsg.setFont(new Font("Arial",Font.BOLD,30));
   lblMsg.setForeground(Color.RED);
      
   this.getContentPane().add(lblMsg);
   blink();
   
 }
   
 void blink()
 {
   
   while(true)
   {
    if(lblMsg.getLocation().getX()==1000)
    {
     lblMsg.setLocation(-260,(int)lblMsg.getLocation().getY());
    }
    lblMsg.setLocation((int)lblMsg.getLocation().getX()+5,(int)lblMsg.getLocation().getY());
    try{
       Thread.currentThread().sleep(100);
    }
    catch(Exception e)
    {
     ;
    }
   }
  
 }
    
 
 public static void main(String []str)
 {
  P14 p = new P14();
  p.setTitle("Program 14 - Developed by Malhar Vora");
 }
}

Write a program to read an alphanumeric from user and check whether entered alphanumeric is (1) Capital Alphabet (2) Small Alphabet (3) Number

/* Write a program to read an alphanumeric from user and check whether entered alphanumeric is (1) Capital Alphabet (2) Small Alphabet (3) Number
   Developed by : Malhar Vora
   Developed on : 15-11-2010
   Development Status : Completed and tested
   Email : vbmade2000@gmail.com
   WebSite : www.malhar2010.blogspot.com
**************************************************************************/
void main()
{

 char c;
 printf("Enter any alphanumeric character :");
 scanf("%c",&c);

 if(c>=48 && c<=57)
 {
        printf("Number");
        return;
 }
 else if(c>=65 && c<=91)
 {
        printf("Capital alphabet");
        return;
 }
 else if(c>=97 && c<=123)
 {
        printf("Small Alphabet");
        return;
 }
 else
 {
        printf("Unknown symbol");
        return;
 }

}

A program to read an integer no recursively until the user enters negative numbers

/* Write a program to read an integer no recursively until the user enters negative numbers
   and find the sum of nos entered by the user
   Developed by : Malhar Vora
   Developed on : 15-11-2010
   Development Status : Completed and tested
   Email : vbmade2000@gmail.com
   WebSite : www.malhar2010.blogspot.com
********************************************************************************************/
int a=0,sum=0;

void main()
{
   printf("Enter no :");
   scanf("%d",&a);

   if(a<0)
   {
 printf("Sum is : %d",sum);
 return;
   }
   else
   {
 sum = sum + a;
   }
   main();

}

A program to accept nos from user till their sum exceeds 50


/* Write a program to accept nos from user till their sum exceeds 50
   Developed by : Malhar Vora
   Developed on : 15-11-2010
   Development Status : Completed and tested
   Email : vbmade2000@gmail.com
   WebSite : www.malhar2010.blogspot.com
********************************************************************************************/

void main()
{

    int a=0,sum=0;

    test:
   if(sum>=50)
   {
  printf("Sum exceeds 50");
  return;
   }
   printf("Enter no:");
   scanf("%d",&a);

   sum=sum + a;
   goto test;

}

A program to get a no from user and find the sum of its odd digits

/* Write a program to get a no from user  and find the sum of its odd digits
   Developed by : Malhar Vora
   Developed on : 15-11-2010
   Development Status : Completed and tested
   Email : vbmade2000@gmail.com
   WebSite : www.malhar2010.blogspot.com
**********************************************************************************/   
void main()
{

 int a=0,temp=0,sum=0;
 printf("Enter no :");
 scanf("%d",&a);
 if(a==0)
 {
     printf("No can't be 0");
     return;
 }

 //Label test
 test:
  if(a==0)
  {
       printf("Sum is :%d",sum);
       return;
  }

  temp=a%10;
  if(temp%2!=0)
  {
       sum=sum+temp;
  }
  a=a/10;
  goto test;

}

Sunday, November 14, 2010

Calling conventions demystified

Calling conventions is important concepts in computer languages. It defines a way in which parameters are transferred between one functions when one function calls another. There are the major types of parameter passing.

1) Call by Value:-
In this mechanism, a copy of each actual parameter is passed to a called function and stored into a corresponding formal parameter. So if a called function modifies the formal parameter, it does not affect the actual parameter or say the originally passed values. Here since the mechanism only copies data from the caller, the actual parameter can be any expression or variable.


void increment(int a)
{
      a++;
}

main()
{
 int p=10;
 increment (p);
 printf(“%d”,p);
}


In above C program value of variable p will remain 10 because when we call function increment(), copy of value of variable p will be copied to local variable a of function increment(). So value of p will not be affected. In Java it is default mechanism.

2) Call by reference:-
In this mechanism, a caller passes the reference of each actual parameter. So the caller function and called function both works on same copy of data. When a called function modifies the value of formal parameter, originally passed actual parameter is also affected because both working on same data. This mechanism performs better compared to Call by value .In C pointers can be used to use this mechanism. It can be used when large object has to be passed as function argument to save memory. When using this mechanism only variable can be passed and expression can’t be passed. In C++ a const keyword can be used to use this mechanism with constraint that value should not be modified.

void print(int const& x)
{
      x = 2; // This is not allowed.
      cout << x ;
}



Example C function

void increment(int *a)
{
     (*a)++;
}

main()
{
    int b=10;
    increment (&b);
    printf("%d",b);
}


In above program, a value of variable b will be 11 because we have passed reference of b and so in turn function increment() works on same copy.

3) Call by value-result:-
This mechanism can be said as a combination of both Call by value and Call by reference. In this mechanism same like Call by value copy of actual parameter is passed to a corresponding formal parameter. If called function modifies a formal parameter, actual parameter is not affected but when function returns, the value of formal parameter is copied back to actual parameter. Here also like Call by reference, the called function copies data to called function parameter, the passed value can only be variable and not any expression. This mechanism is available in Ada.



Other mechanisms like call by copy-restore, call by need , call by name are also available but they are not widely used.

A Program to enter a 4 digit integer from user and display it in characters without using loop and functions ( e.g 1654 = One Six Five Four )

/*Program to get 4 digit integer rom user and display each digit in character ( e.g 1545 should be displayed as One Five Four Five )
  Developed by : Malhar Vora
  Development Status : Completed and Tested
  Developed on : 14/11/2010
  Email : vbmade2000@gmail.com
  Web Site : www.malhar2010.blogspot.com
***********************************************************************************/  
void main()
{

 int a=0,temp=0,divisor=1000,temp1=0;

 printf("Enter no:");
 scanf("%d",&a);

 test:
  if(divisor==0)
  {
      return;
  }

  temp=a/divisor;
  divisor=divisor/10;
  temp1=temp%10;

  switch(temp1)
  {
   case 1:
    printf("One");
    break;
   case 2:
    printf("Two");
    break;
   case 3:
    printf("Three");
    break;
   case 4:
    printf("Four");
    break;
   case 5:
    printf("Five");
    break;
   case 6:
    printf("Six");
    break;
   case 7:
    printf("Seven");
    break;
   case 8:
    printf("Eight");
    break;
   case 9:
    printf("Nine");
   case 0:
    printf("Zero");
    break;
  }
  goto test;

}

Create an application which will implement the concept of JRadioButton to change the text into TextArea according to the selected Radio options.


/* Program : 10 
   Create an application which will implement the concept of JRadioButton to change the text into TextArea according to the selected Radio options.
   Developed by : Malhar Vora
   Developed on : 5-11-2010
   Development Status : Completed and tested
   Email     : vbmade2000@gmail.com
   WebSite   : http://technojungle.co.cc
*******************************************************************************************************************/
import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.awt.event.*;

public class P10 extends JFrame implements ActionListener
{

 ButtonGroup rdoGroup=null;
 JRadioButton rdoSenCase=null;
 JRadioButton rdoLowerCase=null;
 JRadioButton rdoUpperCase=null;
 JRadioButton rdoTitleCase=null;
 JRadioButton rdoToggleCase=null;
 JTextField txtData=null;
 
    P10()
 {
   
   rdoSenCase = new JRadioButton("Sentence case");
   rdoLowerCase = new JRadioButton("lowercase");
   rdoUpperCase = new JRadioButton("UPPERCASE");
   rdoTitleCase = new JRadioButton("Title Case");
   rdoToggleCase = new JRadioButton("tOOGLE cASE");
   rdoGroup = new ButtonGroup();
   txtData = new JTextField("Enter your text here");
   
   rdoGroup.add(rdoSenCase);
   rdoGroup.add(rdoLowerCase );
   rdoGroup.add(rdoUpperCase);
   rdoGroup.add(rdoTitleCase);
   rdoGroup.add(rdoToggleCase);
   
   
   rdoSenCase.addActionListener(this); 
   rdoLowerCase.addActionListener(this);
   rdoUpperCase.addActionListener(this);
   rdoTitleCase .addActionListener(this);
   rdoToggleCase.addActionListener(this);
   
   setLayout(null);
   txtData.setBounds(50,50,300,30);
   rdoSenCase.setBounds(50,90,200,30);
   rdoLowerCase.setBounds(50,120,200,30);
   rdoUpperCase.setBounds(50,150,200,30);
   rdoTitleCase.setBounds(50,180,200,30);
   rdoToggleCase.setBounds(50,210,200,30);

   this.getContentPane().add(txtData); 
   this.getContentPane().add(rdoSenCase); 
   this.getContentPane().add(rdoLowerCase); 
   this.getContentPane().add(rdoUpperCase); 
   this.getContentPane().add(rdoTitleCase); 
   this.getContentPane().add(rdoToggleCase); 
      
   setTitle("Program 10 - Developed by Malhar Vora");
   setSize(380,300);
   setVisible(true);
   setDefaultCloseOperation(EXIT_ON_CLOSE);      
 }
  
  
 public void actionPerformed(ActionEvent ae)
 {
   String cmd=ae.getActionCommand();
   if(txtData.getText().equals(""))
   {
    JOptionPane.showMessageDialog(this,"Please enter some text","Error",JOptionPane.ERROR_MESSAGE);
    return;
   }
   
   if(cmd.equals("lowercase"))
   {
    txtData.setText(txtData.getText().toLowerCase());
   }
   else if(cmd.equals("UPPERCASE"))
   {
    txtData.setText(txtData.getText().toUpperCase());
   }
   else if(cmd.equals("Sentence case"))
   {
    String temp="";
    temp = temp + Character.toUpperCase(txtData.getText().charAt(0));
    
    for(int i=1;i<txtData.getText().length();i++)
    {
     temp = temp + Character.toLowerCase(txtData.getText().charAt(i));
    } 
    
    txtData.setText(temp);   
         
   }
   else if(cmd.equals("tOOGLE cASE"))
   {
    String temp="";
        
    for(int i=0;i<txtData.getText().length();i++)
    {
     if(Character.isUpperCase(txtData.getText().charAt(i)))
     {
      temp = temp + Character.toLowerCase(txtData.getText().charAt(i));
     }
     else
     {
      temp = temp + Character.toUpperCase(txtData.getText().charAt(i));
     }
    } 
    txtData.setText(temp); 
   }
   else if(cmd.equals("Title Case"))
   {
     
    StringTokenizer st = new StringTokenizer(txtData.getText()," ");
    String tempToken="";
    txtData.setText("");
    while(st.hasMoreTokens())
    {
      tempToken = st.nextToken(); 
      txtData.setText(txtData.getText() + titleCase(tempToken) + " ");             
    }
     
    
   }
   
   
   
 } 
 
 String titleCase(String str)
 {
    
    String temp="";
    temp = temp + Character.toUpperCase(str.charAt(0));
    
    for(int i=1;i<str.length();i++)
    {
     temp = temp + Character.toLowerCase(str.charAt(i));
    } 
    return temp;
    
 }
 public static void main(String []str)
 {
   P10 p = new P10();
 }  


}




  

Friday, November 12, 2010

Create an application that will demonstrate the concept of ProgressBar.

/* Program : 8
   Create an application that will demonstrate the concept of ProgressBar.
   Developed by : Malhar Vora
   Developed on : 9-11-2010
   Development Status : Completed and tested
   Email     : vbmade2000@gmail.com
   WebSite   : www.malhar2010.blogspot.com
*******************************************************************************************************************/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


public class P8 extends JFrame implements ActionListener
{
 
 JProgressBar pBar=null;
 JButton btnStart=null;
 JButton btnStop=null;
 MakeProgress mp=null;
 
 boolean stop=false;
 
 P8()
 {
   //Setting properties of Frame
   setSize(400,200);
   setResizable(false);
   setTitle("Progressbar Demo");
   setDefaultCloseOperation(EXIT_ON_CLOSE);
   setVisible(true);
   this.getContentPane().setLayout(null);
   
   pBar = new JProgressBar(0,100);
   pBar.setBounds(10,10,360,40);
   pBar.setStringPainted(true);
   
   btnStart = new JButton("Start");
   btnStop = new JButton("Stop");
   
   btnStart.setBounds(10,80,100,50);
   btnStop.setBounds(120,80,100,50);
   
   this.getContentPane().add(pBar);
   this.getContentPane().add(btnStart);
   this.getContentPane().add(btnStop);
   
   btnStart.addActionListener(this);
   btnStop.addActionListener(this);
      
   //makeProgress();
   mp = new MakeProgress();
 }
 
 public void  actionPerformed(ActionEvent ae)
 {
   String cmd = ae.getActionCommand();
   if(cmd.equals("Start"))
   {
     stop=false; 
     
   }
   else if(cmd.equals("Stop"))
   {
     stop=true;           
   }
 }
  
 class MakeProgress extends Thread
 {
  
  
  MakeProgress()
  {
   start();
  }  
  public void run()
  {
   while(true)
   {
    if(stop==true)
    {
    
     try{
       wait();
     }
     catch(Exception e)
     {
       ;
     }
    }
    else
    {
     if(pBar.getValue()==100)
     {
      pBar.setValue(0);
     }
     pBar.setValue(pBar.getValue()+1);
     pBar.setString("" + pBar.getValue());
    
     try{
       sleep(2000);
     }
     catch(InterruptedException ie){
       ;
     } 
    }
   }
  
  }
 
 }
 
 public static void main(String []str)
 {
  P8 p = new P8();
 }
 

}


Thursday, November 11, 2010

Create an application that shows the usage of SliderBar to imlpement the RGBcolored label

/* Program : 7
   Create an application that shows the usage of SliderBar to imlpement the RGBcolored label
   Developed by : Malhar Vora
   Developed on : 9-11-2010
   Development Status : Completed and tested
   Email     : vbmade2000@gmail.com
   WebSite   : www.malhar2010.blogspot.com
*******************************************************************************************************************/
import javax.swing.*;
import java.awt.*;
import javax.swing.event.*;

public class P7 extends JFrame implements ChangeListener
{

 JSlider sliderRed=null;
 JSlider sliderGreen=null;
 JSlider sliderBlue=null;
 JLabel lblRed=null;
 JLabel lblGreen=null;
 JLabel lblBlue=null;
 JLabel lblColor=null;
 Color colorFrame=null;
 
 P7()
 {
  
 
  sliderRed = new JSlider(JSlider.HORIZONTAL, 0, 255, 0);
  sliderGreen = new JSlider(JSlider.HORIZONTAL, 0, 255, 0);
  sliderBlue = new JSlider(JSlider.HORIZONTAL, 0, 255, 0);
  
  lblRed = new JLabel("Red");
  lblGreen = new JLabel("Green");
  lblBlue = new JLabel("Blue");
  lblColor = new JLabel("My color changes");
  
  //Setting properties of JFrame
  setTitle("Program 7 - Developed by Malhar Vora");
  setSize(400,500);
  setDefaultCloseOperation(EXIT_ON_CLOSE);
  setVisible(true); 
  setResizable(false);
  this.getContentPane().setLayout(new GridLayout(7,1));
  
  
  //Adding controls to JFrame
  this.getContentPane().add(lblColor);
  this.getContentPane().add(lblRed);
  this.getContentPane().add(sliderRed);
  this.getContentPane().add(lblGreen);
  this.getContentPane().add(sliderGreen);
  this.getContentPane().add(lblBlue);
  this.getContentPane().add(sliderBlue);
  
  
  //Setting properties of JSliders
  sliderRed.setMajorTickSpacing(25); //For sliderRed
  sliderRed.setPaintLabels(true);
  sliderRed.setPaintTicks(true);
  sliderRed.setPaintTrack(true);
  sliderGreen.setMajorTickSpacing(25);  //For sliderGreen
  sliderGreen.setPaintLabels(true);
  sliderGreen.setPaintTicks(true);
  sliderGreen.setPaintTrack(true);
  sliderBlue.setMajorTickSpacing(25);  //For sliderBlue
  sliderBlue.setPaintLabels(true);
  sliderBlue.setPaintTicks(true);
  sliderBlue.setPaintTrack(true);
  
  sliderRed.addChangeListener(this);
  sliderGreen.addChangeListener(this);
  sliderBlue.addChangeListener(this);
   
 }
 
 public void stateChanged(ChangeEvent ce)
 {
   colorFrame = new Color(sliderRed.getValue(),sliderGreen.getValue(),sliderBlue.getValue());   
   lblColor.setForeground(colorFrame); 
 }
 
 public static void main(String []str)
 {
  P7 p =new P7();
 }

}
 

Write an application which will create a popup menu with different menuitems and set the label according to menutem

/* Program : 6 
   Write an application which will create a popup menu with different menuitems and set the label according to menutem
   Developed by : Malhar Vora
   Developed on : 8-11-2010
   Development Status : Completed and tested
   Email     : vbmade2000@gmail.com
   WebSite   : www.malhar2010.blogspot.com
*******************************************************************************************************************/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


public class P6 extends JFrame implements ActionListener
{


 JPopupMenu mnuContext = null;
 JMenuItem mnu1 = null;
 JMenuItem mnu2 = null;
 JMenuItem mnu3 = null;
 JMenuItem mnu4 = null;
 
 P6()
 {
  
  setTitle("Program 6 - Developed by Malhar Vora");
  setSize(400,300);
  setDefaultCloseOperation(EXIT_ON_CLOSE);
  setVisible(true);
  
  mnu1 = new JMenuItem("Abc");
  mnu2 = new JMenuItem("bbc");
  mnu3 = new JMenuItem("pqr");
  mnu4 = new JMenuItem("xyz");
  
  mnuContext = new JPopupMenu();
  mnuContext.add(mnu1);
  mnuContext.add(mnu2);
  mnuContext.add(mnu3);
  mnuContext.add(mnu4);
  
  PopupListener pl = new PopupListener();
  addMouseListener(pl);
  
  mnu1.addActionListener(this);
  mnu2.addActionListener(this);
  mnu3.addActionListener(this);
  mnu4.addActionListener(this);
   
 }
 
 
 public void actionPerformed(ActionEvent ae)
 {
  String cmd = ae.getActionCommand();
  setTitle(cmd);
 }
 
 class PopupListener extends MouseAdapter
 {
  public void mousePressed(MouseEvent me)
  {
   if (me.isPopupTrigger())
   { 
    mnuContext.show(me.getComponent(), me.getX(), me.getY()); 
   } 
  }
 
  public void mouseReleased(MouseEvent me)
  {
   if (me.isPopupTrigger())
   { 
    mnuContext.show(me.getComponent(), me.getX(), me.getY()); 
   } 
  }
}
 
 public static void main(String []str)
 {
  P6 p = new P6();
 }

}




Tuesday, November 9, 2010

Write an application which will demonsrate the use of JTabbePane class to create a GUI with TabbedPanes.

/* Program : 5 
   Write an application which will demonsrate the use of JTabbePane class to create a GUI with TabbedPanes.
   Developed by : Malhar Vora
   Developed on : 8-11-2010
   Development Status : Completed and tested
   Email     : vbmade2000@gmail.com
   WebSite   : www.malhar2010.blogspot.com
*******************************************************************************************************************/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


public class P5 extends JFrame
{
 
 JLabel lblPage1 = null;
 JLabel lblPage2 = null;
 JTabbedPane mainTab = null;
 JPanel page1 = null;
 JPanel page2 = null;
 
 
 P5()
 {
  
  setSize(400,500);
  setTitle("Program 4 - Developed by Malhar Vora");
  setVisible(true);
  setDefaultCloseOperation(EXIT_ON_CLOSE);
  
  lblPage1 = new JLabel("This is first Page - 1");
  lblPage2 = new JLabel("This is first Page - 2");
  page1 = new JPanel();
  page2 = new JPanel();
    
  page1.setLayout(new BorderLayout());  
  page2.setLayout(new BorderLayout());  
  
  page1.add(lblPage1);
  page2.add(lblPage2);
  
  mainTab = new JTabbedPane();
  
  mainTab.addTab("Page 1",page1);
  mainTab.addTab("Page 2",page2);
  
  this.getContentPane().add(mainTab);
   
  
 }
 
 
 public static void main(String []str)
 {
  P5 p = new P5();
 }

}
 

 
 

Sunday, November 7, 2010

Create a program that will write and read the same object from a file and display the content on the screen

/* Program : 2 
   Create a program that will write and read the same object from a file and display the content on the screen
   Developed by : Malhar Vora
   Developed on : 5-11-2010
   Development Status : Completed and tested
   Email     : vbmade2000@gmail.com
   WebSite   : http://technojungle.co.cc
*******************************************************************************************************************/
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class Student implements Serializable
{
 private int id;
 private String name;
 private String course;
  
 Student()
 {
   id=0;
   name="";
   course="";
 }
 
 Student(int sid,String sname,String scourse)
 {
   this.id=sid;
   this.name=sname;
   this.course=scourse;
 }
 
 int getId()
 {
   return this.id;
 }
 
 void setId(int sid)
 {
   this.id=sid;
 }
 
 String getName()
 {
   return this.name;
 }
 
 void setName(String sname)
 {
   this.name=sname;
 }
 
 String getCourse()
 {
   return this.course;
 }
 
 void setCourse(String scourse)
 {
   this.course=scourse;
 }
 
  
}


public class P2 extends JFrame implements ActionListener
{
 
 JLabel lblId=null;
 JLabel lblName=null;
 JLabel lblCourse=null;
 JTextField txtId=null;
 JTextField txtName=null;
 JTextField txtCourse=null;
 JButton btnSave=null;
 JButton btnClear=null;
 JButton btnLoad=null;
 
 
 P2()
 {
   
   lblId = new JLabel("Student ID");
   lblName = new JLabel("Student Name");
   lblCourse = new JLabel("Course");
   txtId = new JTextField(5);
   txtName = new JTextField(20);
   txtCourse = new JTextField(40);
   btnSave  = new JButton("Save");
   btnClear  = new JButton("Clear");
   btnLoad  = new JButton("Load");  
   
   
   
   setTitle("Program 2 - Developed by Malhar Vora");
   setSize(400,500);
   setVisible(true);
   setDefaultCloseOperation(EXIT_ON_CLOSE);
   setLayout(null);
   
   
   lblId.setBounds(50,50,100,50);
   lblName.setBounds(50,90,100,50);
   lblCourse.setBounds(50,130,100,50);
   txtId.setBounds(150,60,60,30);
   txtName.setBounds(150,100,200,30);
   txtCourse.setBounds(150,140,100,30);
   btnSave.setBounds(50,200,80,30);  
   btnClear.setBounds(150,200,80,30);  
   btnLoad.setBounds(250,200,80,30);
   
   btnSave.setMnemonic(KeyEvent.VK_S);  
   btnClear.setMnemonic(KeyEvent.VK_C);  
   btnLoad.setMnemonic(KeyEvent.VK_L);  
   
   this.getContentPane().add(lblId);
   this.getContentPane().add(lblName);
   this.getContentPane().add(lblCourse);
   this.getContentPane().add(txtId);
   this.getContentPane().add(txtName);
   this.getContentPane().add(txtCourse);
   this.getContentPane().add(btnSave);
   this.getContentPane().add(btnClear);
   this.getContentPane().add(btnLoad);
   
   txtId.requestFocus();
   
   btnSave.addActionListener(this); 
   btnClear.addActionListener(this); 
   btnLoad.addActionListener(this); 
   
 }
 
 void saveStudent(Student s)
 {
   FileOutputStream fos=null;
   ObjectOutputStream oos=null;
   try{

     fos = new FileOutputStream("Student.dat");
     oos = new ObjectOutputStream(fos);
     oos.writeObject(s);     
     
   }
   catch(Exception e)
   {
    JOptionPane.showMessageDialog(this,"Error in writing data to file","Error",JOptionPane.ERROR_MESSAGE);
   }
   finally
   {
    try{
      oos.close();
      fos.close();
    }
    catch(Exception e)
    {
     ;
    }
   }
 
 }
 
 Student loadStudent()
 {
  FileInputStream fis=null;
  ObjectInputStream ois=null;
  Student s=null;
  
  try{
   
    fis = new FileInputStream("Student.dat");
    ois = new ObjectInputStream(fis);
    s=(Student)ois.readObject();    
  
  }
  catch(Exception e)
  {
    JOptionPane.showMessageDialog(this,"Error in reading data","Error",JOptionPane.ERROR_MESSAGE);
  }
  finally
  {
    try{
     ois.close();
     fis.close();
    }
    catch(Exception e)
    {
     ;
    }
  }
  return s;
 
 }
 
 public void actionPerformed(ActionEvent ae)
 {
  String cmd = ae.getActionCommand();
  Student s=null;
  
  if(cmd.equals("Save"))
  {
 
   s = new Student();
   s.setId(Integer.parseInt(txtId.getText()));
   s.setName(txtName.getText());
   s.setCourse(txtCourse.getText());
   
   saveStudent(s);
  }
  else if(cmd.equals("Clear"))
  {
   txtId.setText("");
   txtName.setText("");
   txtCourse.setText("");   
  }
  else if(cmd.equals("Load"))
  {
   s=null;
   s=loadStudent();
   txtId.setText("");
   txtName.setText("");
   txtCourse.setText(""); 
   if(s!=null)
   {
    txtId.setText("" + s.getId());   
    txtName.setText(s.getName());
    txtCourse.setText(s.getCourse());
   }
  }
 }
 
 public static void main(String []str)
 {
   P2 p = new P2();
 }

 

}
  
 

Friday, November 5, 2010

Create an application which demonstrates the use of JLabel, JButton and JTextField classes of the Swing to perform binary operation. Also implement the concepts of Icon,ToolTipText and shortCutKey within the same program.

/* Program : 3 
   Create an application which demonstrates the use of JLabel, JButton and JTextField classes of the Swing to perform binary operation. Also implement the concepts of Icon,ToolTipText and shortCutKey within the same program.
   Developed by : Malhar Vora
   Developed on : 5-11-2010
   Development Status : Completed and tested
   Email     : vbmade2000@gmail.com
   WebSite   : http://technojungle.co.cc
*******************************************************************************************************************/

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


class P3 extends JFrame implements ActionListener
{ 


 JLabel lblval1 = null;
 JLabel lblval2 = null;
 JLabel lblresult = null;
 JTextField txtFirst =null;
 JTextField txtSecond = null;
 JTextField txtSum = null;
 JButton btnSum = null;
 Icon icn = null;
 
 
 P3()
 {
   lblval1 = new JLabel("First Value");
   lblval2 = new JLabel("Second Value");
   lblresult = new JLabel("Result");
   
   txtFirst = new JTextField(5);
   txtSecond = new JTextField(5);
   txtSum = new JTextField(5);
   
   icn = new ImageIcon("icon.png");
   btnSum = new JButton("Sum",icn);
   
   setLayout(null);
   setTitle("Program 3 - Developed by Malhar Vora");
   setVisible(true);
   setSize(400,250);
   setDefaultCloseOperation(EXIT_ON_CLOSE);
 
  lblval1.setBounds(80,50,100,10);
  txtFirst.setBounds(160,40,100,30);
    
  lblval2.setBounds(60,90,100,10);
  txtSecond.setBounds(160,80,100,30);
    
  lblresult.setBounds(80,120,100,30);
  txtSum.setBounds(160,120,100,30);
  txtSum.setEditable(false);
    
  btnSum.setBounds(160,160,120,30); 
  btnSum.setToolTipText("Click to make summation");
  btnSum.setMnemonic(KeyEvent.VK_S);
  
   
   this.getContentPane().add(lblval1);
   this.getContentPane().add(lblval2);
   this.getContentPane().add(txtFirst);
   this.getContentPane().add(txtSecond);
   this.getContentPane().add(lblresult);
   this.getContentPane().add(txtSum);
   this.getContentPane().add(btnSum);   

  btnSum.addActionListener(this); 
  
  txtFirst.requestFocus();
  
 }

 public void actionPerformed(ActionEvent ae)
 {
  String cmd = ae.getActionCommand();
  
  if(cmd.equals("Sum"))
  {
   
   if(txtFirst.getText().equals(""))
   {
    JOptionPane.showMessageDialog(this,"Please enter first value","Error in summation",JOptionPane.ERROR_MESSAGE);
    txtFirst.requestFocus();
   }
   else if(txtSecond.getText().equals(""))
   {
    JOptionPane.showMessageDialog(this,"Please enter second value","Error in summation",JOptionPane.ERROR_MESSAGE);
    txtSecond.requestFocus();
   }
   else
   {
    try{
     int a,b,c;
     a = Integer.parseInt(txtFirst.getText());
     b = Integer.parseInt(txtSecond.getText());
     c = a+b;
     txtSum.setText("" + c);
    }
    catch(Exception e)
    {
     txtSum.setText("Error in summation");
    }
    
   }
  }
  
 }

 public static void main(String []str)
 {
  P3 p = new P3(); 
 }

}

Thursday, November 4, 2010

C++ Programming Tutorial - 29 - Array Ranges in Functions

C++ Programming Tutorial - 28 - Changing Array Values with Functions

C++ Programming Tutorial - 27 - Protecting Arrays with const

C++ Programming Tutorial - 26 - Populating an Array with Functions

C++ Programming Tutorial - 25 - Passing Arrays into Functions

C++ Programming Tutorial - 24 - Reading From a File

C++ Programming Tutorial - 21 - Switch Statement

C++ Programming Tutorial - 23 - Writing on Files

C++ Programming Tutorial - 22 - Structures

C++ Programming Tutorial - 20 - Logical OR Operator

C++ Programming Tutorial - 18 - The if else Statement

C++ Programming Tutorial - 19 - The if else if else Statement

C++ Programming Tutorial - 17 - The if Statement

C++ Programming Tutorial - 16 - Creating a Pointer

C++ Programming Tutorial - 15 - Address Operator

C++ Programming Tutorial - 14 - string Class

C++ Programming Tutorial - 13 - Store Text in an Array

C++ Programming Tutorial - 12 - char Array

C++ Programming Tutorial - 11 - More on Building Arrays

C++ Programming Tutorial - 10 - Introduction to Arrays

C++ Programming Tutorial - 9 - using namespace std; Trick

C++ Programming Tutorial - 8 - Dating Young Girls

C++ Programming Tutorial - 7 - Finally Creating Our Own Function!

C++ Programming Tutorial - 6 - Functions with Multiple or No Parameters

C++ Programming Tutorial - 5 - Fantastic Functions

C++ Programming Tutorial - 4 - Come Get Sum!

C++ Programming Tutorial - 3 - Introduction to Variables

C++ Programming Tutorial - 2 - Building and Running a Basic Program

C++ Programming Tutorial - 1 - Installing Dev C++

How to share an internet connection using CCProxy

CCProxy is software which can be used to share Internet connection on a network. It is very easy to use.

Steps for main system from which you want to share Internet connection

1) Download CCProxy sotfware from here

2) Create a simple workgroup network of systems.

3) Install CCProxy

4) Start your local area network connection

5) Start CCProxy from Start Menu->All Programs->CCProxy

6) Click on Start button from toolbar.


Steps for systems in which you want to use use shared Internet connection


1) Set proxy address in Internet Explorer

    -> Open Toosl menu

    -> Click on Internet Options

    -> Click on Connections tab

    -> Click on LAN Settings button located at botton

    -> Check use a proxy server for your LAN checkbox given under "Proxy Server" section

    -> Enter IP address of your main system in address box and port no in port box (Default port is 808)

    -> [ Optional ] Click on Advanced button and enter IP and corresponding port no in all boxes.


2) Set proxy address in Mozilla Firefox

    -> Open Toosl menu

    -> Click on Options

    -> Click on Advanced button in toolbar

    -> Click on Network tab

    -> Click on Settings button

    -> Click on Manual proxy configuration option button

    -> Enter IP address of your main system in HTTP proxy box and port no in port box (Default port is 808)

    -> [ Optional ] Check Use this proxy server for all protocols checkbox to apply same IP for all      protocols



You can also create users accounts to allow access only to registered users and monitor bandwidth usage.



             

             

Tuesday, November 2, 2010

Types of kernel

The kernel is a program that constitutes the central core of a operating system. It has complete control over everything that occurs in the system. 

The kernel is the first part of the operating system to load into memory during booting and it remains there for the entire duration of the computer session because its services are required continuously. Thus it is important for it to be as small as possible while still providing all the essential services needed by the other parts of the operating system and by the various application programs.

Because the service provided by kernel is critical in nature, the kernel is usually loaded into a protected area of memory so no other programs are able to interfere with kernel. 

The kernel provides basic services for all other parts of the operating system, typically including memory management, process management, file management and I/O (input/output) management.  Application programs can reuse these services using specified set of functions called System Calls.

Most of the kernels are designed for a specific operating system. For example Microsoft Windows XP kernel is only for Microsoft Windows XP. A few kernels have been designed for being suitable to use with any operating system. A best example of it is Mach kernel developed at Carnegie Mellon University and is used in Macintosh OS X operating system.


Categories of kernel :

Kernels can be classified in following major categories.

Monolithic kernel:

The word “monolithic” means everything in a single piece. So as the name implies, these kernels have been used by UNIX – like operating systems. It contains all the core operating system functions and device drivers. These functions do not run in separate process. Context switching is very less so it s faster.

Architecture of monolithic kernel

Since every function in the kernel has all privileges, a bug in one function can corrupt data structures of other. The whole kernel is less modular.

Pros

    * Speed
    * Simplicity of design

Cons

    * Potential stability issues
    * Can become huge - Linux 2.6 has 7.0 million lines of code
    * Potentially difficult to maintain

Examples

    * Traditional Unix kernels (For example  BSDs and Solaris)
    * Linux
    * MS-DOS, Windows 9x
    * Windows CE ( Embedded monolithic kernel)
    * Embedded Linux (Embedded monolithic kernel)



Microkernel:

In the Microkernel, only the most fundamental of tasks are performed. It usually provides only minimal services, such as defining memory address spaces, interprocess communication (IPC) and process management. All other functions, such as hardware management, are implemented as processes running independently of the kernel. Most Microkernels use a message passing system of some sort to handle requests from one server to another.

Architecture of Microkernel

Pros

    * Stability
    * Security
    * Potentially more responsive (though often not in practice)
    * Benefits for SMP machines

Cons

    * Additional context switches are usually required
    * Slow Inter Process Communication can result in poor performance

Examples of Microkernels and OSs based on Microkernels:

    * AIX
    * AmigaOS
    * Amoeba
    * Chorus Microkernel
    * EROS
    * K42
    * Minix
    * MorphOS
    * QNX
    * RadiOS
    * Spring Microkernel


Hybrid kernel:

As the word “Hybrid” in category implies, Hybrid kernels combine concepts of both monolithic kernels and Microkernels. When properly implemented it is hoped that this will result in the performance benefits of a monolithic kernel, with the stability of a Microkernel. Most modern operating system kernels today fall in this category.
Architecture of Hybrid kernel


Examples

    * NT kernel (used in Windows NT, 2000, XP, Vista and Windows 7)
    * Dragonfly BSD
    * Mac OS
    * BeOS
    * Plan 9