Find us on Google+ Kill the code

Wednesday, 1 August 2012

Java simple Checkbox Program


import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.JApplet;
import javax.swing.JCheckBox;
import javax.swing.JLabel;


public  class ckbox extends JApplet implements ItemListener {

JLabel msg;
JCheckBox cb,cb1,cb2,cb3;

public void init()
{
Container c = getContentPane();
c.setLayout(new FlowLayout());
msg = new JLabel("you have selected ..");
cb = new JCheckBox("Java");
cb.addItemListener(this);
cb1 = new JCheckBox("Dot Net");
cb1.addItemListener(this);
cb2 = new JCheckBox("XYZ");
cb2.addItemListener(this);
cb3 = new JCheckBox("All");
cb3.addItemListener(this);

add(cb3);
add(cb);
add(cb1);
add(cb2);
add(msg);


}

@Override
public void itemStateChanged(ItemEvent ie)
{

JCheckBox temp = (JCheckBox)ie.getItem();

if(temp.isSelected() == true )
{
msg.setText("you have selected"+temp.getText());
}
else
{
msg.setText("you have deselected"+temp.getText());
}


if(temp.getText().equals("All"))
{
if(temp.isSelected()==true)
{

cb1.setSelected(true);
cb2.setSelected(true);
cb.setSelected(true);
}
else
{

cb1.setSelected(false);
cb2.setSelected(false);
cb.setSelected(false);
}
}



}
}

Database Connectivity in Java


This program is for database connectivity in java
follow the steps
1) first create the database in MS ACCESS (DATABASE + TABLE)
2) write a program and execute program
3) In program SagarDB is database name and DemoTable is table name in MS ACCESS.

import java.sql.Connection;
import java.sql.DriverManager;

import java.sql.*;

public class DemoDbconnect
{
public static void main (String[] args)
{
       try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection cn = DriverManager.getConnection("jdbc:odbc:SagarDB");
Statement st = cn.createStatement();
ResultSet rs = st.executeQuery("select * from DemoTable;");

while(rs.next())
{
System.out.println(rs.getString(1)+"   " + rs.getString(2)+"   " + rs.getString(3)+"   ");
}
cn.close();
       }
 

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

Friday, 27 July 2012

How to create a python server ?

Initially,you must have Python installed.

After the installation,do following.

Open a notepad file and type the following code there:

from http.server import HTTPServer, CGIHTTPRequestHandler
port = 8080
httpd = HTTPServer((”, port), CGIHTTPRequestHandler)
print(“Starting simple_httpd on port: ” + str(httpd.server_port))
httpd.serve_forever()

Save it and remember the location of it.

Thereby,

For Windows user

1.Go to Start –>All Programs–>Python 3.2–>IDLE
2.Press Ctrl+O to open the file saved above.
3.Press F5.



Above window with message “Staring simple_httpd on port 8080″ shows success of our work.

For Unix And Mac OS X Users

You need to do two things to prepare your CGI script for execution:

1. Set the executable bit for your CGI using the chmod +x command.
2. Add the following line of code to the very top of your program:
#! /usr/local/bin/python3

Thereby do another thing:
1. Open Terminal (or Shell).
2. Type python

That’s it,server is running on your *NIX OS.

That’s all how a simple “home-made” Python server is made and run,simply with above 4 steps.Send your queries below in the comments.