Standard and Scientific Calculator In Java

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

public class calculator extends JFrame implements ActionListener
{
JTextField jtx;
double temp,temp1,result,a;
static double m1,m2;
int k=1,x=0,y=0,z=0;
char ch;
JButton
one,two,three,four,five,six,seven,eight,nine,zero,clr,pow2,pow3,exp;
JButton
plus,min,div,lg,rec,mul,eq,plmi,poin,mr,mc,mp,mm,sqrt,sin,cos,tan;
JMenuBar bar;
JMenu view;
JMenuItem exit;
JRadioButtonMenuItem standard,scientific;
JSeparator jp;
ButtonGroup bg;
Container cont;
JPanel textPanel,syntpanel,buttonpanel;
calculator()
{
cont=getContentPane();
cont.setLayout(new BorderLayout());
JPanel textpanel=new JPanel();
Font font=new Font("Arial",Font.PLAIN,18);
jtx=new JTextField(25);
jtx.setFont(font);
jtx.setHorizontalAlignment(SwingConstants.RIGHT);
jtx.addKeyListener(new KeyAdapter()
{
public void keyTyped(KeyEvent keyevent)
{
char c=keyevent.getKeyChar();
if(c>='0' && c<='9')
{
}
else
{
keyevent.consume();
}
}
});
textpanel.add(jtx);
buttonpanel=new JPanel();
buttonpanel.setLayout(new GridLayout(5,4,2,2));
boolean t=true;
syntpanel=new JPanel();
syntpanel.setLayout(new GridLayout(5,1));
bar=new JMenuBar();
view=new JMenu("View");

standard =new JRadioButtonMenuItem("Standard",true);
standard.setMnemonic('S');
standard.addItemListener(new radiohandler());
scientific =new JRadioButtonMenuItem("Sceintific");
standard.setMnemonic('c');
scientific.addItemListener(new radiohandler());
jp=new JSeparator();
exit=new JMenuItem("Exit");
standard.setMnemonic('E');
exit.addActionListener(this);
bg=new ButtonGroup();
bg.add(standard);
bg.add(scientific);
view.add(standard);
view.add(scientific);
view.add(jp);
view.add(exit);
bar.add(view);
setJMenuBar(bar);

mr=new JButton("MR");
buttonpanel.add(mr);
mr.addActionListener(this);
seven=new JButton("7");
buttonpanel.add(seven);
seven.addActionListener(this);
eight=new JButton("8");
buttonpanel.add(eight);
eight.addActionListener(this);
nine=new JButton("9");
buttonpanel.add(nine);
nine.addActionListener(this);
clr=new JButton("AC");
buttonpanel.add(clr);
clr.addActionListener(this);

mc=new JButton("MC");
buttonpanel.add(mc);
mc.addActionListener(this);
four=new JButton("4");
buttonpanel.add(four);
four.addActionListener(this);
five=new JButton("5");
buttonpanel.add(five);
five.addActionListener(this);
six=new JButton("6");
buttonpanel.add(six);
six.addActionListener(this);
mul=new JButton("*");
buttonpanel.add(mul);
mul.addActionListener(this);

mp=new JButton("M+");
buttonpanel.add(mp);
mp.addActionListener(this);
one=new JButton("1");
buttonpanel.add(one);
one.addActionListener(this);
two=new JButton("2");
buttonpanel.add(two);
two.addActionListener(this);
three=new JButton("3");
buttonpanel.add(three);
three.addActionListener(this);
min=new JButton("-");
buttonpanel.add(min);
min.addActionListener(this);

mm=new JButton("M-");
buttonpanel.add(mm);
mm.addActionListener(this);
zero=new JButton("0");
buttonpanel.add(zero);
zero.addActionListener(this);
plmi=new JButton("+/-");
buttonpanel.add(plmi);
plmi.addActionListener(this);
poin=new JButton(".");
buttonpanel.add(poin);
poin.addActionListener(this);
plus=new JButton("+");
buttonpanel.add(plus);
plus.addActionListener(this);


rec=new JButton("1/x");
buttonpanel.add(rec);
rec.addActionListener(this);
sqrt=new JButton("Sqrt");
buttonpanel.add(sqrt);
sqrt.addActionListener(this);
lg=new JButton("log");
buttonpanel.add(lg);
lg.addActionListener(this);
div=new JButton("/");
div.addActionListener(this);
buttonpanel.add(div);
eq=new JButton("=");
buttonpanel.add(eq);
eq.addActionListener(this);

sin=new JButton("SIN");
syntpanel.add(sin);
sin.addActionListener(this);
cos=new JButton("COS");
syntpanel.add(cos);
cos.addActionListener(this);
tan=new JButton("TAN");
syntpanel.add(tan);
tan.addActionListener(this);
pow2=new JButton("x^2");
syntpanel.add(pow2);
pow2.addActionListener(this);
pow3=new JButton("x^3");
syntpanel.add(pow3);
pow3.addActionListener(this);
exp=new JButton("Exp");
exp.addActionListener(this);

cont.add("Center",buttonpanel);
cont.add("North",textpanel);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
class radiohandler implements ItemListener
{
public void itemStateChanged(ItemEvent ie)
{
AbstractButton button=(AbstractButton)ie.getItem();
String label=button.getText();
{
if(label.equals("Standard"))
{
cont.remove(syntpanel);
validate();
}
if(label.equals("Sceintific"))
{
cont.add("West",syntpanel);
validate();
}
}
}
}
public void actionPerformed(ActionEvent e)
{
String s=e.getActionCommand();
if(s.equals("Exit"))
{
System.exit(0);
}
if(s.equals("1"))
{
if(z==0)
{
jtx.setText(jtx.getText()+"1");
}
else
{
jtx.setText("");
jtx.setText(jtx.getText()+"1");
z=0;
}
}
if(s.equals("2"))
{
if(z==0)
{
jtx.setText(jtx.getText()+"2");
}
else
{
jtx.setText("");
jtx.setText(jtx.getText()+"2");
z=0;
}
}
if(s.equals("3"))
{
if(z==0)
{
jtx.setText(jtx.getText()+"3");
}
else
{
jtx.setText("");
jtx.setText(jtx.getText()+"3");
z=0;
}
}
if(s.equals("4"))
{
if(z==0)
{
jtx.setText(jtx.getText()+"4");
}
else
{
jtx.setText("");
jtx.setText(jtx.getText()+"4");
z=0;
}
}
if(s.equals("5"))
{
if(z==0)
{
jtx.setText(jtx.getText()+"5");
}
else
{
jtx.setText("");
jtx.setText(jtx.getText()+"5");
z=0;
}
}
if(s.equals("6"))
{
if(z==0)
{
jtx.setText(jtx.getText()+"6");
}
else
{
jtx.setText("");
jtx.setText(jtx.getText()+"6");
z=0;
}
}
if(s.equals("7"))
{
if(z==0)
{
jtx.setText(jtx.getText()+"7");
}
else
{
jtx.setText("");
jtx.setText(jtx.getText()+"7");
z=0;
}
}
if(s.equals("8"))
{
if(z==0)
{
jtx.setText(jtx.getText()+"8");
}
else
{
jtx.setText("");
jtx.setText(jtx.getText()+"8");
z=0;
}
}
if(s.equals("9"))
{
if(z==0)
{
jtx.setText(jtx.getText()+"9");
}
else
{
jtx.setText("");
jtx.setText(jtx.getText()+"9");
z=0;
}
}
if(s.equals("0"))
{
if(z==0)
{
jtx.setText(jtx.getText()+"0");
}
else
{
jtx.setText("");
jtx.setText(jtx.getText()+"0");
z=0;
}
}
if(s.equals("AC"))
{
jtx.setText("");
x=0;
y=0;
z=0;
}
if(s.equals("log"))
{
if(jtx.getText().equals(""))
{
jtx.setText("");
}
else
{
a=Math.log(Double.parseDouble(jtx.getText()));
jtx.setText("");
jtx.setText(jtx.getText() + a);
}
}
if(s.equals("1/x"))
{
if(jtx.getText().equals(""))
{
jtx.setText("");
}
else
{
a=1/Double.parseDouble(jtx.getText());
jtx.setText("");
jtx.setText(jtx.getText() + a);
}
}
if(s.equals("Exp"))
{
if(jtx.getText().equals(""))
{
jtx.setText("");
}
else
{
a=Math.exp(Double.parseDouble(jtx.getText()));
jtx.setText("");
jtx.setText(jtx.getText() + a);
}
}
if(s.equals("x^2"))
{
if(jtx.getText().equals(""))
{
jtx.setText("");
}
else
{
a=Math.pow(Double.parseDouble(jtx.getText()),2);
jtx.setText("");
jtx.setText(jtx.getText() + a);
}
}
if(s.equals("x^3"))
{
if(jtx.getText().equals(""))
{
jtx.setText("");
}
else
{
a=Math.pow(Double.parseDouble(jtx.getText()),3);
jtx.setText("");
jtx.setText(jtx.getText() + a);
}
}
if(s.equals("+/-"))
{
if(x==0)
{
jtx.setText("-"+jtx.getText());
x=1;
}
else
{
jtx.setText(jtx.getText());
}
}
if(s.equals("."))
{
if(y==0)
{
jtx.setText(jtx.getText()+".");
y=1;
}
else
{
jtx.setText(jtx.getText());
}
}
if(s.equals("+"))
{
if(jtx.getText().equals(""))
{
jtx.setText("");
temp=0;
ch='+';
}
else
{
temp=Double.parseDouble(jtx.getText());
jtx.setText("");
ch='+';
y=0;
x=0;
}
jtx.requestFocus();
}
if(s.equals("-"))
{
if(jtx.getText().equals(""))
{
jtx.setText("");
temp=0;
ch='-';
}
else
{
x=0;
y=0;
temp=Double.parseDouble(jtx.getText());
jtx.setText("");
ch='-';
}
jtx.requestFocus();
}
if(s.equals("/"))
{
if(jtx.getText().equals(""))
{
jtx.setText("");
temp=1;
ch='/';
}
else
{
x=0;
y=0;
temp=Double.parseDouble(jtx.getText());
ch='/';
jtx.setText("");
}
jtx.requestFocus();
}
if(s.equals("*"))
{
if(jtx.getText().equals(""))
{
jtx.setText("");
temp=1;
ch='*';
}
else
{
x=0;
y=0;
temp=Double.parseDouble(jtx.getText());
ch='*';
jtx.setText("");
}
jtx.requestFocus();
}
if(s.equals("MC"))
{
m1=0;
jtx.setText("");
}
if(s.equals("MR"))
{
jtx.setText("");
jtx.setText(jtx.getText() + m1);
}
if(s.equals("M+"))
{
if(k==1)
{
m1=Double.parseDouble(jtx.getText());
k++;
}
else
{
m1+=Double.parseDouble(jtx.getText());
jtx.setText(""+m1);
}
}
if(s.equals("M-"))
{
if(k==1)
{
m1=Double.parseDouble(jtx.getText());
k++;
}
else
{
m1-=Double.parseDouble(jtx.getText());
jtx.setText(""+m1);
}
}
if(s.equals("Sqrt"))
{
if(jtx.getText().equals(""))
{
jtx.setText("");
}
else
{
a=Math.sqrt(Double.parseDouble(jtx.getText()));
jtx.setText("");
jtx.setText(jtx.getText() + a);
}
}
if(s.equals("SIN"))
{
if(jtx.getText().equals(""))
{
jtx.setText("");
}
else
{
a=Math.sin(Double.parseDouble(jtx.getText()));
jtx.setText("");
jtx.setText(jtx.getText() + a);
}
}
if(s.equals("COS"))
{
if(jtx.getText().equals(""))
{
jtx.setText("");
}
else
{
a=Math.cos(Double.parseDouble(jtx.getText()));
jtx.setText("");
jtx.setText(jtx.getText() + a);
}
}
if(s.equals("TAN"))
{
if(jtx.getText().equals(""))
{
jtx.setText("");
}
else
{
a=Math.tan(Double.parseDouble(jtx.getText()));
jtx.setText("");
jtx.setText(jtx.getText() + a);
}
}
if(s.equals("="))
{
if(jtx.getText().equals(""))
{
jtx.setText("");
}
else
{
temp1 = Double.parseDouble(jtx.getText());
switch(ch)
{
case '+':
result=temp+temp1;
break;
case '-':
result=temp-temp1;
break;
case '/':
result=temp/temp1;
break;
case '*':
result=temp*temp1;
break;
}
jtx.setText("");
jtx.setText(jtx.getText() + result);
z=1;
}
}
jtx.requestFocus();
}
public static void main(String args[])
{
calculator n=new calculator();
n.setTitle("CALCULATOR");
n.setSize(370,250);
n.setResizable(false);
n.setVisible(true);
}
}

School Management System Project In Java

//Case Study

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

public class ProjectX extends JFrame implements ChangeListener,
ActionListener
{
static int choice = 0;
static String line = "--------------------------------";
DataInputStream inputData = new DataInputStream(System.in);
private Registration studentDetails = new Registration();
int topScore = studentDetails.getTopScore();
int passMarks = studentDetails.getPassMarks();
int firstClass = studentDetails.getFirstClass();
int secondClass = studentDetails.getSecondClass();

JTabbedPane tabbedPane = new JTabbedPane();
JLabel statusLabel = new JLabel();
JLabel titleLabel = new JLabel("Student Software Beta Edition");
JPanel addStudentPanel = new JPanel();
JTextField studentName = new JTextField();
JTextField physicsMarks = new JTextField();
JTextField biologyMarks = new JTextField();
JTextField mathsMarks = new JTextField();
JButton submitDetails = new JButton("Submit Details");
JPanel studentDetailsPanel = new JPanel();
JTextField studentID1 = new JTextField();
JTextArea studentInfo = new JTextArea();
JButton submitID1 = new JButton("Submit ID");
JPanel studentGradePanel = new JPanel();
JTextField studentID2 = new JTextField();
JTextArea studentGrade = new JTextArea();
JButton submitID2 = new JButton("Submit ID");
JPanel numberPassedPanel = new JPanel();
JTextArea studentPassed = new JTextArea();
JPanel classTopperPanel = new JPanel();
JTextArea studentTopper = new JTextArea();

public ProjectX(String frameTitle)
{
super(frameTitle);
setResizable(true);
setSize(400,400);
submitDetails.addActionListener(this);
submitID1.addActionListener(this);
submitID2.addActionListener(this);

getContentPane().setLayout(new BorderLayout());

getContentPane().add(titleLabel,"North");

tabbedPane.addTab("Add Student",addStudentPanel);
addStudentPanel.setLayout(new GridLayout(8,2,5,5));
addStudentPanel.add(new JLabel("Student Name: "));
addStudentPanel.add(studentName);
addStudentPanel.add(new JLabel("Physics Marks: "));
addStudentPanel.add(physicsMarks);
addStudentPanel.add(new JLabel("Biology Marks: "));
addStudentPanel.add(biologyMarks);
addStudentPanel.add(new JLabel("Maths Marks: "));
addStudentPanel.add(mathsMarks);
addStudentPanel.add(submitDetails);

tabbedPane.addTab("Student Details",studentDetailsPanel);
studentDetailsPanel.add(new JLabel("Enter Student ID: "));
studentDetailsPanel.add(studentID1);
studentDetailsPanel.add(submitID1);
studentDetailsPanel.add(new JLabel("Student Details:"));
studentDetailsPanel.add(studentInfo);

tabbedPane.addTab("Student Grade",studentGradePanel);
studentGradePanel.setLayout(new GridLayout(5,2,5,5));
studentGradePanel.add(new JLabel("Enter Student ID: "));
studentGradePanel.add(studentID2);
studentGradePanel.add(submitID2);
studentGradePanel.add(new JLabel("Student Grade:"));
studentGradePanel.add(studentGrade);

tabbedPane.addTab("Passed Student",numberPassedPanel);
numberPassedPanel.setLayout(new GridLayout(2,2,5,5));
numberPassedPanel.add(new JLabel("Number of Student Passed: "));
numberPassedPanel.add(studentPassed);

tabbedPane.addTab("Class Topper",classTopperPanel);
classTopperPanel.setLayout(new GridLayout(2,2,5,5));
classTopperPanel.add(new JLabel("Here are the class Toppers: "));
classTopperPanel.add(studentTopper);

tabbedPane.addChangeListener(this);
getContentPane().add(tabbedPane,"Center");

statusLabel.setText("Status: Normal");
getContentPane().add(statusLabel,"South");

setVisible(true);

}

public static void main(String args[])
{
ProjectX outputScreen = new ProjectX("Case Study");
}

public String setStudentInfo()
{
int id = studentDetails.addStudent(studentName.getText(),
Integer.parseInt(physicsMarks.getText()),
Integer.parseInt(biologyMarks.getText()),
Integer.parseInt(mathsMarks.getText()));
return
(" " +
line +
"Record Created For " + studentName +
"
" +
"Student ID: " + id +
"
" +
line );
}

public String getStudentInfo()
{
int id = Integer.parseInt(studentID1.getText());
if(studentDetails.getStudentDetails(id))
return ("
" +
line +
"Student Details
" +
line +
"Student ID:" + " " + id + "
" +
"Student Name:" + " " + studentDetails.studentName + "
" +
"Physics Marks:" + " " + studentDetails.physicsMarks + "
" +
"Biology Marks:" + " " + studentDetails.biologyMarks + "
" +
"Maths Marks:" + " " + studentDetails.mathsMarks + "
" +
line );
else
return("
Records Not Found for ID " + id);
}

public String getStudentGrade()
{
int id = Integer.parseInt(studentID2.getText());
studentDetails.getStudentDetails(id);
String grade;
if(studentDetails.studentName == null)
{
System.out.println("
Records Not Found for ID " + id);
return null;
}
if(studentDetails.physicsMarks <>
studentDetails.biologyMarks <>
passMarks)
{
grade = "Failed";
}
else
{
int avgMarks = (studentDetails.physicsMarks +
studentDetails.biologyMarks + studentDetails.mathsMarks)/3;
if(avgMarks >= passMarks && avgMarks < grade =" ">
Class";
else if(avgMarks >= secondClass && avgMarks < grade ="
"Second Class";
else if(avgMarks >= firstClass && avgMarks < grade =" ">
Class";
else grade = "Distinction";
}
return(line + "Grade For " + studentDetails.studentName + " is " + grade
+ "
" + line);
}

public String getNumberPasses()
{
int lastID = Registration.getNextID() -1;
boolean passed = true;
int numberPassed = 0;
for(int id = 1; id <= lastID; id++)
{
studentDetails.getStudentDetails(id);
if(studentDetails.physicsMarks >= passMarks &&
studentDetails.biologyMarks >= passMarks && studentDetails.mathsMarks >=
passMarks) numberPassed++;
}
return(line + "Number of Student Passed: " + numberPassed + "
" +
line);
}

public String getClassTopper()
{
int lastID = Registration.getNextID() -1;
String classTopper;
StringBuffer buffer = new StringBuffer(500);
int topMarks = 0;
for(int id = 1; id <= lastID; id++)
{
studentDetails.getStudentDetails(id);
int studentMarks = studentDetails.physicsMarks +
studentDetails.biologyMarks + studentDetails.mathsMarks;
if(studentMarks > topMarks) topMarks = studentMarks;
}
buffer.append(line + "Student Having Top Marks:
");
for(int id = 1; id <= lastID; id++)
{
studentDetails.getStudentDetails(id);
int studentMarks = studentDetails.physicsMarks +
studentDetails.biologyMarks + studentDetails.mathsMarks;
if(studentMarks == topMarks)
{
buffer.append(studentDetails.studentName + " Having Total Marks: " +
topMarks + "
");
}
}
buffer.append(line);
return(buffer.toString());
}

public void stateChanged(ChangeEvent e)
{
switch(tabbedPane.getSelectedIndex())
{
case 3: studentPassed.setText(getNumberPasses());
break;
case 4: studentTopper.setText(getClassTopper());
break;
}
}

public void actionPerformed(ActionEvent e)
{
if(e.getSource() == submitID1)
{
studentInfo.setText(getStudentInfo());
}
else if(e.getSource() == submitID2)
{
studentGrade.setText(getStudentGrade());
}
if(e.getSource() == submitDetails)
{
setStudentInfo();
}
}

}


//Registration Class
class Registration
{
private int topScore = 90;
private int passMarks = 35;
private int firstClass = 65;
private int secondClass = 45;
private static String idFile = "id.dat";
private static String studentFile = "stdfile.dat";

public int id;
public String studentName;
public int physicsMarks;
public int biologyMarks;
public int mathsMarks;

public int addStudent(String studentName, int physicsMarks, int
biologyMarks, int mathsMarks)
{
int id = 0;
try
{
FileWriter fileOutput = new FileWriter(Registration.studentFile,true);
id = Registration.getNextID();
String buffer = id + "|" + studentName + "|" + physicsMarks + "|" +
biologyMarks + "|" + mathsMarks + "
";
fileOutput.write(buffer);
fileOutput.close();
Registration.setID(id);
}
catch(IOException e)
{
System.err.println(e.toString());
System.exit(1);
}
return id;

}

//Function to get the details of a student given the ID
public boolean getStudentDetails(int id)
{
try
{
FileReader fileInput = new FileReader(Registration.studentFile);
BufferedReader br = new BufferedReader(fileInput);
{

String str;
while((str = br.readLine()) != null)
{
StringTokenizer fields = new StringTokenizer(str,"|");
if(Integer.parseInt(fields.nextToken()) == id)
{
this.id = id;
this.studentName = fields.nextToken();
this.physicsMarks = Integer.parseInt(fields.nextToken());
this.biologyMarks = Integer.parseInt(fields.nextToken());
this.mathsMarks = Integer.parseInt(fields.nextToken());
return true;
}
}
}

}

catch(IOException e)
{
System.err.println(e.toString());
System.exit(1);
}

return false;
}

public int getTopScore()
{
return topScore;
}

public int getPassMarks()
{
return passMarks;
}

public int getFirstClass()
{
return firstClass;
}

public int getSecondClass()
{
return secondClass;
}

//Function to get the next ID available
public static int getNextID()
{
int id = 0;
try
{
RandomAccessFile studentIDFile = new
RandomAccessFile(Registration.idFile,"rw");
if(studentIDFile.length() == 0)
{
id = 0;
}
else id = studentIDFile.readInt();
id++;
studentIDFile.close();
}

catch(IOException e)
{
System.err.println(e.toString());
System.exit(1);
}
return id;
}

//Function to Store current ID in a file
public static void setID(int id)
{
try
{
RandomAccessFile studentIDFile = new
RandomAccessFile(Registration.idFile,"rw");
studentIDFile.seek(0);
studentIDFile.writeInt(id);
studentIDFile.close();
}

catch(IOException e)
{
System.err.println(e.toString());
System.exit(1);
}
}
}



Program to Set the foreground and background color to the text area in Java

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

class colopat extends Frame
{
Checkbox r,g,b;
Checkbox m,y,gr,p,w,bl,c;
TextArea ta;
Checkbox r1,g1,b1;
Checkbox m1,y1,gr1,p1,w1,bl1,c1;
Label ba,fo;
Panel pa1,p2,p3;

colopat()
{
setSize(800,600);

setLayout(new BorderLayout());
pa1=new Panel(new GridLayout(5,2,10,10));
p2=new Panel(new GridLayout(5,2,10,10));

CheckboxGroup cbg=new CheckboxGroup();

r=new Checkbox("red",cbg,false);
g=new Checkbox("green",cbg,false);
b=new Checkbox("blue",cbg,false);
m=new Checkbox("megenta",cbg,false);
y=new Checkbox("yellow",cbg,false);
gr=new Checkbox("grey",cbg,false);
p=new Checkbox("pink",cbg,false);
w=new Checkbox("white",cbg,false);
bl=new Checkbox("black",cbg,true);
c=new Checkbox("cyan",cbg,false);
ba=new Label("BACKGROUND COLORS",Label.CENTER);
ba.setBackground(Color.pink);

pa1.add(ba);
pa1.add(r);
pa1.add(b);
pa1.add(m);
pa1.add(y);
pa1.add(gr);
pa1.add(p);
pa1.add(w);
pa1.add(bl);
pa1.add(c);
add("West",pa1);

ta=new TextArea(5,25);
p3=new Panel(new GridLayout(3,1));
p3.add(new Label("Text Area",1));
p3.add(ta);
add("Center",p3);

r.addItemListener(new CheckBoxHandler(this));
g.addItemListener(new CheckBoxHandler(this));
b.addItemListener(new CheckBoxHandler(this));
m.addItemListener(new CheckBoxHandler(this));
y.addItemListener(new CheckBoxHandler(this));
gr.addItemListener(new CheckBoxHandler(this));
p.addItemListener(new CheckBoxHandler(this));
w.addItemListener(new CheckBoxHandler(this));
c.addItemListener(new CheckBoxHandler(this));
bl.addItemListener(new CheckBoxHandler(this));

CheckboxGroup cbg1=new CheckboxGroup();
r1=new Checkbox("red",cbg1,false);
g1=new Checkbox("green",cbg1,false);
b1=new Checkbox("blue",cbg1,false);
m1=new Checkbox("megenta",cbg1,false);
y1=new Checkbox("yellow",cbg1,false);
gr1=new Checkbox("grey",cbg1,false);
p1=new Checkbox("pink",cbg1,false);
w1=new Checkbox("white",cbg1,false);
bl1=new Checkbox("black",cbg1,true);
c1=new Checkbox("cyan",cbg1,false);
fo=new Label("FOREGROUND COLORS");
fo.setBackground(Color.pink);

p2.add(fo);
p2.add(c1);
p2.add(g1);
p2.add(b1);
p2.add(m1);
p2.add(y1);
p2.add(gr1);
p2.add(p1);
p2.add(w1);
p2.add(bl1);
p2.add(c1);
add("East",p2);

r1.addItemListener(new CheckBoxHandler(this));
g1.addItemListener(new CheckBoxHandler(this));
b1.addItemListener(new CheckBoxHandler(this));
m1.addItemListener(new CheckBoxHandler(this));
y1.addItemListener(new CheckBoxHandler(this));
gr1.addItemListener(new CheckBoxHandler(this));
p1.addItemListener(new CheckBoxHandler(this));
w1.addItemListener(new CheckBoxHandler(this));
c1.addItemListener(new CheckBoxHandler(this));
bl1.addItemListener(new CheckBoxHandler(this));
c1.addItemListener(new CheckBoxHandler(this));

addWindowListener(new mywindowAdapter(this));

setVisible(true);
}

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

class CheckBoxHandler implements ItemListener
{
colopat cp;

CheckBoxHandler(colopat cp)
{
this.cp=cp;
}
public void itemStateChanged(ItemEvent ie)
{
if(cp.r.getState())
cp.ta.setBackground(Color.red);
else if(cp.g.getState())
cp.ta.setBackground(Color.green);
else if(cp.b.getState())
cp.ta.setBackground(Color.blue);
else if(cp.m.getState())
cp.ta.setBackground(Color.magenta);
else if(cp.y.getState())
cp.ta.setBackground(Color.yellow);
else if(cp.gr.getState())
cp.ta.setBackground(Color.lightGray);
else if(cp.bl.getState())
cp.ta.setBackground(Color.black);
else if(cp.w.getState())
cp.ta.setBackground(Color.white);
else if(cp.p.getState())
cp.ta.setBackground(Color.pink);
else
cp.ta.setBackground(Color.cyan);


if(cp.r1.getState())
cp.ta.setForeground(Color.red);
else if(cp.g1.getState())
cp.ta.setForeground(Color.green);
else if(cp.b1.getState())
cp.ta.setForeground(Color.blue);
else if(cp.m1.getState())
cp.ta.setForeground(Color.magenta);
else if(cp.y1.getState())
cp.ta.setForeground(Color.yellow);
else if(cp.gr1.getState())
cp.ta.setForeground(Color.lightGray);
else if(cp.bl1.getState())
cp.ta.setForeground(Color.black);
else if(cp.w1.getState())
cp.ta.setForeground(Color.white);
else if(cp.p1.getState())
cp.ta.setForeground(Color.pink);
else
cp.ta.setForeground(Color.cyan);
}
}

class mywindowAdapter extends WindowAdapter
{
colopat cp;

mywindowAdapter(colopat cp)
{
this.cp=cp;
}
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}

Program to convert numbers in a file to corresponding words.

import java.io.*;
import java.lang.*;

class NumToWords
{
public static void main(String a[]) throws IOException
{
String s="";
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter filename : ");
try
{
s=br.readLine();
}catch(Exception e){}
InputStream in=new FileInputStream(s);
MyInputStream mis=new MyInputStream(in);
mis.changeNumbers();
in.close();
mis.close();
}
}
class MyInputStream extends FilterInputStream
{
InputStream is;
MyInputStream(InputStream in)
{
super(in);
is=in;
}
public void changeNumbers() throws IOException
{
PushbackInputStream pis;
String num="";
char ch;
int c;
pis=new PushbackInputStream(is);
while((c=pis.read())!=-1)
{
ch=(char)c;
if('0'<=ch&&ch<='9')
{
num="";
while('0'<=ch&&ch<='9'&&c!=-1)
{
num=num+ch;
c=pis.read();
ch=(char)c;
}
System.out.print(MyInputStream.process(num));
pis.unread(ch);
}
else
System.out.print(ch);
}
}
static String process(String str)
{
String a1[]={"One","Two","Three","Four","Five","Six","Seven","Eight","Nine"};
String a2[]={"Twenty","Thirty","Fourty","Fifty","Sixty","Seventy","Eighty","Ninety"};
String a3[]={"Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"};
String a4[]={"Hundered","Thousand","Lakhs","Crores"};
int num=0;
try
{
num=Integer.parseInt(str);
}catch(Exception e){}
if(num==0)
return "Zero";
int n,n1;
String ans="";
String ans1="";
n1=num%10;
num=num/10;
if(n1!=0)
ans=a1[n1-1];
if(num>0)
{
n=num%10;
num=num/10;
if(n==1)
ans=a3[n1];
else if(n!=0)
ans=a2[n-2]+" "+ans;
}
if(num>0)
{
n=num%10;
num=num/10;
if(n!=0)
ans=a1[n-1]+" "+a4[0]+" "+ans;
}
for(int i=1;num>0;i++)
{
n1=num%10;
num=num/10;
if(n1!=0)
ans1=a1[n1-1];
if(num>0)
{
n=num%10;
num=num/10;
if(n==1)
ans1=a3[n1];
else if(n!=0)
ans1=a2[n-2]+" "+ans1;
}
ans=ans1+" "+a4[i]+" "+ans;
ans1="";
}
return(ans);
}
}

Program to counting number of Chars, Words and Lines in a given file in Java

import java.lang.*;
import java.io.*;
import java.util.*;
class WordCount
{
public static void main(String arg[]) throws Exception
{
int char_count=0;
int word_count=0;
int line_count=0;
String s;
StringTokenizer st;
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter filename : ");
s=buf.readLine();
buf=new BufferedReader(new FileReader(s));
while((s=buf.readLine())!=null)
{
line_count++;
st=new StringTokenizer(s," ,;:.");
while(st.hasMoreTokens())
{
word_count++;
s=st.nextToken();
char_count+=s.length();
}
}
System.out.println("Character Count : "+char_count);
System.out.println("Word Count : "+word_count);
System.out.println("Line Count : "+line_count);
buf.close();
}
}

student management system Project In Java

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


public class menu extends Frame implements
WindowListener,ActionListener
{
MenuBar mb;
MenuItem student,rollnowise,namewise,allresult;
public static menu m;
rollnowise rw;
namewise n;
student st;
int x,y,d;

public menu()
{
super("menu ARPAN");
addWindowListener(this);
x=y=700;
d=10;
setSize(x,y);
setBackground(Color.orange);
addMenu();
show();
}

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


void addMenu()
{
MenuBar mb=new MenuBar();
Menu register=new Menu("REGISTER");
Menu inquery=new Menu("INQUERY");
register.add("STUDENT");
register.add("EXIT");
inquery.add("ROLLNOWISE");
inquery.add("NAMEWISE");

mb.add(register);
mb.add(inquery);

setMenuBar(mb);

register.addActionListener(this);
inquery.addActionListener(this);

}





public void actionPerformed(ActionEvent ae)

{
String arg=ae.getActionCommand();
if(ae.getSource() instanceof Menu)
if(arg.equals("EXIT"))
{
System.exit(0);
}
if(ae.getSource() instanceof Menu)
if("STUDENT".equals(arg))
{
st=new student();
st.show();
}
if(ae.getSource() instanceof Menu)
if("ROLLNOWISE".equals(arg))
{
rw=new rollnowise();
rw.show();
}
if(ae.getSource() instanceof Menu)
if("NAMEWISE".equals(arg))
{
n=new namewise();
n.show();
}
}


public void windowClosed(WindowEvent we){}
public void windowDeiconified(WindowEvent we){}
public void windowIconified(WindowEvent we){}
public void windowActivated(WindowEvent we){}
public void windowDeactivated(WindowEvent we){}
public void windowOpened(WindowEvent we){}
public void windowClosing(WindowEvent we)
{
while(x>0 && y>0)
{
setSize(x,y);
x=x-d;
y=y-d;
show();
}
System.out.println("mail me at arpankumarsingh@yahoo.com");
dispose();
System.exit(0);

}
}




//class for name wise report

class namewise extends Frame implements WindowListener,ActionListener
{
public static namewise nw;
Label l1=new Label("NAME",Label.LEFT);
Label l2=new Label("ROLLNO",Label.LEFT);
Label l3=new Label("COLG",Label.LEFT);
Label l4=new Label("SUB1",Label.LEFT);
Label l5=new Label("SUB2",Label.LEFT);
Label l6=new Label("SUB3",Label.LEFT);
Label l7=new Label("SUB4",Label.LEFT);
Label l8=new Label("SUB5",Label.LEFT);
TextField tf_entername=new TextField(20);
Button but_entername =new Button("FIND");
Button ok=new Button("OK");
Graphics g;
String sqlstr;
Statement st;
GridLayout gl=new GridLayout(1,2);
GridLayout cl=new GridLayout(1,5);

Font font18=new Font("VinetaBT",Font.BOLD|Font.ITALIC,18);

int x,y,d;
Dialog dlg;
Label msg;

public namewise()
{
super("NAMEWISE");
addWindowListener(this);
setLayout(new GridLayout(12,1));
setBackground(Color.orange);
setForeground(Color.black);
addMenu();
x=550;

y=450;
d=100;
setSize(x,y);
show();
}

void addMenu()
{
Panel p4=new Panel();
Label l11=new Label("ENTERNAME");

p4.add(l11);
p4.add(tf_entername);
p4.add(but_entername);
add(p4);

but_entername.addActionListener(this);
ok.addActionListener(this);


//Dialog for confirmation

dlg=new Dialog(this,"Inventory Management System",false);
dlg.setLayout(new GridLayout(2,1));
dlg.setSize(100,100);
dlg.setLocation(200,100);
ok.setSize(50,50);
msg=new Label("NAME NOT FOUND");
dlg.add(msg);
dlg.add(ok);

}


public void actionPerformed(ActionEvent e)
{
Panel p1=new Panel();
l1.setFont(font18);
l2.setFont(font18);
p1.setLayout(gl);
p1.add(l1);
p1.add(l2);
g=getGraphics();
g.drawLine(40,0,40,0);

Panel p2=new Panel();
l3.setFont(font18);
p2.add(l3);
p2.setLayout(gl);

Panel p3=new Panel();
l4.setFont(font18);
l5.setFont(font18);
l6.setFont(font18);
l7.setFont(font18);
l8.setFont(font18);

p3.add(l4);
p3.add(l5);
p3.add(l6);
p3.add(l7);
p3.add(l8);
p3.setLayout(cl);


String arg=e.getActionCommand();
if(e.getSource() instanceof Button)
if("FIND".equals(arg))
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbc:odbc:stu","","");
sqlstr="select * from stu1 where NAME='"+
tf_entername.getText()+"'";
st=con.createStatement();
ResultSet rs;
rs= st.executeQuery(sqlstr);

while(rs.next())
{
Panel a1=new Panel();
l1=new Label("",Label.LEFT);
l2=new Label("",Label.LEFT);
l1.setFont(font18);
l2.setFont(font18);
a1.setLayout(gl);

Panel a2=new Panel();
l3=new Label("",Label.LEFT);
l3.setFont(font18);
a2.setLayout(gl);

Panel a3=new Panel();
l4=new Label("",Label.LEFT);
l5=new Label("",Label.LEFT);
l6=new Label("",Label.LEFT);
l7=new Label("",Label.LEFT);
l8=new Label("",Label.LEFT);
l4.setFont(font18);

l5.setFont(font18);

l6.setFont(font18);

l7.setFont(font18);

l8.setFont(font18);
a3.setLayout(cl);

l1.setText(rs.getString("NAME"));
l2.setText(""+rs.getInt("ROLLNO"));
l3.setText(rs.getString("COLG"));
l4.setText(""+rs.getInt("SUB1"));
l5.setText(""+rs.getInt("SUB2"));
l6.setText(""+rs.getInt("SUB3"));
l7.setText(""+rs.getInt("SUB4"));
l8.setText(""+rs.getInt("SUB5"));

a1.add(l1);
a1.add(l2);

a2.add(l3);


a3.add(l4);
a3.add(l5);
a3.add(l6);
a3.add(l7);
a3.add(l8);

add(p1);
add(a1);

add(p2);
add(a2);

add(p3);
add(a3);
show();
}
}
catch(ClassNotFoundException se)
{
tf_entername.setText("Error : " + se.toString());

}
catch(SQLException se)
{
tf_entername.setText("Error : " + se.toString());

}
}

public void windowClosed(WindowEvent we){}
public void windowDeiconified(WindowEvent we){}
public void windowIconified(WindowEvent we){}
public void windowActivated(WindowEvent we){}
public void windowDeactivated(WindowEvent we){}
public void windowOpened(WindowEvent we){}

public void windowClosing(WindowEvent we)
{
while(x>0 && y>0)
{
setSize(x,y);
x=x-d;
y=y-d;
show();
}
dispose();

}
}


//class for rollnowise report
class rollnowise extends Frame implements
WindowListener,ActionListener
{

public static rollnowise rw;
Label l1=new Label("NAME",Label.LEFT);
Label l2=new Label("ROLLNO",Label.LEFT);
Label l3=new Label("COLG",Label.LEFT);
Label l4=new Label("SUB1",Label.LEFT);
Label l5=new Label("SUB2",Label.LEFT);
Label l6=new Label("SUB3",Label.LEFT);
Label l7=new Label("SUB4",Label.LEFT);
Label l8=new Label("SUB5",Label.LEFT);
TextField tf_entername=new TextField(20);
Button but_entername =new Button("FIND");
String sqlstr;
Statement st;
GridLayout gl=new GridLayout(1,2);
GridLayout cl=new GridLayout(1,5);

Font font18=new Font("VinetaBT",Font.BOLD|Font.ITALIC,18);

int x,y,d;


public rollnowise()
{
super("ROLLNOWISE");
addWindowListener(this);
setLayout(new GridLayout(12,1));
setBackground(Color.orange);
setForeground(Color.black);
addMenu();
x=550;
y=450;
d=100;
setSize(x,y);
show();
}



void addMenu()
{
Panel p4=new Panel();
Label l11=new Label("ENTERROLLNO");

p4.add(l11);
p4.add(tf_entername);
p4.add(but_entername);
add(p4);

but_entername.addActionListener(this);
}

public void actionPerformed(ActionEvent e)
{
Panel p1=new Panel();
l1.setFont(font18);
l2.setFont(font18);
p1.setLayout(gl);


p1.add(l1);
p1.add(l2);
l3.setFont(font18);
Panel p2=new Panel();
p2.add(l3);
p2.setLayout(gl);

Panel p3=new Panel();

l4.setFont(font18);

l5.setFont(font18);

l6.setFont(font18);

l7.setFont(font18);

l8.setFont(font18);
p3.add(l4);
p3.add(l5);
p3.add(l6);
p3.add(l7);
p3.add(l8);
p3.setLayout(cl);

/* Panel p4=new Panel();
Label l11=new Label("ENTERROLLNO");

p4.add(l11);
p4.add(tf_entername);
p4.add(but_entername);
add(p4);
add(p1);
add(p2);
add(p3);
*/
String arg=e.getActionCommand();
if(e.getSource() instanceof Button)
if("FIND".equals(arg))
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbc:odbc:stu","","");
sqlstr="select * from stu1 where ROLLNO="+
tf_entername.getText()+"";
st=con.createStatement();
ResultSet rs;
rs= st.executeQuery(sqlstr);


while(rs.next())
{
Panel a1=new Panel();
l1=new Label("",Label.LEFT);
l2=new Label("",Label.LEFT);
l1.setFont(font18);
l2.setFont(font18);
a1.setLayout(gl);

Panel a2=new Panel();
l3=new Label("",Label.LEFT);
l3.setFont(font18);
a2.setLayout(gl);

Panel a3=new Panel();
l4=new Label("",Label.LEFT);
l5=new Label("",Label.LEFT);
l6=new Label("",Label.LEFT);
l7=new Label("",Label.LEFT);
l8=new Label("",Label.LEFT);
l4.setFont(font18);

l5.setFont(font18);

l6.setFont(font18);

l7.setFont(font18);

l8.setFont(font18);
a3.setLayout(cl);

l1.setText(rs.getString("NAME"));
l2.setText(""+rs.getInt("ROLLNO"));
l3.setText(rs.getString("COLG"));
l4.setText(""+rs.getInt("SUB1"));
l5.setText(""+rs.getInt("SUB2"));
l6.setText(""+rs.getInt("SUB3"));
l7.setText(""+rs.getInt("SUB4"));
l8.setText(""+rs.getInt("SUB5"));

a1.add(l1);
a1.add(l2);

a2.add(l3);


a3.add(l4);
a3.add(l5);
a3.add(l6);
a3.add(l7);
a3.add(l8);

add(p1);
add(a1);

add(p2);
add(a2);

add(p3);
add(a3);
show();
}
}
catch(ClassNotFoundException se)
{

tf_entername.setText("Error : " + se.toString());
}

catch(SQLException se)
{
tf_entername.setText("Error : " + se.toString());
}
}

public void windowClosed(WindowEvent we){}
public void windowDeiconified(WindowEvent we){}
public void windowIconified(WindowEvent we){}
public void windowActivated(WindowEvent we){}
public void windowDeactivated(WindowEvent we){}
public void windowOpened(WindowEvent we){}

public void windowClosing(WindowEvent we)
{
while(x>0 && y>0)
{
setSize(x,y);
x=x-d;
y=y-d;
show();
}
dispose();

}
}


//class which help in storing records in the database
class student extends Frame implements ActionListener,WindowListener

{
public static student st;
TextField tf_name=new TextField(20);
TextField tf_rollno=new TextField(20);
TextField tf_colg=new TextField(20);
TextField tf_marks=new TextField(20);
TextField tf_sub1=new TextField(4);
TextField tf_sub2=new TextField(4);
TextField tf_sub3=new TextField(4);
TextField tf_sub4=new TextField(4);
TextField tf_sub5=new TextField(4);


Label l2=new Label("ROLLNO");
Label l1=new Label("NAME");
Label l3=new Label("MARKS");
Label l4=new Label("COLG");
Label l5=new Label("MARK SHEET");
Label l6=new Label("SUB1");
Label l7=new Label("SUB2");
Label l8=new Label("SUB3");
Label l9=new Label("SUB4");
Label l10=new Label("SUB5");
Button but_add=new Button("ADD");
Button but_edit=new Button("EDIT");
Button but_find=new Button("FIND");
Button but_delete=new Button("DELETE");
Button but_cancel=new Button("CANCEL");
Button ok=new Button("OK");
Dialog dlg;
Label msg;
int x,y,d;

public student()
{
super("palce");
addWindowListener(this);
setLayout(new GridLayout(6,1));
setBackground(Color.yellow);
setVisible(true);
addmenu();
x=550;
y=450;
d=12;
setSize(x,y);
show();
}


void addmenu()
{
//GridLayout gl=new GridLayout();
Panel p1=new Panel();
p1.add(l1);
p1.add(tf_name);

p1.add(l2);
p1.add(tf_rollno);

Panel p2=new Panel();
p2.add(l5);
Panel p3=new Panel();
p3.add(but_add);
p3.add(but_find);
p3.add(but_cancel);
p3.add(but_edit);
p3.add(but_delete);



Panel p4=new Panel();
//p4.add(l3);
p4.add(l6);
p4.add(l7);
p4.add(l8);
p4.add(l9);
p4.add(l10);

Panel p8=new Panel();
p8.add(tf_sub1);
p8.add(tf_sub2);
p8.add(tf_sub3);
p8.add(tf_sub4);
p8.add(tf_sub5);

Panel p5=new Panel();
p5.add(l4);
p5.add(tf_colg);

add(p2);
add(p1);
add(p5);
add(p4);
add(p8);
add(p3);
but_add.addActionListener(this);
but_cancel.addActionListener(this);
but_find.addActionListener(this);
but_delete.addActionListener(this);
but_edit.addActionListener(this);
ok.addActionListener(this);
//Dialog for confirmation

dlg=new Dialog(this,"Inventory Management System",false);
dlg.setLayout(new GridLayout(2,1));
dlg.setSize(100,100);
dlg.setLocation(200,100);
ok.setSize(50,50);
msg=new Label("Record Updated");
dlg.add(msg);
dlg.add(ok);



}
public void actionPerformed(ActionEvent e)
{
String arg=e.getActionCommand();
//ADDBUTTON
if(e.getSource() instanceof Button)
if("ADD".equals(arg))
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:stu","","");
Statement st;

String sqlStr;
sqlStr="insert into
stu1(NAME,ROLLNO,COLG,SUB1,SUB2,SUB3,SUB4,SUB5)values('"+tf_name.getText()
+"',"+tf_rollno.getText()+",'"+tf_colg.getText()+"',"+tf_sub1.getText()+",
+tf_sub2.getText()+"," +tf_sub3.getText()+","+tf_sub4.getText()+","+tf_sub

5.getText()+")";
st=con.createStatement();
st.executeUpdate(sqlStr);
}
catch(ClassNotFoundException se)
{
// tf_name.setText("Error : " + se.toString());
msg.setText("ERROR");
dlg.show();
}
catch(SQLException se)
{
// tf_name.setText("Error : " + se.toString());
msg.setText("ENTER TEXTFIELD");
dlg.show();
}

//OK button

if ( e.getSource() instanceof Button)
if ("OK".equals(arg))
{ dlg.dispose();
}
//CANCEL
if(e.getSource() instanceof Button)
if("CANCEL".equals(arg))

{
tf_name.setText("");
tf_rollno.setText("");
tf_colg.setText("");
tf_sub1.setText("");
tf_sub2.setText("");
tf_sub3.setText("");
tf_sub4.setText("");
tf_sub5.setText("");
}
//FIND
if(e.getSource() instanceof Button)
if("FIND".equals(arg))
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:stu","","");
Statement st;
String sqlstr;
sqlstr="select * from stu1 where ROLLNO ="+tf_rollno.getText()+"";
st=con.createStatement();
ResultSet rs;
rs=st.executeQuery(sqlstr);
rs.next();
tf_name.setText(""+rs.getString("NAME"));
tf_colg.setText(""+rs.getString("COLG"));
tf_sub1.setText(""+rs.getInt("SUB1"));
tf_sub2.setText(""+rs.getInt("SUB2"));
tf_sub3.setText(""+rs.getInt("SUB3"));
tf_sub4.setText(""+rs.getInt("SUB4"));
tf_sub5.setText(""+rs.getInt("SUB5"));
}
catch(ClassNotFoundException se)
{
msg.setText("RECORD NOT FOUND");
dlg.show();

// tf_name.setText("Error : " + se.toString());
}
catch(SQLException se)
{
msg.setText("RECORD NOT FOUND");
dlg.show();
//tf_name.setText("Error : " + se.toString());
}
//DELETE
if(e.getSource() instanceof Button)
if("DELETE".equals(arg))
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:stu","","");
Statement st;
String sqlstr;
sqlstr="delete * from stu1 where ROLLNO="+tf_rollno.getText()+"";
st=con.createStatement();
st.executeUpdate(sqlstr);
tf_name.setText("");
tf_colg.setText("");
tf_sub1.setText("");
tf_sub2.setText("");
tf_sub3.setText("");
tf_sub4.setText("");
tf_sub5.setText("");

tf_rollno.setText("");
msg.setText("RECORD DELETED");
dlg.show();

}
catch(ClassNotFoundException se)
{
tf_name.setText("Error : " + se.toString());
}
catch(SQLException se)
{
tf_name.setText("Error : " + se.toString());
}

//EDIT
if(e.getSource() instanceof Button)
if("EDIT".equals(arg))
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:stu","","");
Statement st;
String sqlstr;
sqlstr="update stu1 set
NAME='"+tf_name.getText()+"',SUB1="+tf_sub1.getText()+",SUB2="+tf_sub2.get
Text()+",SUB3="+tf_sub3.getText()+",SUB4="+tf_sub4.getText()+",SUB5="+tf_s
ub5.getText()+",COLG='"+tf_colg.getText()+"' where
ROLLNO="+tf_rollno.getText();
st=con.createStatement();
st.executeUpdate(sqlstr);
msg.setText("RECORD UPDATED");
dlg.show();
}
catch(ClassNotFoundException se)
{

tf_name.setText("Error : " + se.toString());
}
catch(SQLException se)
{

tf_name.setText("Error : " + se.toString());
}
}
public void windowClosed(WindowEvent we){}
public void windowDeiconified(WindowEvent we){}
public void windowIconified(WindowEvent we){}
public void windowActivated(WindowEvent we){}
public void windowDeactivated(WindowEvent we){}
public void windowOpened(WindowEvent we){}
public void windowClosing(WindowEvent we)
{
while(x>0 && y>0)
{
setSize(x,y);
x=x-d;
y=y-d;
show();
}
dispose();
}

}

We Are Founder..