HI!!!!!!!!!!!!!!!!!!!!!

Ads

 
 

Share on Google+Share on Google+

anjuvijayan
HI!!!!!!!!!!!!!!!!!!!!!
3 Answer(s)      6 years and 4 months ago
Posted in : JDBC
import java.awt.*; 
import java.sql.*;
import javax.swing.*;
import java.awt.event.*;

public class NewJFrame extends javax.swing.JFrame {
    JTextField text1,text2,text3,text4,text5,text6,text7,text8,text10;
    JLabel label1,label2,label3,label4,label5,label6,label7,label8,label9,label10,label;
    JPasswordField text,text9;
    JLabel lab1;
    JPanel panel,panel1;
    JButton b1,b2,b3,b4;
    JTabbedPane tp; 
     void createSAccount(){
        JTabbedPane tp=new JTabbedPane(); 
        panel=new JPanel(new GridLayout(10,2));
        panel1=new JPanel(new GridLayout(3,2));
        label1=new JLabel("Name");
        text1=new JTextField(10); 
        label=new JLabel("Password");
        text=new JPasswordField(10);
        label2=new JLabel("Year of study");
        text2=new JTextField(10);
        label3=new JLabel("Faculty");
        text3=new JTextField(10);
        label4=new JLabel("Course"); 
        text4=new JTextField(10);
        label5=new JLabel("University");
        text5=new JTextField(10);
        label6=new JLabel("Phone No");
        text6=new JTextField(10);
        label7=new JLabel("Email Id");
        text7=new JTextField(10);
        label8=new JLabel("Address");
        text8=new JTextField(10);
        label9=new JLabel("Enter Password"); 
        text9=new JPasswordField(10);
        label10=new JLabel("Deposit");
        text10=new JTextField(10); 
        b1=new JButton("Add");
        b2=new JButton("Reset");
        b3=new JButton("Savings"); 
        b4=new JButton("Withdraw"); 
        panel.add(label1);
        panel.add(text1);
        panel.add(label);
        panel.add(text);
        panel.add(label2); 
        panel.add(text2);
        panel.add(label3);
        panel.add(text3);
        panel.add(label4);
        panel.add(text4);
        panel.add(label5); 
        panel.add(text5);
        panel.add(label6);
        panel.add(text6);
        panel.add(label7);
        panel.add(text7); 
        panel.add(label8);
        panel.add(text8);
        panel.add(b1); 
        panel.add(b2);
        panel1.add(label9); 
        panel1.add(text9);
        panel1.add(label10); 
        panel1.add(text10);
        panel1.add(b3);
        panel1.add(b4);
        b1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae){
                String t1=text1.getText();
                String t=text.getText();
                String t2=text2.getText(); 
                String t3=text3.getText();
                String t4=text4.getText();
                String t5=text5.getText();
                String t6=text6.getText();
                String t7=text7.getText(); 
                String t8=text8.getText();

try{ Class.forName("com.mysql.jdbc.Driver");
Connection con =DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","admin");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("Select balance from bank where branch='kannur'");
Statement st=con.createStatement();
int i=st.executeUpdate("insert into bankdata(name,pass,year,faculty,course,university,phoneNo,email,address) values('"+t1+"','"+t+"',"+t2+",'"+t3+"','"+t4+"','"+t5+"',"+t6+",'"+t7+"','"+t8+"')");
JOptionPane.showMessageDialog(null,"Thanks for creating an account.");
}
catch(Exception e){}
} 
});
b2.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent ae){
        text1.setText("");
        text.setText("");
        text2.setText("");
        text3.setText(""); 
        text4.setText(""); 
        text5.setText("");
        text6.setText(""); 
        text7.setText("");
        text8.setText("");
        } 
        });
b3.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent ae){
        String t9=text9.getText();
        String t10=text10.getText();
        int savings=Integer.parseInt(t10);
        int bal=0;
        try{
Class.forName("com.mysql.jdbc.Driver");
Connection con =DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","admin");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("Select balance from bankdata where pass='"+t9+"'");

if(rs.next()){
    bal=rs.getInt("balance");
    int ts=savings+bal; 
    stmt.executeUpdate("update bankdata set balance="+ts+" where pass='"+t9+"'"); 
    JOptionPane.showMessageDialog(null,"Your savings is: "+ts); 
    } 
    }

catch(Exception e){} 
}
});
b4.addActionListener(new ActionListener() { 
    public void actionPerformed(ActionEvent ae){
        String t9=text9.getText();
        int bal=0;
        JOptionPane pane = new JOptionPane("Do you want to withdraw");
        Object[] options = new String[] { "Yes", "No" }; 
        pane.setOptions(options); 
        JDialog dialog = pane.createDialog(null, "Dilaog");
        dialog.show(); 
        Object obj = pane.getValue(); 
        String st=obj.toString(); 
        if(st.equals("Yes")){
            String st1=JOptionPane.showInputDialog(null,"Enter amount to withdraw");
            int withdrawl=Integer.parseInt(st1);
            try{ Class.forName("com.mysql.jdbc.Driver");
            Connection con =DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","admin"); 
            Statement stmt=con.createStatement();
            ResultSet rs=stmt.executeQuery("Select balance from bankdata where pass='"+t9+"'");

if(rs.next()){
    bal=rs.getInt("balance");
    int leftSavings=bal-withdrawl; 
    Statement stat=con.createStatement();
    stat.executeUpdate("update bankdata set balance="+leftSavings+" where pass='"+t9+"'");
    JOptionPane.showMessageDialog(null," You have withdrawn "+withdrawl+" shillings and your balance is "+leftSavings);
    }
    } 
    catch(Exception e){}
    }
    else{ 
        System.exit(0);
        } 
        }
        }); 
        tp.addTab("Create Account",panel);
        tp.addTab("Deposit/Withdraw",panel1); 
        add(tp);
        setVisible(true); 
        pack();
        }
        public static void main(String[]args){
            NewJFrame f=new NewJFrame();
            f.createSAccount();
}
}

CAN ANYONE HELP ME TO DESIGN A FRAME FOR THIS PROGRAMME??
Ads
View Answers

January 21, 2011 at 2:59 PM


Hi Friend,

Try this:

import java.awt.*; 
import java.sql.*;
import javax.swing.*;
import java.awt.event.*;

public class NewJFrame extends javax.swing.JFrame {
    JTextField text1,text2,text3,text4,text5,text6,text7,text8,text10;
    JLabel label1,label2,label3,label4,label5,label6,label7,label8,label9,label10,label;
    JPasswordField text,text9;
    JLabel lab1;
    JPanel panel,panel1;
    JButton b1,b2,b3,b4;
    JTabbedPane tp; 
     void createSAccount(){
        JTabbedPane tp=new JTabbedPane(); 
        panel=new JPanel();
        panel1=new JPanel();
        label1=new JLabel("Name");
        text1=new JTextField(10); 
        label=new JLabel("Password");
        text=new JPasswordField(10);
        label2=new JLabel("Year of study");
        text2=new JTextField(10);
        label3=new JLabel("Faculty");
        text3=new JTextField(10);
        label4=new JLabel("Course"); 
        text4=new JTextField(10);
        label5=new JLabel("University");
        text5=new JTextField(10);
        label6=new JLabel("Phone No");
        text6=new JTextField(10);
        label7=new JLabel("Email Id");
        text7=new JTextField(10);
        label8=new JLabel("Address");
        text8=new JTextField(10);
        label9=new JLabel("Enter Password"); 
        text9=new JPasswordField(10);
        label10=new JLabel("Deposit");
        text10=new JTextField(10); 
        b1=new JButton("Add");
        b2=new JButton("Reset");
        b3=new JButton("Savings"); 
        b4=new JButton("Withdraw"); 
        panel.setLayout(null);
        panel1.setLayout(null);
        label1.setBounds(300,100,100,20);
        text1.setBounds(500,100,180,20);

        label.setBounds(300,140,100,20);
        text.setBounds(500,140,180,20);

        label2.setBounds(300,180,100,20);
        text2.setBounds(500,180,180,20);

        label3.setBounds(300,220,100,20);
        text3.setBounds(500,220,180,20);

        label4.setBounds(300,260,100,20);
        text4.setBounds(500,260,180,20);

        label5.setBounds(300,300,100,20);
        text5.setBounds(500,300,180,20);

        label6.setBounds(300,340,100,20);
        text6.setBounds(500,340,180,20);

        label7.setBounds(300,380,100,20);
        text7.setBounds(500,380,180,20);

        label8.setBounds(300,420,100,20);
        text8.setBounds(500,420,180,20);

        b1.setBounds(300,460,100,20);
        b2.setBounds(500,460,100,20);

        label9.setBounds(300,100,100,20);
        text9.setBounds(500,100,180,20);

        label10.setBounds(300,140,100,20);
        text10.setBounds(500,140,180,20);

        b3.setBounds(300,180,100,20);
        b4.setBounds(500,180,100,20);

        panel.add(label1);
        panel.add(text1);
        panel.add(label);
        panel.add(text);
        panel.add(label2); 
        panel.add(text2);
        panel.add(label3);
        panel.add(text3);
        panel.add(label4);
        panel.add(text4);
        panel.add(label5); 
        panel.add(text5);
        panel.add(label6);
        panel.add(text6);
        panel.add(label7);
        panel.add(text7); 
        panel.add(label8);
        panel.add(text8);
        panel.add(b1); 
        panel.add(b2);
        panel1.add(label9); 
        panel1.add(text9);
        panel1.add(label10); 
        panel1.add(text10);
        panel1.add(b3);
        panel1.add(b4);


January 21, 2011 at 3:02 PM


continue..

b1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae){
                String t1=text1.getText();
                String t=text.getText();
                String t2=text2.getText(); 
                String t3=text3.getText();
                String t4=text4.getText();
                String t5=text5.getText();
                String t6=text6.getText();
                String t7=text7.getText(); 
                String t8=text8.getText();

try{ Class.forName("com.mysql.jdbc.Driver");
Connection con =DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","admin");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("Select balance from bank where branch='kannur'");
Statement st=con.createStatement();
int i=st.executeUpdate("insert into bankdata(name,pass,year,faculty,course,university,phoneNo,email,address) values('"+t1+"','"+t+"',"+t2+",'"+t3+"','"+t4+"','"+t5+"',"+t6+",'"+t7+"','"+t8+"')");
JOptionPane.showMessageDialog(null,"Thanks for creating an account.");
}
catch(Exception e){}
} 
});
b2.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent ae){
        text1.setText("");
        text.setText("");
        text2.setText("");
        text3.setText(""); 
        text4.setText(""); 
        text5.setText("");
        text6.setText(""); 
        text7.setText("");
        text8.setText("");
        } 
        });
b3.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent ae){
        String t9=text9.getText();
        String t10=text10.getText();
        int savings=Integer.parseInt(t10);
        int bal=0;
        try{
Class.forName("com.mysql.jdbc.Driver");
Connection con =DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","admin");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("Select balance from bankdata where pass='"+t9+"'");

if(rs.next()){
    bal=rs.getInt("balance");
    int ts=savings+bal; 
    stmt.executeUpdate("update bankdata set balance="+ts+" where pass='"+t9+"'"); 
    JOptionPane.showMessageDialog(null,"Your savings is: "+ts); 
    } 
    }

catch(Exception e){} 
}
});


January 21, 2011 at 3:03 PM


continue..

b4.addActionListener(new ActionListener() { 
    public void actionPerformed(ActionEvent ae){
        String t9=text9.getText();
        int bal=0;
        JOptionPane pane = new JOptionPane("Do you want to withdraw");
        Object[] options = new String[] { "Yes", "No" }; 
        pane.setOptions(options); 
        JDialog dialog = pane.createDialog(null, "Dilaog");
        dialog.show(); 
        Object obj = pane.getValue(); 
        String st=obj.toString(); 
        if(st.equals("Yes")){
            String st1=JOptionPane.showInputDialog(null,"Enter amount to withdraw");
            int withdrawl=Integer.parseInt(st1);
            try{ Class.forName("com.mysql.jdbc.Driver");
            Connection con =DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","admin"); 
            Statement stmt=con.createStatement();
            ResultSet rs=stmt.executeQuery("Select balance from bankdata where pass='"+t9+"'");

if(rs.next()){
    bal=rs.getInt("balance");
    int leftSavings=bal-withdrawl; 
    Statement stat=con.createStatement();
    stat.executeUpdate("update bankdata set balance="+leftSavings+" where pass='"+t9+"'");
    JOptionPane.showMessageDialog(null," You have withdrawn "+withdrawl+" shillings and your balance is "+leftSavings);
    }
    } 
    catch(Exception e){}
    }
    else{ 
        System.exit(0);
        } 
        }
        }); 
        tp.addTab("Create Account",panel);
        tp.addTab("Deposit/Withdraw",panel1); 
        add(tp);
        setVisible(true); 
        setSize(1024,768);
        }
        public static void main(String[]args){
            NewJFrame f=new NewJFrame();
            f.createSAccount();
}
}

Thanks


Ads









Related Tutorials/Questions & Answers:
Tutorials   
Java Spring Hibernate Struts Training java.lang.classnotfoundexception com.mysql.jdbc.driver how to retrieve text and images from mysql database and show on html page using jsp servlet How to install Neo4j on Ubuntu 15.10? please help me in these prog MYSQL - mysql copy table to another table example by creating new table solution for mapping hibernate and pojos from net beans through database Connect GWT application with Oracle inventory System of Medical Store inventory System of Medical Store inventory System of Medical Store inventory System of Medical Store This code have created jTable that connected with a database.every cell of last column have a button.But this button doesn't work properly.Where is the error java program Java Database Program jdbc Database connection class in a live project ..?? What is JDBC architecture? Unable to Create DSN for excel to ms access importing data and edit that data Database Scrolling Buttons how to use foreign key in java How to delete content of a log file from linux terminal? JSP-Oracle connectivity Student Management System Java code for Saving Marathi (Indian local language ) in Mysql and retrieving the same crud operations with foreign key constraint. I really need help with this assignment question Please help me out Please Backup Failed Mysqldump Got Errno 28 On Write Upgrade MySQL 5.1 to 5.5 in cpanel mysqldump all databases com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'jpa.sequence' doesn't exist persistence xml class element persistence.xml for MySQL MySQL JDBC Driver pom dependency code Blob column jdk6 and oracle 8i connexion oracle 8i et jdk6 java [ cannot retrive date from sql ] why?? Order Entry System How to threow timeout exception when DB is not responding How to threow timeout exception when DB is not responding This is the employee form to add data to mysql database but I got error of NullPointerException, Is this write code please give me feedback as soon as possible make a method which takes user name & pwd as parameter & validate them against the database. If the corresponding user exist return true otherwise false. prabhakar validating credentials and displaying error message in login .jsp if not valid JDBC jdbc jdbc code register servlet vibhu

Ads

 
Advertisement null

Ads