Posts

Run jar thriugh bat file

@echo on; start; set classpath="C:\Program Files\Java\jre7"; java -jar abc.jar pause;

Change Look and Feel Metals of JFrame in Netbeans

 try {             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {                 if ("Metals".equals(info.getName())) {                     javax.swing.UIManager.setLookAndFeel(info.getClassName());                     break;                 }             }         } catch (ClassNotFoundException ex) {             java.util.logging.Logger.getLogger(Rms.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);         } catch (InstantiationException ex) {             java.util.logging.Logger.getLogger(Rms.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);         } catch (IllegalAccessException ex) {             java.util.logging.Logger.getLogger(Rms.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);         } catch (javax.swing.UnsupportedLookAndFeelException ex) {             java.util.logging.Logger.getLogger(Rms.class.getName()).log(java.util.logging.Level.SEVERE, null,

Change Look and Feel Windows of JFrame in Netbeans

try {             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {                 if ("Windows Classic".equals(info.getName())) {                     javax.swing.UIManager.setLookAndFeel(info.getClassName());                     break;                 }             }         } catch (ClassNotFoundException ex) {             java.util.logging.Logger.getLogger(Rms.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);         } catch (InstantiationException ex) {             java.util.logging.Logger.getLogger(Rms.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);         } catch (IllegalAccessException ex) {             java.util.logging.Logger.getLogger(Rms.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);         } catch (javax.swing.UnsupportedLookAndFeelException ex) {             java.util.logging.Logger.getLogger(Rms.class.getName()).log(java.util.loggi

Change Look and Feel Windows Classic of JFrame in Netbeans

try {             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {                 if ("Windows Classic".equals(info.getName())) {                     javax.swing.UIManager.setLookAndFeel(info.getClassName());                     break;                 }             }         } catch (ClassNotFoundException ex) {             java.util.logging.Logger.getLogger(Rms.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);         } catch (InstantiationException ex) {             java.util.logging.Logger.getLogger(Rms.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);         } catch (IllegalAccessException ex) {             java.util.logging.Logger.getLogger(Rms.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);         } catch (javax.swing.UnsupportedLookAndFeelException ex) {             java.util.logging.Logger.getLogger(Rms.class.getName()).log(java.util.logging.Level.SEVERE

Change Look and Feel Nimbus of JFrame in Netbeans

try {             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {                 if ("Nimbus".equals(info.getName())) {                     javax.swing.UIManager.setLookAndFeel(info.getClassName());                     break;                 }             }         } catch (ClassNotFoundException ex) {             java.util.logging.Logger.getLogger(MAIN.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);         } catch (InstantiationException ex) {             java.util.logging.Logger.getLogger(MAIN.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);         } catch (IllegalAccessException ex) {             java.util.logging.Logger.getLogger(MAIN.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);         } catch (javax.swing.UnsupportedLookAndFeelException ex) {             java.util.logging.Logger.getLogger(MAIN.class.getName()).log(java.util.logging.Level.SEVERE, nul

Random Number

import java.util.*; public class question {   public static void main(String[] args) {     System.out.println((char)('A' + Math.random() * 27)); Random rn        = new Random(); //int    range     = 9999999 - 1000000 + 1; int    randomNum =  rn.nextInt(1) + 100;  // For 7 digit number System.out.println(randomNum); Random rc = new Random(); char   c  = (char)(rc.nextInt(26) + 'A'); System.out.println(c); String str = c+""+randomNum;       System.out.println(str);   } }

Disable jbutton

JButton jb=new JButton(); jb.setEnabled(false);

Set image on Jlabel

         JFileChooser chooser = new JFileChooser();         chooser.addChoosableFileFilter(new ImageFileFilter()); int returnVal = chooser.showOpenDialog(null); if(returnVal == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile();  path=file.getPath(); ImageIcon icon=new ImageIcon(path); Jlabel jLabel1=new JLabel(); jLabel1.setIcon(icon);

Add Items in JComboBox in java swing

 try         {                                  Class.forName("com.mysql.jdbc.Driver");             java.sql.Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3305/rms","root","root");     String sql="select name from categories";     java.sql.PreparedStatement pst=con.prepareStatement(sql);       ResultSet rs = pst.executeQuery(sql);   while(rs.next())   {    String name=rs.getString(1);    jComboBox1.addItem(name);   } con.close(); pst.close();         }         catch(Exception e)         {             JOptionPane.showMessageDialog(null, e);         }

Tabbed Pane in java swing through 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 rms; import com.mysql.jdbc.Connection; import com.mysql.jdbc.PreparedStatement; import java.sql.DriverManager; import java.sql.ResultSet; import javax.swing.JOptionPane; import net.proteanit.sql.DbUtils; /**  *  * @author NAVJYOTI  */ public class Rms extends javax.swing.JFrame {     /**      * Creates new form Rms      */     public Rms() {         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">                          

Save Image in Database.

//import com.oreilly.servlet.MultipartRequest; import java.io.*; import java.sql.*; import javax.servlet.http.*; import javax.servlet.*; //import org.apache.commons.fileupload.disk.DiskFileItemFactory; //import org.apache.commons.fileupload.servlet.ServletFileUpload;   public class UploadServlet extends HttpServlet { public void doPost(HttpServletRequest request, HttpServletResponse response)     throws ServletException, IOException {   response.setContentType("text/html"); PrintWriter out = response.getWriter(); //MultipartRequest m=new MultipartRequest(request,"c:/test"); //String image=request.getParameter("image"); //out.println(image); try {     //DiskFileItemFactory factory = new DiskFileItemFactory();      //       ServletFileUpload sfu  = new ServletFileUpload(factory);   Class.forName("com.mysql.jdbc.Driver");     Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3305/file","root&

Round off in java

Example-12.51->13 System.out.println(Math.round(12.51));

Add Check Box in Jtable in netbeans

Check Username Exists or not in jsp.through jquery.

put the textfield id="docid" $(document).ready(function(e) {    $("#docid").keyup(function (e) { //removes spaces from username $(this).val($(this).val().replace(/\s/g, '')); var username = $(this).val(); //if(username.length < 4){$("#user-result").html('');return;} //if(username.length >= 4){ $("#user-result").html('<img src="ajax-loader.gif" />'); $.post('check_username.php', {'username':username}, function(data) {  $("#user-result").html(data); }); //} }); }); check_username.jsp <% Class.forName("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3305","root","root"); PreparedStatement pst=con.PreparedStatement("select * from demo where id='"+Integer.parseInt(request.getParameter("username"))+"'&q

calculating sum of rows and set to JLabel.

try         {          Connection con=new Connection();             java.sql.Connection co=con.connectit();             PreparedStatement pst=co.prepareStatement("select SUM(AmountRecieved),SUM(Total),SUM(Total)-SUM(AmountRecieved) as DueBalance from strech");             ResultSet rs=pst.executeQuery();             while(rs.next())             {                 jLabel40.setText(""+rs.getDouble(2));                 jLabel42.setText(""+rs.getDouble(1));                 jLabel44.setText(""+rs.getDouble(3));             }             co.close();             pst.close();         }             catch(Exception e)                     {                     System.out.println(e);                     }