Posts

Showing posts from July, 2014

Example.

public class c {     public static void main(String args[])     {     System.out.println("\u0905\u0905\u0940\u0924\u093E\u092A"); } }

Find Product and its Sub_product list through JComboBox Item State change.

 private void jComboBox2ItemStateChanged(java.awt.event.ItemEvent evt) {                                                     String name1=jComboBox2.getSelectedItem().toString();         String id=null;         try         {     Class.forName("com.mysql.jdbc.Driver");     java.sql.Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3305/inventory","root","root");     String sql="select BRANDID from brand where BRANDNAME='"+name1+"'";     java.sql.PreparedStatement pst=con.prepareStatement(sql);     ResultSet rs=pst.executeQuery();     while(rs.next())     {         id=rs.getString(1);     }     get(id);         }         catch(Exception e)         {             System.out.println(e);         }     }           public void get(String id) {         DefaultComboBoxModel model = new DefaultComboBoxModel();        try         {     Class.forName("co

Retrieve CSV file through java.

try         {            Class.forName("com.mysql.jdbc.Driver");            java.sql.Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3305/supplimentry","root","root");            String sql="LOAD DATA LOCAL INFILE 'h://inventory.csv'\n" +             "INTO TABLE inventory\n" +             "FIELDS TERMINATED BY ','\n" +             "OPTIONALLY ENCLOSED BY '\"'\n" +             "LINES TERMINATED BY '\n'";            java.sql.PreparedStatement pst1=con.prepareStatement(sql);            pst1.executeUpdate();            con.close();            pst1.close();            JOptionPane.showMessageDialog(null,"Restore Successfully!!!!");         }         catch(Exception e)         {             System.out.println(e);         }

create csv file through java.

    String sql2="SELECT * FROM inventory into outfile 'h:/inventory.csv' FIELDS TERMINATED BY ','\n" + "ENCLOSED BY '\"'\n" + "LINES TERMINATED BY '\\n';";         com.mysql.jdbc.PreparedStatement pst1=(com.mysql.jdbc.PreparedStatement) con.prepareStatement(sql2);         pst1.executeQuery();         pst1.close();         JOptionPane.showMessageDialog(null,"Go To H-Drive For CSV File");         Desktop.getDesktop().open(new File("h://inventory.csv"));    

Ceate CSV File through java.

   String sql2="SELECT * FROM inventory into outfile 'h:/inventory.csv' FIELDS TERMINATED BY ','\n" + "ENCLOSED BY '\"'\n" + "LINES TERMINATED BY '\\n';";         com.mysql.jdbc.PreparedStatement pst1=(com.mysql.jdbc.PreparedStatement) con.prepareStatement(sql2);         pst1.executeQuery();         pst1.close();         JOptionPane.showMessageDialog(null,"Go To H-Drive For CSV File");         Desktop.getDesktop().open(new File("h://inventory.csv"));    

Login Through Enter Button in java swing.

  if(evt.getKeyCode()==KeyEvent.VK_ENTER)       {             type=jComboBox1.getSelectedItem().toString(); if(type=="ADMIN") {         try        {            String cn=jTextField1.getText();            String pass=jPasswordField1.getText();            String type1=jComboBox1.getSelectedItem().toString();            if(cn.equals(""))            {                JOptionPane.showMessageDialog(null,"Pls Enter ur Name and Password");            }            else if(pass.equals(""))            {                JOptionPane.showMessageDialog(null,"Pls Enter ur Name and Password");            }                     else            {            Class.forName("com.mysql.jdbc.Driver");            java.sql.Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3305/supplimentry","root","root");            java.sql.PreparedStatement pst=con.prepareStatement("select nam

Pie Chart.

    public double gt()     {         double exp=0;         try         {           Class.forName("com.mysql.jdbc.Driver");            java.sql.Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3305/supplimentry","root","root");            String sql1="SELECT sum(Amount) as Amount from expenses";            java.sql.PreparedStatement pst1=con.prepareStatement(sql1);             ResultSet rs=pst1.executeQuery();            while(rs.next())             {             exp=rs.getDouble(1);             }         }         catch(Exception e)         {                    }         return exp;     }     public double it()     {         double exp=0;         try         {           Class.forName("com.mysql.jdbc.Driver");            java.sql.Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3305/supplimentry","root","root");            String sq

On Jtable Update.

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                               System.out.println("NAVEEN");         int row=jTable2.getSelectedRow();         System.out.println(""+row);         String t1=(jTable2.getModel().getValueAt(row, 0).toString());          System.out.println(""+t1); String name = (jTable2.getModel().getValueAt(row, 1).toString());  System.out.println(name); String mail = (jTable2.getModel().getValueAt(row, 2).toString()); String add = (jTable2.getModel().getValueAt(row, 3).toString());  System.out.println(add);      String pass = (jTable2.getModel().getValueAt(row, 4).toString());    System.out.println(pass);  try{   Class.forName("com.mysql.jdbc.Driver");     java.sql.Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3305/naveen","root","root");   String query = "update jtable set name=?,mail=?,address=?,passw

BarCode with Random Number.

import java.io.FileNotFoundException; import java.io.FileOutputStream; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.PageSize; import com.itextpdf.text.Paragraph; import com.itextpdf.text.Rectangle; import com.itextpdf.text.pdf.Barcode128; import com.itextpdf.text.pdf.PdfWriter; import java.awt.Desktop; import java.io.File; import java.util.Random; //import com.lowagie.text.Document; //import com.lowagie.text.DocumentException; //import com.lowagie.text.PageSize; //import com.lowagie.text.Paragraph; //import com.lowagie.text.Rectangle; //import com.lowagie.text.pdf.Barcode128; //import com.lowagie.text.pdf.PdfWriter; public class BarCode128 {  public static void main(String[] args) throws FileNotFoundException, DocumentException {     Document document = new Document(new Rectangle(PageSize.A4));       PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("h:/Naveen3.pdf"));

itextpdf.jar

package barcode; /**  *  * @author NAVJYOTI  */ import java.io.FileNotFoundException; import java.io.FileOutputStream; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.PageSize; import com.itextpdf.text.Paragraph; import com.itextpdf.text.Rectangle; import com.itextpdf.text.pdf.Barcode128; import com.itextpdf.text.pdf.PdfWriter; import java.awt.Desktop; import java.io.File; //import com.lowagie.text.Document; //import com.lowagie.text.DocumentException; //import com.lowagie.text.PageSize; //import com.lowagie.text.Paragraph; //import com.lowagie.text.Rectangle; //import com.lowagie.text.pdf.Barcode128; //import com.lowagie.text.pdf.PdfWriter; public class BarCode128 {  public static void main(String[] args) throws FileNotFoundException, DocumentException {     Document document = new Document(new Rectangle(PageSize.A4));       PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(&

Insert Data in Database with Batch with help of JTable.

/*  * To change this license header, choose License Headers in Project Properties.  * To change this template file, choose Tools | Templates  * and open the template in the editor.  */ package commity; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JOptionPane; import net.proteanit.sql.DbUtils; /**  *  * @author NAVJYOTI  */ public class JTableinsertintodatabase extends javax.swing.JFrame {     /**      * Creates new form JTableinsertintodatabase      */     public JTableinsertintodatabase() {         initComponents();         set();     }     /**      * 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.      */     @SuppressWarnings("unchecked"

Insert data in database through JTable.

package commity; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JOptionPane; import net.proteanit.sql.DbUtils; /**  *  * @author NAVJYOTI  */ public class JTableinsertintodatabase extends javax.swing.JFrame {     /**      * Creates new form JTableinsertintodatabase      */     public JTableinsertintodatabase() {         initComponents();         set();     }     /**      * 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.      */     @SuppressWarnings("unchecked")     // <editor-fold defaultstate="collapsed" desc="Generated Code">                             private void initComponents() {         jScrollPane1 = new jav

Item State change of JComboBox and Get values from database and show Data on JTable.

 try     {     Class.forName("com.mysql.jdbc.Driver");     java.sql.Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3305/supplimentry","root","root");     String sql="select * from inventory where Brand_Name='"+jComboBox3.getSelectedItem().toString()+"'";     java.sql.PreparedStatement pst=con.prepareStatement(sql);     DefaultTableModel tm33 = (DefaultTableModel)list1.getModel();     tm33.setRowCount(0);  TableColumn col = new TableColumn(tm33.getColumnCount());  JTableHeader header = list1.getTableHeader();   header.setBackground(Color.yellow);        ResultSet rs = pst.executeQuery(sql);     int i=0;     while(rs.next())     {     Vector v2 = new Vector();     v2.addElement(rs.getString(1));     v2.addElement(rs.getString(2));     v2.addElement(rs.getInt(3));     v2.addElement(rs.getDouble(4));     v2.addElement(rs.getDouble(5));     v2.addElement(rs.getDouble(6));     v2.

jComboBox2 ItemStateChanged.

  private void jComboBox2ItemStateChanged(java.awt.event.ItemEvent evt) {                                           String name=jComboBox2.getSelectedItem().toString(); if(name.equals("Bristish Nutrition")) {     jTextField1.setText("BN"); } else if(name.equals("Muscle Blaze")) {     jTextField1.setText("MB"); }     }  

Add Product Through yes no option

int p=JOptionPane.showConfirmDialog(null,"Do U Want to Add","Add Product",JOptionPane.YES_NO_OPTION);       if(p==0)       {         try        {            Class.forName("com.mysql.jdbc.Driver");            java.sql.Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3305/supplimentry","root","root");            java.sql.PreparedStatement pst1=con.prepareStatement("select * from inventory where Product_Code='"+jTextField2.getText()+"'");            ResultSet rs=pst1.executeQuery();            if(rs.next())            {               JOptionPane.showMessageDialog(null,"Already Exists!!");               con.close();               pst1.close();               rs.close();            }            else            {                java.sql.Date sqldate = new java.sql.Date(jd1.getDate().getTime());                String sql="insert into inventory(Product_Co

Reset JTable.

DefaultTableModel dm=(DefaultTableModel)list1.getModel();      dm.setRowCount(0);

set blank on jtable.

        for (int i = 0; i < addtocart.getRowCount(); i++)         {         for(int j = 0; j < addtocart.getColumnCount(); j++)          {           addtocart.setValueAt("", i, j);          }          }       for (int i = 0; i < addtocart1.getRowCount(); i++)         {         for(int j = 0; j < addtocart1.getColumnCount(); j++)          {           addtocart1.setValueAt("", i, j);          }

get value from textfield and set on selected jtable row.

  DefaultTableModel tm=(DefaultTableModel)addtocart.getModel();        tm.setValueAt(jTextField25.getText(),addtocart.getSelectedRow(),1);        tm.setValueAt(jTextField17.getText(),addtocart.getSelectedRow(),2);        tm.setValueAt(jTextField16.getText(),addtocart.getSelectedRow(),3);

Item State change on JComboBox and enable and disable JTextField.

  private void jComboBox1ItemStateChanged(java.awt.event.ItemEvent evt) {                                           String name=jComboBox1.getSelectedItem().toString(); if(name.equals("Tax Invoice")) {     jTextField12.setEnabled(true); } else if(name.equals("Sale Invoice")) {     jTextField12.setEnabled(false); }     }    

SplitPane Example

/*  * To change this license header, choose License Headers in Project Properties.  * To change this template file, choose Tools | Templates  * and open the template in the editor.  */ package Demo; /**  *  * @author NAVJYOTI  */ public class split extends javax.swing.JFrame {     /**      * Creates new form split      */     public split() {         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.      */     @SuppressWarnings("unchecked")     // <editor-fold defaultstate="collapsed" desc="Generated Code">                             private void initComponents() {         jSplitPane1 = new javax.swing.JSplitPane();         jPanel1 = new javax.swing.JPanel();         jButton1 = new javax.swing.JButton();         jButton2 = new javax.swin

Change JTabbedPane tab. through JButton.

 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                             jTabbedPane1.setSelectedIndex(1);     }                                      

RESET JTABLE BLANK.

  DefaultTableModel tm33 = (DefaultTableModel)list1.getModel();         tm33.setRowCount(0);

Reset Jtable

public void clear()    {         for (int i = 0; i < addtocart.getRowCount(); i++)         {         for(int j = 0; j < addtocart.getColumnCount(); j++)          {           addtocart.setValueAt("", i, j);          }          }       for (int i = 0; i < addtocart1.getRowCount(); i++)         {         for(int j = 0; j < addtocart1.getColumnCount(); j++)          {           addtocart1.setValueAt("", i, j);          }          }              jLabel23.setText("N/L");    }

Jasper Report with Java Swing in netbeans.

/*  * To change this license header, choose License Headers in Project Properties.  * To change this template file, choose Tools | Templates  * and open the template in the editor.  */ package Demo; import java.sql.DriverManager; import net.sf.jasperreports.engine.JasperCompileManager; import net.sf.jasperreports.engine.JasperFillManager; import net.sf.jasperreports.engine.JasperPrint; import net.sf.jasperreports.engine.JasperReport; import net.sf.jasperreports.view.JasperViewer; /**  *  * @author NAVJYOTI  */ public class report extends javax.swing.JFrame {     /**      * Creates new form report      */     public report() {         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.      */     @SuppressWarnings("unchecked")     // <editor-fold defaultstate=&qu

Query for Retrieve record through month.

SELECT * FROM insatllment WHERE MONTH(Date) = 01 Month(Column_Name) 1-Column_Name is column name of Table.

Retrieve Data on Month in MySql

 d5  = ((JTextField)jDateChooser1.getDateEditor().getUiComponent()).getText(); Calendar c = Calendar.getInstance();         try {             c.setTime(sdf.parse(d5));             month1 = c.get(Calendar.MONTH)+1;             System.out.println(month1);         } catch (ParseException ex) {             Logger.getLogger(Commity.class.getName()).log(Level.SEVERE, null, ex);         }   try         {     Class.forName("com.mysql.jdbc.Driver");     java.sql.Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3305/commity","root","root");     String sql="select MemberName,Group_Number,Payment from insatllment where MONTH(Date)='"+month1+"' and Group_Number='"+jTextField13.getText()+"'";     java.sql.PreparedStatement pst=con.prepareStatement(sql);     ResultSet rs = pst.executeQuery(sql);   countdate.setModel(DbUtils.resultSetToTableModel(rs)); con.close(); pst.close(

Choose File Through JFileChooser.

 JFileChooser fc = new JFileChooser();                         String desc = "Excel ( *.xls)";                         String[] types = {".xls"};                         fc.addChoosableFileFilter(                             new FileNameExtensionFilter(desc, types));                         int returnval = fc.showOpenDialog(null);                         if (returnval == JFileChooser.APPROVE_OPTION) {                             File file = fc.getSelectedFile();                     jTextField1.setText(file.getPath());                                                    }

Java swing, close one window and open another when button is clicked

public void close() {     this.setVisible(false);     this.dispose(); //WindowEvent w=new WindowEvent(this,WindowEvent.WINDOW_CLOSING); //Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(w); }