You are on page 1of 19

2010

Informatics Practices
Practical File

Anurag Kumar
Class: XII Science
School: K V No 1 Bathinda Cantt
Session: 2010 - 2011
Roll No.:
private void emptyBTNActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
DefaultTableModel model = (DefaultTableModel)empTbl.getModel();
int rows = model.getRowCount();
//now remove all components of table
if (rows>0){
for(int i=0;i<rows;i++){
model.removeRow(0);
}
}
}

private void searchBTNActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
emptyBTN.doClick();
DefaultTableModel model = (DefaultTableModel)empTbl.getModel();
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/employee","root","a");
Statement stmt = con.createStatement();
String sfld = (String)srchFldCBX.getSelectedItem();
String op = (String)opCBX.getSelectedItem();
String cirt = criteriaTF.getText();
String query = "SELECT EMPNO,ENAME,JOB,HIREDATE,SAL,DEPTNO FROM employee
WHERE"+sfld+""+op+""+cirt+";";
ResultSet rs = stmt.executeQuery(query);
while(rs.next()){
model.addRow(new Object[]{
rs.getInt(1),rs.getInt(2),rs.getString(3),rs.getDate(4),rs.getFloat(5),rs.getInt(6),
} );

}
rs.close();
stmt.close();
con.close();

}
catch(Exception e){
JOptionPane.showMessageDialog(null,"Error in Connectivity");

}
Name Of Field Variable Name Font Items Text
Search Criteria Application on Database employee
Label 1 title Tahoma18 bold - Write Required
Query
Label 2 search Tahoma 14 - Search Field
bold
Label3 critLbl Tahoma 14 - Criteria
bold
TextField1 critTF Tahoma 14 -
bold
ComboBox 1 srchFldCBX Tahoma 8 Empno,ename,job, -
sal,deptno
ComboBox2 opCBX Tahoma 8 =,<,>,!= -
public class record_load extends javax.swing.JFrame {
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
/** Creates new form record_load */
public record_load() {
initComponents();
}
private void loadBTNActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/employee","root","a");
stmt = con.createStatement();
String dep = depnoTF.getText();
String query = "SELECT * From dept where deptno"+dep+";";
rs = stmt.executeQuery(query);
if (rs.next()){
String dno = rs.getString("depno");
String dname = rs.getString("dname");
String lc = rs.getString("loc");
dnameTF.setText(dname);
locTF.setText(lc);
updBtn.setEnabled(true);
delBTN.setEnabled(true);
dnameTF.setEnabled(true);
locTF.setEnabled(true);
}
else {
JOptionPane.showMessageDialog(null,"No Such Record Found");
}
}

catch(Exception e){
JOptionPane.showMessageDialog(null,"Error in Connectivity");

private void updBtnActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
int ans = JOptionPane.showConfirmDialog(null,"Surely wanna Update The Record");
if( ans == JOptionPane.YES_OPTION){
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/employee","root","a");
stmt = con.createStatement();
String dep = depnoTF.getText();
String query = "Update dept Set dname = '"+dnameTF.getText()+"',loc =
'"+locTF.getText()+"where deptno ="+dep+";";

stmt.executeUpdate(query);
JOptionPane.showMessageDialog(null,"Record Susscefully Updated");

}
catch(Exception e){
JOptionPane.showMessageDialog(null,"Error in Connectivity");

dnameTF.setText("");
depnoTF.setText("");
locTF.setText("");
updBtn.setEnabled(false);
delBTN.setEnabled(false);

}
}
}
private void delBTNActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:


int ans = JOptionPane.showConfirmDialog(null,"Surely wanna Update The Record");
if( ans == JOptionPane.YES_OPTION){
try{
stmt = con.createStatement();
String query = "Delete From dept where deptno ="+depnoTF.getText()+";";

stmt.executeUpdate(query);
JOptionPane.showMessageDialog(null,"Record Susscefully Deleted");
}
catch(Exception e){
JOptionPane.showMessageDialog(null,"Error in deletion!");
}
}

dnameTF.setText("");
depnoTF.setText("");
locTF.setText("");
updBtn.setEnabled(false);
delBTN.setEnabled(false);
}
Name Of Field Variable Name Font Items Text
Updating/Deleting Table
Label 1 depnolbl Tahoma14 bold - DeptNo
Label 2 Depnamelbl Tahoma 14 - Dep-Name
bold
Label3 Loclbl Tahoma 14 - Location
bold
TextField1 depnoTF Tahoma 14 -
bold
TextField2 dnameTF Tahoma 8 -
TextField3 locTF Tahoma 8 -
Button 1 Loadbtn Tahoma 12 - Load Btn
Button 2 updBtn Tahoma 12 - Update Record
Button 3 delBtn Tahoma 12 - Delete Record
At the top of the code write :

Import java.util.Random;
Then

private void SpinBtnActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
Random RandGen = new Random();
int n1 = RandGen.nextInt((10));
int n2 = RandGen.nextInt((10));
int n3 = RandGen.nextInt((10));
num1.setText(""+n1);
num2.setText(""+n2);
num3.setText(""+n3);

private void EndBtnActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
System.exit(0);
}
Name Of Field Variable Name Font Border Text
Main Form
Label 1 num1 Tahoma 20 bold - 0
Label 2 num2 Tahoma 20bold - 0
Label3 num4 Tahoma 20 bold - 0
Button 1 spinBtn Tahoma 20 bold - Spin
Button 2 endBtn Tahoma 20 bold - End
Label4 Title Tahoma 24 Bold - Lucky Seven
private void CopyBtnActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

TypeArea.copy();

private void PasteBtnActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

TypeArea.paste();

private void CutBtnActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

TypeArea.cut();

}
Name Of Field Variable Name Font Border Text
Main Form
Button1 cutBtn Tahoma 20 bold - Cut
Button2 copyBtn Tahoma 20bold - Copy
Button3 pasteBtn Tahoma 20 bold - Paste
TextArea1 Typearea Tahoma 12 -
private void tagoalbtnActionPerformed(java.awt.event.ActionEvent evt) {

String v1= tagoals.getText();


int goa = Integer.parseInt(v1);
goa = goa + 1;
tagoals.setText(""+goa);

// TODO add your handling code here:


}

private void tbgoalbtnActionPerformed(java.awt.event.ActionEvent evt) {


String v2 = tbgoals.getText();
int gob = Integer.parseInt(v2);
gob = gob +1;
tbgoals.setText(""+gob);

// TODO add your handling code here:


}

private void resbtnActionPerformed(java.awt.event.ActionEvent evt) {


String v1 = tagoals.getText();
int goa = Integer.parseInt(v1);
String v2 = tbgoals.getText();
int gob = Integer.parseInt(v2);
String res = (goa>gob? "Team A Wins" : (goa<gob) ? "Team B wins" : "Scores Levelled");
result.setText(res);
Name Of Field Variable Name Font Border Text
Main Form
Label1 Score Tahoma 20 bold - ScoreBoard
Label2 Football Tahoma 20bold - FootBAll Match
Label3 teamA Tahoma 12 bold - Team A
Label4 teamB Tahoma 12 bold - Team B
Label5 Tagoals Tahoma 48 bold Metallic Border 0
Label6 Tbgoals Tahoma 48 bold Metallic Border 0
Label7 Resultlbl Tahoma 14 bold Metallic Border
Button1 Resbtn Tahoma 14 - Declare Result
Button2 tagoalsbtn Tahoma 14 - Scored Goals
Button3 tagoalsbtn Tahoma14 - Scored Goals

You might also like