1. IMPORTANT CODDES(Part I)
int a = Integer.parseInt((String)jcombobox1.getSelectedItem());
String abc = (String)jcombobox1.getSelectedItem();
or
String abc = String.valueOf(jcombobox1.getSelectedItem());
jTextfield1.setEnable(false);
int vowelcount=0; char c; String a ="Kulbhushan";
for( int i = 0; i < a.length(); i++)
{ c = a.charAt(i); switch(c) { case 'a': System.out.println("Vowel"+c); vowelcount++; break; case 'e': System.out.println("Vowel"+c); vowelcount++; break; case 'i': System.out.println("Vowel"+c); vowelcount++; break; case 'o': System.out.println("Vowel"+c); vowelcount++; break; case 'u': System.out.println("Vowel"+c); vowelcount++; break; } } System.out.println("Total no of Vowels : " + vowelcount); System.out.println("Total no of Consonant : " + (a.length() - vowelcount));
String a = jTextField1.getText();
String p = new String(jPasswordField1.getPassword());
if(a.equals("kulbhushan") && p.equals("sir"))
{
JOptionPane.showMessageDialog(this, "Successful login");
}
else
{
JOptionPane.showMessageDialog(this, "login failed");
}
for(int i=1;i<=10;i++)
{
cmb.addItem(i);
}
private void BtnPrintActionPerformed(java.awt.event.ActionEvent evt) { // Here we use Table component to print data MessageFormat header = new MessageFormat("Patient Information"); MessageFormat Footer = new MessageFormat("Page{0,number,integer}"); try { Mytable.print(JTable.PrintMode.NORMAL,header,Footer); } catch(Exception ex) { JOptionPane.showMessageDialog(null, ex); } }
if(jComboBox1.getSelectedIndex()<=0)
{
JOptionPane.showMessageDialog(this, "Select Item first");
}
String[] a = new String[2];
a[0]="January";
a[1]="February";
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(a));
String a = jTextField1.getText();
if(a.isEmpty()==true)
{
JOptionPane.showMessageDialog(this, "Please fill value");
}
int MySlectedRow = jTable1.getSelectedRow(); if(MySlectedRow==-1) { JOptionPane.showMessageDialog(this, "Please Select At least one Row"); } else { int response = JOptionPane.showConfirmDialog(null, "Do you want to continue","Confirm",JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE); if(response==JOptionPane.YES_OPTION) { int row = jTable1.getSelectedRow(); int row = jTable1.getSelectedRow(); // 0 means first column // 1 means second column // 2 means third column int ID = Integer.parseInt(jTable1.getValueAt(row, 0).toString()); jTextField2.setText(jTable1.getValueAt(row, 1).toString()); // Now write your delete code here and pass the id to delete the object } }
private void jTextField1KeyPressed(java.awt.event.KeyEvent evt) { char c = evt.getKeyChar();
if ( ((c < '0') || (c > '9')) && (c != KeyEvent.VK_BACK_SPACE))
{ jTextField1.setEditable(false); } else { jTextField1.setEditable(true); } }
Step 1:- Add these library import javax.swing.JFrame; import java.awt.print.PrinterException; import java.util.logging.Level; import java.util.logging.Logger; Step 2: private void btnAddRecordActionPerformed(java.awt.event.ActionEvent evt) { txtReceipt.append("\t\t\t Jayshree Periwal International School" + "\n\n"+ "\n ##############################\n"+"\n\n"+ "First Name \t\t\t" + txtfirstname.getText()+ "\n\n"+ "Last Name:\t\t\t" + txtlastname.getText()+ "\n\n"+ "Mobile Number:\t\t\t" + txtmobileno.getText()+ "\n\n"+ "Refrence Number:\t\t" + txtrefreence.getText()+ "\n\n" ); } Step 3 : private void BtnPrintActionPerformed(java.awt.event.ActionEvent evt) { try { txtReceipt.print(); } catch (PrinterException ex) { Logger.getLogger(Temp.class.getName()).log(Level.SEVERE, null, ex); } }
import java.sql.SQLException; try { Statement stmk =(Statement)con.createStatement(); String sqlk ; sqlk = "insert into take(mobileno,username)values('"+ username +"','"+ ddk +"')"; stmk.executeUpdate(sqlk); } catch(SQLException e) { System.out.println("Message = " + e.getMessage()); JOptionPane.showMessageDialog(this, e.getMessage()); }
1. show tables;
2. desc student; or Describe student;
private void AddPatinetActionPerformed(java.awt.event.ActionEvent evt) { this.setVisible(false); new Dashboard().setVisible(true); }
You have to create this code at keypressed event
private void jTextField1KeyPressed(java.awt.event.KeyEvent evt) {
if(jTextField1.getText().length()>=5)
{
jTextField1.setText(jTextField1.getText().substring(0, 4));
}
private void btnCalculateReturnActionPerformed(java.awt.event.ActionEvent evt) { NewClass ClassObject = new NewClass(); int kuldd = ClassObject.SumTwoNumbers(5, 10); JOptionPane.showMessageDialog(this, kuldd); }
You have to add this files in header first
import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.Calendar;
private void formWindowOpened(java.awt.event.WindowEvent evt) { // TODO add your handling code here: SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy"); Date date = new Date(); jLabel2.setText(formatter.format(date)); Calendar cal = Calendar.getInstance(); cal.getTime(); SimpleDateFormat sdfd24hour = new SimpleDateFormat("HH:mm:ss"); SimpleDateFormat sdfd12hour = new SimpleDateFormat("hh:mm a"); jLabel3.setText(sdfd12hour.format(cal.getTime())); jLabel4.setText(sdfd24hour.format(cal.getTime())); }
Step1: first of all pehle ki tarah breakpoint lagao ASP.net ki tarah
Step 2: then keyboar Ctrl+Shift+f5 dabao, page run ho jaiyega
Step 3: phir button pe click kare jaha aapne brk point lagaya tha
Step 3:- thne f8 dabate jao or value check hoti jaigi
(In case if it is not working with f8 then use f7)
(Note For checking loop USe F8)
String studid = txtstudname.getText(); String studname = txtfathername.getText(); try { Class.forName("java.sql.DriverManager"); Connection conk = (Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/school","root","kulbhushan"); Statement stmk =(Statement)conk.createStatement(); DefaultTableModel model = (DefaultTableModel)jTable1.getModel(); String myquery; myquery = "select * from studinfo"; ResultSet rs = stmk.executeQuery(myquery); int rows = model.getRowCount(); for(int i = rows - 1; i >=0; i--) { model.removeRow(i); } while(rs.next()) { String teachername = rs.getString("mobileno"); String contactno = rs.getString("username"); model.addRow(new Object[]{teachername,contactno}); } stmk.close(); conk.close(); } catch(Exception ex) { JOptionPane.showMessageDialog(this, ex.getMessage()); }
int response; if(txtteachername.getText().isEmpty()) { JOptionPane.showMessageDialog(this, "Please Select Record First!!"); } else { try { Class.forName("java.sql.DriverManager"); Connection conk = (Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/school","root","kullu"); Statement stmk =(Statement)conk.createStatement(); response = JOptionPane.showConfirmDialog(null, "Do you want to continue","Confirm",JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE); if(response==JOptionPane.YES_OPTION) //JOptionPane.showMessageDialog(this, "yes right"); { String DeleteQuery; DeleteQuery = "delete from staff where teacherid=" + Mainteacherid + ""; stmk.executeUpdate(DeleteQuery); JOptionPane.showMessageDialog(this, "Deleted Successfully"); txtteachername.setText(""); txtcontactno.setText(""); txtsalary.setText(""); DefaultTableModel model = (DefaultTableModel)jTable1.getModel(); String myquery; myquery = "select * from staff"; ResultSet rs = stmk.executeQuery(myquery); while(rs.next()) { String teacherid = rs.getString("teacherid"); String teachername = rs.getString("teachername"); String contactno = rs.getString("contactno"); String teachingclass = rs.getString("teachingclass"); String salary = rs.getString("salary"); String Qualification = rs.getString("qualification"); String Experience = rs.getString("experience"); String gender = rs.getString("gender"); model.addRow(new Object[]{teacherid,teachername,gender,contactno,teachingclass,salary,Qualification,Experience}); } } stmk.close(); conk.close(); } catch(Exception ex) { JOptionPane.showMessageDialog(this, ex.getMessage()); } }
If u want to use tree component than use it Event- Tree_selection and write
your code according ur requirement.
import javax.swing.JOptionPane;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.sql.Driver;
import javax.swing.table.DefaultTableModel;
private void btnsaveActionPerformed(java.awt.event.ActionEvent evt) {
String teachername = txtteachername.getText();
String contactno = txtcontactno.getText();
String salary = txtsalary.getText();
String teachingclass = (String)cmbteachingclass.getSelectedItem();
String Qualification = (String)cmbqualification.getSelectedItem();
String Experience = (String)cmbexperience.getSelectedItem();
if(teachername.isEmpty())
{
JOptionPane.showMessageDialog(this, "Please Teacher Name First");
}
else if(contactno.isEmpty())
{
JOptionPane.showMessageDialog(this, "Please fill Contact No");
}
else if(salary.isEmpty())
{
JOptionPane.showMessageDialog(this, "Please fill Salary");
}
else
{
String Mygender="";
if(rdmale.isSelected())
{
Mygender=rdmale.getText();
}
else
{
Mygender=rdfemale.getText();
}
try
{
Class.forName("java.sql.DriverManager");
Connection conk = (Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/school","root",
"password");
Statement stmk =(Statement)conk.createStatement();
String sqlk ;
sqlk = "insert into staff(teachername,gender,contactno,teachingclass,salary,qualification,experience)
values('"+ teachername +"','"+ Mygender + "','" + contactno + "',
'" + teachingclass +"','"+ salary +"','" + Qualification +"','"+ Experience+"')";
stmk.executeUpdate(sqlk);
JOptionPane.showMessageDialog(this, "Saved Successfully");
txtteachername.setText("");
txtcontactno.setText("");
DefaultTableModel model = (DefaultTableModel)jTable1.getModel();
String myquery; myquery = "select * from staff";
ResultSet rs = stmk.executeQuery(myquery);
while(rs.next())
{
int Teacherid;
Teacherid = Integer.parseInt(rs.getString("teacherid"));
teachername = rs.getString("teachername");
contactno = rs.getString("contactno");
Mygender= rs.getString("gender");
teachingclass = rs.getString("teachingclass");
salary = rs.getString("salary");
Qualification = rs.getString("Qualification");
Experience = rs.getString("Experience");
//model.fireTableDataChanged();
model.addRow(new Object[]{Teacherid,teachername,Mygender,contactno,teachingclass,salary,
Qualification,Experience});
}
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(this, ex.getMessage());
}
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JOptionPane;
import java.sql.*;
import java.util.*;
String username = txtusername.getText();
String password = txtpassword.getText();
try
{
String url="jdbc:mysql://localhost:3306/school";
Properties prop=new Properties();
prop.setProperty("user","root");
prop.setProperty("password","");
Driver d = new com.mysql.jdbc.Driver();
Connection con = d.connect(url,prop);
if(con==null)
{
System.out.println("connection failed");
return;
}
else
{
Statement stmk =(Statement)con.createStatement();
String myquery;
myquery = "select * from stud";
ResultSet rs = stmk.executeQuery(myquery);
while(rs.next())
{
String MYusername = rs.getString("studname");
String MYPassword = rs.getString("fname");
if(username.equals(MYusername) && password.equals(MYPassword))
{
this.setVisible(false);
new staff().setVisible(true);
}
else
{
JOptionPane.showMessageDialog(this, "Incorrect Username Or Password");
}
}
}
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(this, ex.getMessage());
}
HOW TO START:-
Open the browser and just type localhost:80
or
localhost:80/phpmyadmin
NOTE:- Some times we see that after installing it not work it gives the error
404 NOt Found. Than we have to change some settings.
Step 1 :- U see that if folders save on C: Drive under the name
Xampp. after that go to the folder apache, than go to
the folder conf than go the file httpd.conf.
Step 2:- Just open the httpd.conf file with notepad and search
with the keyword Listen u will notice that there
is a wriiten a port no 80 in front of listen,
now just replace 80 to 81 or whatever u want to give the
port no.
Step 3:- Now open the browser and type:- localhost:81
OR
localhost:81/phpmyadmin