Friday, March 25, 2011

Read and writing xlsx files

download jar files:
1.dom4j-1.6.1,jar
2.poi-3.6.jar
3.poi-ooxml-3.5-FINAL-20090928.jar
4.poi-ooxml-schemas-3.6.jar
5.xmlbeans-2.3.0.jar


Code:
import java.io.File;

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

/**
*
* @author sachanta
*/
public class ReadFiles {

public void getFiles() throws IOException {
try {
File pathName = new File("D:/excel");
String filename[] = pathName.list();
if (filename == null) {
System.out.println("No files exists");
} else {
for (int i = 0; i
File f = new File(pathName.getAbsoluteFile(), filename[i]);
String fname = f.getCanonicalPath();
System.out.print(fname);
readWriteExcel(fname, i);
System.out.println("File created successfully");
}
}
} catch (Exception e) {
e.printStackTrace();
}

}

public void readWriteExcel(String fname, int f) throws IOException {
String filename = fname;//"D:/Test case Teplete.xlsx";

FileInputStream fis = null;
FileOutputStream fout = null;

try {
fis = new FileInputStream(filename);
XSSFWorkbook workbook = new XSSFWorkbook(fis);
int numSheets = workbook.getNumberOfSheets();

//writing the excel file
if (f == 0) {
(new File("D:/excel/excel")).mkdir();

}

fout = new FileOutputStream("D:/excel/excel/Consolidated-" + f + ".xlsx");
XSSFWorkbook cworkbook = new XSSFWorkbook();
XSSFSheet csheet = cworkbook.createSheet("output");
int createrownumber = 0;
for (int i = 0; i <>
{
XSSFSheet sheet = workbook.getSheetAt(i);
//String name = workbook.getSheetName(i);
Iterator rows = sheet.rowIterator();
while (rows.hasNext())
{
XSSFRow row = ((XSSFRow) rows.next());
float oldheight = row.getHeightInPoints();
int remove_row = row.getRowNum();
if ((i != 0) && (remove_row == 0))
{
continue;
}
XSSFRow crow = csheet.createRow(createrownumber);
crow.setHeightInPoints(oldheight);
Iterator cells = row.cellIterator();
int cellSize = row.getFirstCellNum();
while (cells.hasNext())
{
XSSFCell cell = (XSSFCell) cells.next();
//creating a cell in target file
XSSFCell cell1 = crow.createCell((short) cellSize);


csheet.autoSizeColumn((short) 0);
csheet.autoSizeColumn((short) 1);
csheet.autoSizeColumn((short) 4);

int columnWidth = sheet.getColumnWidth(cellSize);
csheet.setColumnWidth(cellSize, columnWidth);
String Value = cell.getStringCellValue();

//setting the cell value in the target cell
cell1.setCellValue(Value);

XSSFCellStyle oldCellStyle = cell.getCellStyle();
XSSFCellStyle cellStyle = cworkbook.createCellStyle();

cellStyle.setBorderBottom(CellStyle.BORDER_THIN);
cellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
cellStyle.setBorderLeft(CellStyle.BORDER_THIN);
cellStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
cellStyle.setBorderRight(CellStyle.BORDER_THIN);
cellStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
cellStyle.setBorderTop(CellStyle.BORDER_THIN);
cellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());

cellStyle.setVerticalAlignment(VerticalAlignment.BOTTOM);
//cellStyle.setAlignment(HorizontalAlignment.CENTER);

cellStyle.setWrapText(true);
cellStyle.setFillForegroundColor(oldCellStyle.getFillForegroundXSSFColor());
cellStyle.setFillPattern(oldCellStyle.getFillPattern());
cell1.setCellStyle(cellStyle);
cellSize++;

}//end of cell iterator

createrownumber++;
}//end of row iterator

createrownumber = createrownumber +3;
}//end of sheet iterator

cworkbook.write(fout);

} catch (IOException e) {
e.printStackTrace();
} finally
{
if (fout != null)
{
fout.close();
}
if (fis != null)
{
fis.close();
}

}
}

public static void main(String args[]) {
ReadFiles r = new ReadFiles();
try {
r.getFiles();
} catch (IOException ex) {
Logger.getLogger(ReadFiles.class.getName()).log(Level.SEVERE, null, ex);
}
}
}

Saturday, September 25, 2010

how to enable template path hint in magento 1.4

If you want this option displayed for ‘default config’ also, just edit the app\code\core\Mage\Core\etc\system.xml file.
Look for something like this
<template_hints translate="label">
<
label>Template Path Hintslabel>
<
frontend_type>selectfrontend_type>
<
source_model>adminhtml/system_config_source_yesnosource_model>
<
sort_order>20sort_order>
<
show_in_default>0show_in_default>
<
show_in_website>1show_in_website>
<
show_in_store>1show_in_store>
template_hints>
replace
<show_in_default>0show_in_default>
with
<show_in_default>1show_in_default>
Do the same for this section
<template_hints_blocks translate="label">
<
label>Add Block Names to Hintslabel>
<
frontend_type>selectfrontend_type>
<
source_model>adminhtml/system_config_source_yesnosource_model>
<
sort_order>21sort_order>
<
show_in_default>0show_in_default>
<
show_in_website>1show_in_website>
<
show_in_store>1show_in_store>
template_hints_blocks>
and clear the cache

Resloving magento 1.4 fatal error:line 529

in page.xml under app/design/frontend/base/default/layout (or your custome page.xml)

change the line
to


and clear the cache

Wednesday, September 22, 2010

STRESS!!!! OH!

Before I proceed. I would like to ask you some personal questions, Like:

HOW ARE YOU??? ARE YOU TENSED???

HOW MANY TIME IN A DAY YOU ARE TAKING CARE OF YOUR HEALTH?

Though we are in 20th century, we all have liking for free and modern life style.This modern civilization changes the attitude of woman and makes her busy in her outside job as the house hold. She is now having her two legs in two running boats. Butt you better Know What will be the result. That leads to physical and mental tension.

Today’s work tension makes her not active but also reactive:

We all know about our great scientist Sir Issac Newton. According to his third law of motion-”every action there is an equal and opposite reaction”.

But it is required that this reaction should be positive. when it is concerned with our health. My intention is not to avoid you to do the job but simultaneously you should give importance to your health.

You know scientist are the most busiest person mentally they are not free.

some time this tensed mind caused unnatural death Like “Madam Curie.” Now I am giving You an Example Newton’s busiest life how his mind had no control over his body.

Sir Issac Newton was very absent minded, when he was thinking over a problem.

One morning he got up early and was thinking abut his reaserch problem so deeply that he would not leave the problem and go for the breakfast. but his house-keeper ‘Marry’ thught that newton needed food. So she took a pan of water and egg, and started boiled it.

but Newton wanted to be alone and said

“Marry you can leave the egg with me , I will boil it.”then Marry put the egg on table beside his watch and said Issac you must boiled the egg for Four minutes and went away.

But she was afraid that the Newton might forget to boil the egg. So she returned after an hour later. then you know what she find there?

She found that Newton was standing by the fireplace. He had put the watch in the sauce pan for boiling instead of egg, which was in his hand and still thinking about the problems.

learn from others ‘experience

man’s life in this world is comparatively a shorter one.therefore,he doesn’t have time to learn everything from personal experiences .here is the importance of drawing inspiration from others and their experiences.in other words ,don’t wait for a chance to make the entire mistakes yourself.learning from others’ experience will protect you from a number of failures.

we should also learn some lessons from the nature . the animals ,birds,mountains,plants and everything we see in the world teach us something .you might have heard about the story of Robert Bruce who got inspiration from a spider to defeat the enemies .we can learn a lot of things from the nature ,only if we have an open mind.

Monday, August 2, 2010

calculator program

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

/*
* TwoNumbers.java
*
* Created on Jul 19, 2010, 11:59:42 AM
*/

/**
*
* @author Achanta
*/
public class TwoNumbers extends javax.swing.JFrame {
private boolean counter = true,op=false;
String strnum;
int total = 0,i=0;
boolean click = true;
private int no = 0,lastCommand=1,command=0;
private boolean addClick=true,subClick=true,mulClick=true,divClick=true;
String temp;
int opType=0;
int opStack[]=new int[20];

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

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/

// //GEN-BEGIN:initComponents
private void initComponents() {

jButton11 = new javax.swing.JButton();
text = new javax.swing.JTextField();
add = new javax.swing.JButton();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
sub = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
jButton6 = new javax.swing.JButton();
jButton7 = new javax.swing.JButton();
jButton8 = new javax.swing.JButton();
jButton9 = new javax.swing.JButton();
jButton10 = new javax.swing.JButton();
mulbutton = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
divbutton = new javax.swing.JButton();
equalbutton = new javax.swing.JButton();
c = new javax.swing.JButton();
backspace = new javax.swing.JButton();

jButton11.setText("jButton11");

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

add.setText("+");
add.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addActionPerformed(evt);
}
});

jButton1.setText("1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jButton2.setText("2");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});

jButton3.setText("3");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});

sub.setText("-");
sub.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
subActionPerformed(evt);
}
});

jButton4.setText("4");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});

jButton5.setText("5");
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton5ActionPerformed(evt);
}
});

jButton6.setText("6");
jButton6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton6ActionPerformed(evt);
}
});

jButton7.setText("7");
jButton7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton7ActionPerformed(evt);
}
});

jButton8.setText("8");
jButton8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton8ActionPerformed(evt);
}
});

jButton9.setText("9");
jButton9.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton9ActionPerformed(evt);
}
});

jButton10.setText("0");
jButton10.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton10ActionPerformed(evt);
}
});

mulbutton.setText("*");
mulbutton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mulbuttonActionPerformed(evt);
}
});

jLabel1.setFont(new java.awt.Font("Times New Roman", 3, 14)); // NOI18N
jLabel1.setText("Calculator");

divbutton.setText("/");
divbutton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
divbuttonActionPerformed(evt);
}
});

equalbutton.setText("=");
equalbutton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
equalbuttonActionPerformed(evt);
}
});

c.setText("C");
c.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cActionPerformed(evt);
}
});

backspace.setText("BackSpace");
backspace.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
backspaceActionPerformed(evt);
}
});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(jButton6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton7)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton8)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton9))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton4)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jButton5)
.addComponent(jButton10)))
.addComponent(text, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(backspace, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(c, javax.swing.GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(add)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(sub)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(mulbutton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(divbutton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(equalbutton))
.addGroup(layout.createSequentialGroup()
.addGap(86, 86, 86)
.addComponent(jLabel1)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(text, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton4)
.addComponent(jButton5)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton6)
.addComponent(jButton7)
.addComponent(jButton8)
.addComponent(jButton9)
.addComponent(jButton10))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(add)
.addComponent(sub, javax.swing.GroupLayout.DEFAULT_SIZE, 27, Short.MAX_VALUE)
.addComponent(mulbutton)
.addComponent(divbutton)
.addComponent(equalbutton))
.addGap(1, 1, 1)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(backspace)
.addComponent(c))
.addContainerGap())
);

pack();
}//
//GEN-END:initComponents
private void equal()
{
no=Integer.parseInt(text.getText());
switch(opType)
{
case 1:
total += no;
break;
case 2:
total -= no;
break;
case 3:
total *= no;
break;
case 4:
total /= no;
break;
}
text.setText(Integer.toString(total));
counter=true;
}
private void getDigits()
{
if(counter==true)
{
text.setText("");
text.setText(temp);
no=Integer.parseInt(temp);
counter=false;
}
else {
strnum=text.getText() + temp;
no=Integer.parseInt(strnum);
text.setText(strnum);
}
}

private void assign() {
if (op == false) {
getDigits();
} else {

opeartion();
}
}
private void opeartion() {
if (
(addClick == true || subClick == false||mulClick==false||divClick==false)&&
(subClick==true||addClick==false||mulClick==false||divClick==false)&&
(mulClick==true||addClick==false||subClick==false||divClick==false)&&
(divClick==true||addClick==false||subClick==false||mulClick==false))
{
total = Integer.parseInt(text.getText());
System.out.println("the total and no values are "+total+" "+no);

subClick = false;
mulClick = false;
divClick = false;
addClick = false;
}
else
{
switch (opType) {
case 1:System.out.println("the total and no values are "+total+" "+no);
total+= no;
break;
case 2:System.out.println("the total and no values are "+total+" "+no);
total-= no;
break;
case 3:System.out.println("the total and no values are "+total+" "+no);
total*=no;
break;
case 4:System.out.println("the total and no values are "+total+" "+no);
total=total/no;
break;
}
}
text.setText(Integer.toString(total));
counter=true;
}



private void addActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addActionPerformed
op=true;
opType=1;subClick=true;mulClick=true;divClick=true;
assign();
}//GEN-LAST:event_addActionPerformed

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

temp = "1";op=false;
assign();

}//GEN-LAST:event_jButton1ActionPerformed

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
temp = "2";op=false;
assign();



}//GEN-LAST:event_jButton2ActionPerformed

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
temp = "3";op=false;
assign();


}//GEN-LAST:event_jButton3ActionPerformed

private void subActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_subActionPerformed
op=true;
opType=2;addClick=true;mulClick=true;divClick=true;
assign();
}//GEN-LAST:event_subActionPerformed

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
temp = "4";op=false;
assign();
}//GEN-LAST:event_jButton4ActionPerformed

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
temp = "5";op=false;
assign();
}//GEN-LAST:event_jButton5ActionPerformed

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
temp = "6";op=false;
assign();
}//GEN-LAST:event_jButton6ActionPerformed

private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
temp = "7";op=false;
assign();
}//GEN-LAST:event_jButton7ActionPerformed

private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
temp = "8";op=false;
assign();
}//GEN-LAST:event_jButton8ActionPerformed

private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
temp = "9";op=false;
assign();
}//GEN-LAST:event_jButton9ActionPerformed

private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
temp = "0";op=false;
assign();
}//GEN-LAST:event_jButton10ActionPerformed

private void mulbuttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mulbuttonActionPerformed
op=true;
opType=3;addClick=true;subClick=true;divClick=true;
assign();
}//GEN-LAST:event_mulbuttonActionPerformed

private void divbuttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_divbuttonActionPerformed
op=true;
opType=4;addClick=true;subClick=true;mulClick=true;
assign();
}//GEN-LAST:event_divbuttonActionPerformed

private void equalbuttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_equalbuttonActionPerformed
addClick=true;subClick=true;mulClick=true;divClick=true;
equal();
}//GEN-LAST:event_equalbuttonActionPerformed

private void cActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cActionPerformed
no=0;
text.setText("");
}//GEN-LAST:event_cActionPerformed

private void backspaceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backspaceActionPerformed
String notemp=Integer.toString(no);
System.out.println("the string length is "+notemp.length());
if (notemp.length() == 1) {
no = 0;
notemp=Integer.toString(no);
} else {
notemp = notemp.substring(0, notemp.length() - 1);
int no = Integer.parseInt(notemp);
System.out.println("the number is " + no);
}

text.setText(notemp);
counter=true;
}//GEN-LAST:event_backspaceActionPerformed

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new TwoNumbers().setVisible(true);
}
});
}

// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton add;
private javax.swing.JButton backspace;
private javax.swing.JButton c;
private javax.swing.JButton divbutton;
private javax.swing.JButton equalbutton;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton10;
private javax.swing.JButton jButton11;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JButton jButton7;
private javax.swing.JButton jButton8;
private javax.swing.JButton jButton9;
private javax.swing.JLabel jLabel1;
private javax.swing.JButton mulbutton;
private javax.swing.JButton sub;
private javax.swing.JTextField text;
// End of variables declaration//GEN-END:variables






}

Sunday, May 9, 2010

programs

Menu.java


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

package javaapplication1;

/**
*
* @author Sravanthi
*/
import java.util.*;
public class Menu
{
Scanner sc=new Scanner(System.in);
int no=0;
String name=null;
public Menu()
{}
public void mainmenu()
{
int mchoice=0;
System.out.println("***Main Menu***");
System.out.println("----------------");
System.out.println("1.Admin");
System.out.println("2.User");
System.out.print("enter your choice:");
mchoice=sc.nextInt();
switch(mchoice)
{
case 1:adminmenu();
break;
case 2:usermenu();
break;
}
}

public void adminmenu()
{
do
{
int achoice=0;

System.out.println("****Admin****");
System.out.println("--------------");
System.out.println("1.View");
System.out.println("2.Insert");
System.out.println("3.Update");
System.out.println("4.Delete");
System.out.println("5.Main menu");
System.out.println("6.Exit");
System.out.print("enter your choice:");
achoice=sc.nextInt();
switch(achoice)
{
case 1:
View.view();
break;
case 2:System.out.println("Enter the no:");
no=sc.nextInt();
System.out.println("Enter the name:");
name=sc.next();
Insert.insert(no,name);
break;
case 3:Update.update();
break;
case 4:Delete.delete();
break;
case 5:mainmenu();
break;
case 6:System.exit(0);
default:System.out.println("invalid choice");
}
}while(true);
}

public void usermenu()
{
do
{
int uchoice=0;

System.out.println("****Admin****");
System.out.println("--------------");
System.out.println("1.View");
System.out.println("2.Main menu");
System.out.println("3.Exit");
System.out.print("enter your choice:");
uchoice=sc.nextInt();
switch(uchoice)
{
case 1:View.view();
break;

case 2:mainmenu();
break;
case 3:System.exit(0);
default:System.out.println("invalid choice");
}
}while(true);
}

public static void main(String args[])
{
Menu m=new Menu();
m.mainmenu();
}
}





MySqlconnectin.java



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

package javaapplication1;

/**
*
* @author Sravanthi
*/
import java.sql.*;
public class MysqlConnection
{
public static Connection getConnection()
{
Connection con=null;
try
{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");

}
catch(ClassNotFoundException ce)
{
ce.printStackTrace();
}
catch(SQLException sq)
{
sq.printStackTrace();
}
return con;
}
}



insert.java

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

package javaapplication1;

/**
*
* @author Sravanthi
*/
import java.sql.*;
public class Insert
{
public static void insert(int no,String name)
{
try
{
String sql = "insert into first values("+no+",'"+name+"') ";
Connection connection = MysqlConnection.getConnection();
Statement statement = connection.createStatement();
int n=statement.executeUpdate(sql);
if(n>0)
System.out.println("Record inserted successfully");
else
System.out.println("Record was not inserted");

}
catch(SQLException sq)
{
sq.printStackTrace();
}

}


}


Delete.java

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

package javaapplication1;

/**
*
* @author Sravanthi
*/
import java.sql.*;
public class Delete
{
public static void delete()
{
try
{
String sql = "delete from first where id=1 ";
Connection connection = MysqlConnection.getConnection();
Statement statement = connection.createStatement();
int n=statement.executeUpdate(sql);
if(n>0)
System.out.println("Record was successfully deleted");
else
System.out.println("Record was not deleted");

}
catch(SQLException sq)
{
sq.printStackTrace();
}

}
public static void main(String args[])
{

Delete.delete();
}
}


update.java

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

package javaapplication1;

/**
*
* @author Sravanthi
*/
import java.sql.*;
public class Update
{
public static void update()
{
try
{
String sql = "update first set id=121 where id=2 ";
Connection connection = MysqlConnection.getConnection();
Statement statement = connection.createStatement();
int n=statement.executeUpdate(sql);
if(n>0)
System.out.println("Record was successfully updated");
else
System.out.println("Record was not updated");

}
catch(SQLException sq)
{
sq.printStackTrace();
}

}
public static void main(String args[])
{

Update.update();
}
}


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

package javaapplication1;

/**
*
* @author Sravanthi
*/
import java.sql.*;
public class View
{
public static void view()
{
try
{
String sql = "select * from first ";
Connection connection = MysqlConnection.getConnection();
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery(sql);
while(rs.next())
{
System.out.println(rs.getInt(1)+"\t"+rs.getString(2));
}
}
catch(SQLException sq)
{
sq.printStackTrace();
}

}


}