Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


anjuvijayan
hi.......
2 Answer(s)      3 years and 10 months ago
Posted in : Java Beginners


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

public class NewJFrame extends javax.swing.JFrame {
JTextField1 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;
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();

 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        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+"'");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("Select balance from bankdata where pass='"+t9+"'");

if(rs.next()){
bal=rs.getInt("balance");
int ts=savings+bal;
Statement st1=con.createStatement();
st1.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){

}

}

can anyone tell wts wrong with this code??

Advertisement
View Answers

January 20, 2011 at 3:02 PM


Hi,

Check it:

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){}
} 
});


January 20, 2011 at 3:02 PM


continue..

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();
}
}

Thanks



Related Tutorials/Questions & Answers:
Hi,
Hi,  Hi,what is the purpose of hash table
Hi..
Hi..   what are the keywords available in simple HelloWorld program
Advertisements
Hi..
Hi..  what are access specifier available in java
Hi,
Hi,   labels = new Hashtable<Integer,JLabel>
HI.
HI.  hi,plz send me the code for me using search button bind the data from data base in dropdownlist
Hi..
Hi..  null is a keyword.True/False?   hi friend, In Java true, false and null are not a Java keyword they are literals in Java. For reading in detail go through the following link The null keyword
hi....
hi....  plzz sent me d code for counting vowels in a string... gui programme
Hi
Hi  Hi How to implement I18N concept in struts 1.3? Please reply to me
Hi
Hi  Hi this is really good example to beginners who is learning struts2.0 thanks
hi,
hi,  print("code sample");how to display all elements in 2d array usin any one loop
Hi
Hi   how to read collection obj from jsp to servlet and from jsp - jsp?   Hi Friend, Please visit the following link: http://www.roseindia.net/jsp/servlet-jsp-data-list.shtml Thanks
hi....
hi....  a programme which displays a combobox which contains num from 1 to 10 and calculates the factorial of dt num which user clicks
Hi
Hi  I want import txt fayl java.please say me...   Hi, Please clarify your problem! Thanks
hi
hi   I have connected mysql with jsp in linux and i have used JDBC connectivity but when i run the program, its not working the program is displaying
hi
hi   'print("code sample");`class example(){ public.static.void.main(); system.out.println("this is first pro");}   class example{ public static void main(String[]args){ System.out.println("this is first pro
Hi..
Hi..  diff between syntax and signature?   signature is a particular identity of a method in terms of its argument order ,type and their number e.g. void A(arguments) then here the order ,type and number of arguments
Hi
Hi  Hi All, I am new to roseindia. I want to learn struts. I do not know anything in struts. What exactly is struts and where do we use it. Please help me. Thanks in advance. Regards, Deepak
hi!
hi!  how can i write aprogram in java by using scanner when asking user to enter element user will be free to enter any type that he/she wants to to enter, like(int,double,float,String,....) thanx for answering....   Hi
Hi..
Hi..  what are the steps mandatory to develop a simple java program?   To develop a Java program following steps must be followed by a Java developer : First of all the JDK (Java Development Kit) must be available
hi
hi   on clicking on button on 1st jsp page i want to display following options like friends,family,doctor etc.on next jsp page and also i want link to those options through which i can save the data from 1st jsp in different
hi
hi   on clicking on button on 1st jsp page i want to display following options like friends,family,doctor etc.on next jsp page and also i want link to those options through which i can save the data from 1st jsp in different
hi
online multiple choice examination  hi i am developing online multiple choice examination for that i want to store questions,four options,correct answer in a xml file using jsp or java?can any one help me?   Please
hi
hi  what is the code for printing stars as follows * * * * * * * * * *print("code sample");   Hi Friend, Try... num=4; int p = num; int q = 0; for (int i = 0; i <= num; i++) { for (int j
hi
hi  int A[]=new int{2,5,4,1,3}; what is the error in declaration of this   Hi Friend, This is the wrong way of declaring an array. Array is always declared in the following ways: 1)int arr[]=new int[5]; 2)int arr
Hi
Hi   I need some help I've got my java code and am having difficulty to spot what errors there are is someone able to help import java.util.Scanner; public class Post { public static void main(String[] args) { Scanner sc
hi.......
hi.......  i've a project on railway reservation... i need to connect netbeans and mysql with the help of jdbc driver... then i need to design... for such a programme... plz help me...   Hi Friend, Try this: import java.awt.
hi!
hi!  public NewJFrame() { initComponents(); try { Class.forName("java.sql.Driver"); con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","admin"); } catch(Exception e
Hi
Hi   I have got this code but am not totally understanding what the errors. Could someone Please help. Thanks in advance! import java.util.Random; import java.util.Scanner; private static int nextInt() { public class
hi
storing data in xml file using jsp  hi i am storing data in xml file using jsp.in this when i enter data into xml file i am getting xml declaration for each specified data?can any one help me to prevent this?   <
hi
hi   i want to develop a online bit by bit examination process as part of my project in this i am stuck at how to store multiple choice questions options and correct option for the question.this is the first project i am doing
hi..
hi..  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@ page contentType="text/html;charset=windows-1252"%> <html> <head> <meta http-equiv
 

 

 

DMCA.com