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

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

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??
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









Related Tutorials/Questions & Answers:

Ads