Wednesday, 2 January 2013

Java Swing :- Window Application ( View Phase 2 JForm Window )

import java.sql.*;
/**
 *
 * @author Amol
 */
public class FormWindow extends javax.swing.JFrame {

    /** Creates new form FormWindow */
    public FormWindow() {
        initComponents();
    }

    private void calButtonActionPerformed(java.awt.event.ActionEvent evt) {                                         
        int totalMarks = Integer.parseInt(totalText.getText());
        double marksObtain = Double.parseDouble(markObtainText.getText());
        double percent=(marksObtain*100)/totalMarks;
        percentText.setText(""+percent);
    }                                        

    private void submitButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            
try{
    Class.forName("com.mysql.jdbc.Driver");
    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/sampledb1","root","root");
    String rollNo= rollText.getText();
    String totalMarks=totalText.getText();
    String obtainMarks=markObtainText.getText();
    PreparedStatement ps = con.prepareStatement("insert into student_marks values(?,?,?)");
    ps.setString(1, rollNo);
    ps.setString(2, totalMarks);
    ps.setString(3, obtainMarks);
    ps.execute();
    ps.close();
    con.close();

}
catch(Exception e){
    System.out.println("e = " + e);
}


       

    }                                           
 public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FormWindow().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                    
    private javax.swing.JButton calButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel markObtainLabel;
    private javax.swing.JTextField markObtainText;
    private javax.swing.JTextField percentText;
    private javax.swing.JLabel rollLabel;
    private javax.swing.JTextField rollText;
    private javax.swing.JButton submitButton;
    private javax.swing.JLabel totalMarksLabel;
    private javax.swing.JTextField totalText;
    // End of variables declaration                  

}

No comments:

Post a Comment