informatics practices practical filemminfotek.com/images/practical1.pdfname of field variable name...

19
2010 Anurag Kumar Class: XII Science School: K V No 1 Bathinda Cantt Session: 2010 - 2011 Roll No.: Informatics Practices Practical File

Upload: others

Post on 18-Mar-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Informatics Practices Practical Filemminfotek.com/images/Practical1.pdfName Of Field Variable Name Font Items Text Updating/Deleting Table Label 1 depnolbl Tahoma14 bold - DeptNo Label

2010

Anurag Kumar

Class: XII Science

School: K V No 1 Bathinda Cantt

Session: 2010 - 2011

Roll No.:

Informatics Practices Practical File

Page 2: Informatics Practices Practical Filemminfotek.com/images/Practical1.pdfName Of Field Variable Name Font Items Text Updating/Deleting Table Label 1 depnolbl Tahoma14 bold - DeptNo Label
Page 3: Informatics Practices Practical Filemminfotek.com/images/Practical1.pdfName Of Field Variable Name Font Items Text Updating/Deleting Table Label 1 depnolbl Tahoma14 bold - DeptNo Label
Page 4: Informatics Practices Practical Filemminfotek.com/images/Practical1.pdfName Of Field Variable Name Font Items Text Updating/Deleting Table Label 1 depnolbl Tahoma14 bold - DeptNo Label

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"); }

Page 5: Informatics Practices Practical Filemminfotek.com/images/Practical1.pdfName Of Field Variable Name Font Items Text Updating/Deleting Table Label 1 depnolbl Tahoma14 bold - DeptNo Label

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 bold

- Search Field

Label3 critLbl Tahoma 14 bold

- Criteria

TextField1 critTF Tahoma 14 bold

-

ComboBox 1 srchFldCBX Tahoma 8 Empno,ename,job, sal,deptno

-

ComboBox2 opCBX Tahoma 8 =,<,>,!= -

Page 6: Informatics Practices Practical Filemminfotek.com/images/Practical1.pdfName Of Field Variable Name Font Items Text Updating/Deleting Table Label 1 depnolbl Tahoma14 bold - DeptNo Label
Page 7: Informatics Practices Practical Filemminfotek.com/images/Practical1.pdfName Of Field Variable Name Font Items Text Updating/Deleting Table Label 1 depnolbl Tahoma14 bold - DeptNo Label

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();

Page 8: Informatics Practices Practical Filemminfotek.com/images/Practical1.pdfName Of Field Variable Name Font Items Text Updating/Deleting Table Label 1 depnolbl Tahoma14 bold - DeptNo Label

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); }

Page 9: Informatics Practices Practical Filemminfotek.com/images/Practical1.pdfName Of Field Variable Name Font Items Text Updating/Deleting Table Label 1 depnolbl Tahoma14 bold - DeptNo Label

Name Of Field Variable Name Font Items Text

Updating/Deleting Table

Label 1 depnolbl Tahoma14 bold - DeptNo

Label 2 Depnamelbl Tahoma 14 bold

- Dep-Name

Label3 Loclbl Tahoma 14 bold

- Location

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

Page 10: Informatics Practices Practical Filemminfotek.com/images/Practical1.pdfName Of Field Variable Name Font Items Text Updating/Deleting Table Label 1 depnolbl Tahoma14 bold - DeptNo Label
Page 11: Informatics Practices Practical Filemminfotek.com/images/Practical1.pdfName Of Field Variable Name Font Items Text Updating/Deleting Table Label 1 depnolbl Tahoma14 bold - DeptNo Label

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); }

Page 12: Informatics Practices Practical Filemminfotek.com/images/Practical1.pdfName Of Field Variable Name Font Items Text Updating/Deleting Table Label 1 depnolbl Tahoma14 bold - DeptNo Label

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

Page 13: Informatics Practices Practical Filemminfotek.com/images/Practical1.pdfName Of Field Variable Name Font Items Text Updating/Deleting Table Label 1 depnolbl Tahoma14 bold - DeptNo Label
Page 14: Informatics Practices Practical Filemminfotek.com/images/Practical1.pdfName Of Field Variable Name Font Items Text Updating/Deleting Table Label 1 depnolbl Tahoma14 bold - DeptNo Label

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();

}

Page 15: Informatics Practices Practical Filemminfotek.com/images/Practical1.pdfName Of Field Variable Name Font Items Text Updating/Deleting Table Label 1 depnolbl Tahoma14 bold - DeptNo Label

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 -

Page 16: Informatics Practices Practical Filemminfotek.com/images/Practical1.pdfName Of Field Variable Name Font Items Text Updating/Deleting Table Label 1 depnolbl Tahoma14 bold - DeptNo Label
Page 17: Informatics Practices Practical Filemminfotek.com/images/Practical1.pdfName Of Field Variable Name Font Items Text Updating/Deleting Table Label 1 depnolbl Tahoma14 bold - DeptNo Label

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);

Page 18: Informatics Practices Practical Filemminfotek.com/images/Practical1.pdfName Of Field Variable Name Font Items Text Updating/Deleting Table Label 1 depnolbl Tahoma14 bold - DeptNo Label

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

Page 19: Informatics Practices Practical Filemminfotek.com/images/Practical1.pdfName Of Field Variable Name Font Items Text Updating/Deleting Table Label 1 depnolbl Tahoma14 bold - DeptNo Label