please modify this so that it can work better

please modify this so that it can work better

View Answers

December 2, 2009 at 2:26 PM

Hi Friend,

Try the following code:

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

class openTest extends JFrame{
private JLabel name,gender,facultyName, courseName,year, university,telephone, phone,email, first;
private JPanel panel1,panel2,p1,p2;
private JLabel lab,lab1;
private JLabel l[]=new JLabel [4];
private GridLayout gridLayout1;
private JTextField name1, gender1,facultyName1,courseName1, year1, first1, university1, telephone1, email1, phone1;
private JTextField t[]=new JTextField [4];
private JTabbedPane pane;
private Font boldFont;
private Font boldItalicFont;
private JButton submit;
private JButton but,but1;
BankAccount b;
public openTest(){
super("Savings Account Application Form");
panel1=new JPanel(new GridLayout(11,2));
panel2=new JPanel();
p1=new JPanel(new GridLayout(5,2));
p2=new JPanel();

name =new JLabel("*" +"Surname");
name.setToolTipText("Please tell us surname");
panel1.add(name);
name1 =new JTextField(15);
name1.setFont(boldItalicFont);
name1.setText("");
panel1.add(name1);

first =new JLabel("First name");
first.setToolTipText("Please tell us your first name");
panel1.add(first);
first1 =new JTextField(15);
first1.setText("");
panel1.add(first1);

courseName =new JLabel("Course Name");
courseName.setToolTipText("Please tell us your name");
panel1.add(courseName);
courseName1 =new JTextField(15);
panel1.add(courseName1);

year =new JLabel("Year of study");
year.setToolTipText("Please tell us your year");
panel1.add(year);
year1 =new JTextField(15);
panel1.add(year1);

phone =new JLabel("Mobile Number");
phone.setToolTipText("Please tell us your mobile number");
panel1.add(phone);
phone1 =new JTextField(15);
panel1.add(phone1);

facultyName =new JLabel("Faculty Name");
facultyName.setToolTipText("Please tell us your faculty name");
panel1.add(facultyName);
facultyName1 =new JTextField(15);
panel1.add(facultyName1);

university =new JLabel("University");
university.setToolTipText("Please tell us your university name");
panel1.add(university);
university1=new JTextField(15);
panel1.add(university1);

telephone =new JLabel("Physical Address");
telephone.setToolTipText("Please tell us your telephone contact");
panel1.add(telephone);
telephone1=new JTextField(15);
panel1.add(telephone1);

email =new JLabel("E-mail Address");
email.setToolTipText("Please tell us your E-mail Address");
panel1.add(email);
email1=new JTextField(15);
panel1.add(email1);

gender =new JLabel();
gender.setText("Sex");
gender.setToolTipText("Please tell us your gender");
panel1.add(gender);
gender1 =new JTextField(15);
panel1.add(gender1);

submit =new JButton("Submit");
submit.setSize(10,20);
panel1.add(submit,BorderLayout.WEST);
pane=new JTabbedPane();
pane.addTab("Open Savings Account",panel1);
lab=new JLabel(" ");
lab1=new JLabel(" ");
but=new JButton("Create Account");
but1=new JButton("Test Account");
p2.add(lab1);
p2.add(lab);

December 2, 2009 at 2:30 PM

continue...

l[0]=new JLabel("Enter Your Account Number");
l[1]=new JLabel("Enter Your Initial Balance");
l[2]=new JLabel("Deposit Amount");
l[3]=new JLabel("Withdraw Amount");
for(int i=0;i<4;i++){
t[i]=new JTextField(10);
p1.add(l[i]);
p1.add(t[i]);
}
p1.add(but);
p1.add(but1);
but1.setVisible(false);
l[2].setVisible(false);
l[3].setVisible(false);
t[2].setVisible(false);
t[3].setVisible(false);
panel2.add(p1);
panel2.add(p2);
but.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
String des=JOptionPane.showInputDialog(null,"Deposit or Withdraw");
if(des.equals("Deposit")){
b=new BankAccount(Integer.parseInt(t[0].getText()),Integer.parseInt(t[1].getText()));
but1.setVisible(true);
l[2].setVisible(true);
l[3].setVisible(false);
t[2].setVisible(true);
t[3].setVisible(false);
but.setVisible(false);
l[0].setVisible(false);
l[1].setVisible(false);
t[0].setVisible(false);
t[1].setVisible(false);
lab1.setText("Account : "+b.accnum+", Current Balance : "+b.amount);
but1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
lab.setText(testAccount1(Integer.parseInt(t[2].getText())));
lab1.setText("Account : "+b.accnum+", Current Balance : "+b.amount);
}
});
}
else if(des.equals("Withdraw")){
b=new BankAccount(Integer.parseInt(t[0].getText()),Integer.parseInt(t[1].getText()));
but1.setVisible(true);
l[2].setVisible(false);
l[3].setVisible(true);
t[2].setVisible(false);
t[3].setVisible(true);
but.setVisible(false);
l[0].setVisible(false);
l[1].setVisible(false);
t[0].setVisible(false);
t[1].setVisible(false);
lab1.setText("Account : "+b.accnum+", Current Balance : "+b.amount);
but1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
lab.setText(testAccount2(Integer.parseInt(t[3].getText())));
lab1.setText("Account : "+b.accnum+", Current Balance : "+b.amount);
}
});
}
}
});
pane.addTab("Deposit/Withdrawl",panel2);

add(pane);
ButtonHandler handler =new ButtonHandler();
submit.addActionListener(handler);
}
String testAccount1(int d_amt){
String msg;
b.deposit(d_amt);
msg="Transaction Succesful";
return msg;
}
String testAccount2(int w_amt){
String msg;
msg="Transaction Succesful";
try{
b.withdraw(w_amt);
}catch(FundsInsufficientException fe){
fe=new FundsInsufficientException(b.amount,w_amt);
msg=String.valueOf(fe);
}
return msg;
}
private class ButtonHandler implements ActionListener{
public void actionPerformed(ActionEvent event){

String output="Surname:"+(name1.getText())+
"\nFirst Name:"+(first1.getText())+
"\nCourseName:"+(courseName1.getText())+
"\nYear of study:"+(year1.getText())+
"\nMobile Number:"+(phone1.getText())+
"\nFaculty Name:"+(facultyName1.getText())+
"\nUniversity:"+(university1.getText())+
"\nPhysical Address:"+(telephone1.getText())+
"\nE-mail Address:"+(email1.getText())+
"\nSex:"+(gender1.getText());

December 2, 2009 at 2:30 PM

continue..

if((name1.getText().equals(""))||(first1.getText().equals(""))||(courseName1.getText().equals(""))||(year1.getText().equals(""))||(phone1.getText().equals(""))||(facultyName1.getText().equals(""))||(university1.getText().equals(""))||(telephone1.getText().equals(""))||(email1.getText().equals(""))||(gender1.getText().equals("")))
JOptionPane.showMessageDialog(openTest.this,String.format("Complete the information Above",JOptionPane.ERROR_MESSAGE));
else{
JOptionPane.showMessageDialog(null,output,"Customer Information",JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(openTest.this,
String.format("Congratulations!You have successfully opened an account with us",event.getActionCommand()));
}
name1.setText("");
courseName1.setText("");
facultyName1.setText("");
year1.setText("");
university1.setText("");
email1.setText("");
telephone1.setText("");
gender1.setText("");
first1.setText("");
phone1.setText("");
}
}
}
public class OpenSavingsAccount2{
public static void main(String[] args){
openTest savings =new openTest();
savings.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
savings.setSize(450,380);
savings.setVisible(true);
}
}
class BankAccount{
int accnum;
int amount;
BankAccount(int num,int amt){
accnum=num;
amount=amt;
}
public void deposit(int amt){
amount=amount+amt;
}
public void withdraw(int amt) throws FundsInsufficientException{
if(amt>amount)
throw new FundsInsufficientException(amount,amt);
else
amount=amount-amt;
}
}
class FundsInsufficientException extends Exception{
int balance;
int withdraw_amount;
FundsInsufficientException(int bal,int w_amt){
balance=bal;
withdraw_amount=w_amt;
}
public String toString(){
return "Your withdraw amount ("+withdraw_amount+") is more than the balance ("+balance+"). No withdrawal was recorded.";
}
}

Thanks









Related Tutorials/Questions & Answers:
please modify this so that it can work better - Swing AWT
please modify this so that it can work better   this program is about opening a savings account, i need any one to modify it and add new features...("*" +"Surname"); name.setToolTipText("Please tell us surname"); add(name); name1 =new
modify this so that i can work better - Swing AWT
modify this so that i can work better  this program is about opening a savings account, i need any one to modify it and add new features to it to make i more better. the codes are; //OpenSavingsAccount1.java import
Advertisements
How can i modify my account in roseindia
How can i modify my account in roseindia  Presently am not using my gmail id. I have to modify my roseindia account. Please send the answer to following mail id
can modify this application connection with database
can modify this application connection with database   hi i'm want... to Java Frame, in here can i ask one more question about using this application modify connection with database ? import javax.swing.*; import java.applet.
Please help me to modify my java code from php code
the exact result as the above PHP code is giving. So please help me to convert...Modify Java code from PHP Code  i want to covert this php code int java/JSP. if (isset($_POST['orders'])) { $orders = explode('&', $_POST
Please Provide the direct Downloadable source code for better understanding
Please Provide the direct Downloadable source code for better understanding  Hello Roseindia Team, This is Mohammed Vaseem. Am very much impressed.... I kindly request you to please provide the direct downloadable source code so
Please help me to modify my java code from php code
Please help me to modify my java code from php code  i want to covert...) ... but this is not giving me the exact result as the above PHP code is giving. So please...) in the order column. So that when they refresh the page their order should be remain
Please can you help
Please can you help  I have a some code which uses a textarea comment box that will on post return the users text to the same page that they entered...; Please could you change the code so it will do this Please. Many thanks. Colin
Can a data scientist work from home?
: Can a data scientist work from home? Try to provide me good examples or tutorials links so that I can learn the topic "Can a data scientist work from home...Can a data scientist work from home?  Hi, I am beginner in Data
Can you work part time as a data scientist?
to learn: Can you work part time as a data scientist? Try to provide me good examples or tutorials links so that I can learn the topic "Can you work part...Can you work part time as a data scientist?  Hi, I am beginner
Can you work as a data scientist from home?
to learn: Can you work as a data scientist from home? Try to provide me good examples or tutorials links so that I can learn the topic "Can you work...Can you work as a data scientist from home?  Hi, I am beginner
Can i use Scriptlets inside javascript,if so how?
Can i use Scriptlets inside javascript,if so how?  Can i use Scriptlets inside javascript,if so how
my hibernate showing the following exception so how i can resolve it
my hibernate showing the following exception so how i can resolve it   Caused by: java.lang.ClassNotFoundException: org.hibernate.Session at java.net.URLClassLoader$1.run(Unknown Source
Where can I get best Data science training with project work?
work? Try to provide me good examples or tutorials links so that I can learn the topic "Where can I get best Data science training with project work...Where can I get best Data science training with project work?  Hi, I
Please , can any one answer this Question?
Please , can any one answer this Question?  How to cummunicate one web application to another web application in different places
please check my code is wrong or ok.it was not work .this is form validation in javascript using jsf page
please check my code is wrong or ok.it was not work .this is form validation in javascript using jsf page  <p>?xml version='1.0' encoding...; Please visit the following link: JSF Example
please check my code is wrong or ok.it was not work .this is form validation in javascript using jsf page
;   Please visit the following link: JSF
Can any one please help me in this ,,,,,,, need java code for this ,,,,please anyone
Can any one please help me in this ,,,,,,, need java code for this ,,,,please... is given a serial number is stored securely. Each day a work schedule.... Administration staff, allocate these tasks to different drivers, who work for AVP
please help with the coding of this interface,i cnt seem to figure out codes for things to work here.realy nid them ASAP plz
please help with the coding of this interface,i cnt seem to figure out codes for things to work here.realy nid them ASAP plz  /* * To change.... * WARNING: Do NOT modify this code. The content of this method is * always
please help with the coding of this interface,i cnt seem to figure out codes for things to work here.realy nid them ASAP plz
please help with the coding of this interface,i cnt seem to figure out codes for things to work here.realy nid them ASAP plz  /* * To change.... * WARNING: Do NOT modify this code. The content of this method is * always
How do I change a large string into hex and then into byte so that SHA1 can be applied to it?
How do I change a large string into hex and then into byte so that SHA1 can be applied to it?  I work with cellphones and deal with MEID numbers... into hex and then into byte so that SHA1 can give me the correct result
modify program
modify program  Hi how could I modify this program so that if I say yes for the dialog the following prompt would be displayed for the user to enter the information and would stop if no is selected.As the program is now if I say
Please tell me how can i convert string to timer
Please tell me how can i convert string to timer  Please tell me how can i convert string to timer
how to store,retrieve,modify the data
how to store,retrieve,modify the data  hello sir ,how to store,retrieve,modify the data using the swing please help me
CAN ANYONE SOLVE THIS FOR ME. URGENT HELP NEEDED. PLEASE HELP
CAN ANYONE SOLVE THIS FOR ME. URGENT HELP NEEDED. PLEASE HELP   ... to an earlier version. Always make sure that your work...?? otherwise. The overall mark can be calculated by multiplying both
CAN ANYONE SOLVE THIS FOR ME. URGENT HELP NEEDED. PLEASE HELP
CAN ANYONE SOLVE THIS FOR ME. URGENT HELP NEEDED. PLEASE HELP   Write.... Always make sure that your work compiles. If it doesnââ?¬â... to 40 and ââ?¬Å?failââ?¬Â? otherwise. The overall mark can
please any one can help me to write a code for this question?
please any one can help me to write a code for this question?  1) Copy one file content to other? 2) Count the number of words in a file
Please tell me where I can find tutorials on spring hibernate?
Please tell me where I can find tutorials on spring hibernate?  Hello, Please tell me where I can find tutorials on spring hibernate? Thanks..   Dear Friend, You can find some good tutorials on Spring Hibernate here
how can i write this program ?please suggest me
how can i write this program ?please suggest me  Program to calculate the sum of two big numbers (the numbers can contain more than 1000 digits). Don't use any library classes or methods (BigInteger etc
please any one can help me to write a code for this question?
please any one can help me to write a code for this question?  Q 1) In a class first day 25 students are joined. After two days that total students will increased to 60. We can develop a program by using ArrayList concept
how to modify QuestionServlet.java page?
how to modify QuestionServlet.java page?  Dear frnds, how to modify existing QuestionServlet. java file
ModuleNotFoundError: No module named 'pdfconduit-modify'
ModuleNotFoundError: No module named 'pdfconduit-modify'  Hi, My... named 'pdfconduit-modify' How to remove the ModuleNotFoundError: No module named 'pdfconduit-modify' error? Thanks   Hi, In your
Strategies for better Fleet Management
to record and save data related to daily work, also the past work can be saved and seen whenever the need be. Besides these softwares can maintain the daily work he...Owner and manger of fleet must follow some important strategies for better
how can create pop() method in this program ,Or how can delete image in it when i press pop button in runtime ??? please help me ...
how can create pop() method in this program ,Or how can delete image in it when i press pop button in runtime ??? please help me ...   ...," Album is Full you can not push the image ."); else top=top+1; aray[top]=item
ModuleNotFoundError: No module named 'better'
to install padas library. You can install better python with following command...ModuleNotFoundError: No module named 'better'  Hi, My Python... 'better' How to remove the ModuleNotFoundError: No module named 'better'
how to modify hosts file in ubuntu
how to modify hosts file in ubuntu  Hi, I want to add few host names with ip address in Ubuntu. how to modify hosts file in ubuntu? Thanks  .... In the vi editor you can change values Save and exit vi editor. This way you can
how to modify content of XML file
modify....!!! How do i do it??can somebody give me a sample code...how to modify content of XML file  hi, I want to modify content of a xml file.There are two tags of similar name say <ContentName>C:\Myinfo
Is DataCamp better than coursera?
: Is DataCamp better than coursera? Try to provide me good examples or tutorials links so that I can learn the topic "Is DataCamp better than coursera?"...Is DataCamp better than coursera?  Hi, I am beginner in Data Science
Which is better DataCamp or Dataquest?
: Which is better DataCamp or Dataquest? Try to provide me good examples or tutorials links so that I can learn the topic "Which is better DataCamp...Which is better DataCamp or Dataquest?  Hi, I am beginner in Data
Which is better udemy or DataCamp?
: Which is better udemy or DataCamp? Try to provide me good examples or tutorials links so that I can learn the topic "Which is better udemy or DataCamp?"...Which is better udemy or DataCamp?  Hi, I am beginner in Data
Is R better than Python?
Is R better than Python?  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: Is R better than Python? Try to provide me good examples or tutorials links so that I can
Which is better SAS or SPSS?
is better SAS or SPSS? Try to provide me good examples or tutorials links so that I can learn the topic "Which is better SAS or SPSS?". Also tell me...Which is better SAS or SPSS?  Hi, I am beginner in Data Science
Which country is better for Masters?
: Which country is better for Masters? Try to provide me good examples or tutorials links so that I can learn the topic "Which country is better for Masters...Which country is better for Masters?  Hi, I am beginner in Data
Which is better DataCamp or Coursera?
: Which is better DataCamp or Coursera? Try to provide me good examples or tutorials links so that I can learn the topic "Which is better DataCamp...Which is better DataCamp or Coursera?  Hi, I am beginner in Data
Which is better MBA or MSC?
is better MBA or MSC? Try to provide me good examples or tutorials links so that I can learn the topic "Which is better MBA or MSC?". Also tell me which...Which is better MBA or MSC?  Hi, I am beginner in Data Science
Is Java or Python better to learn?
: Is Java or Python better to learn? Try to provide me good examples or tutorials links so that I can learn the topic "Is Java or Python better to learn?"...Is Java or Python better to learn?  Hi, I am beginner in Data
Is DataCamp better than codecademy?
: Is DataCamp better than codecademy? Try to provide me good examples or tutorials links so that I can learn the topic "Is DataCamp better than codecademy...Is DataCamp better than codecademy?  Hi, I am beginner in Data
Is R or Python better for finance?
or Python better for finance? Try to provide me good examples or tutorials links so that I can learn the topic "Is R or Python better for finance?"...Is R or Python better for finance?  Hi, I am beginner in Data
Is Python or C++ better?
++ better? Try to provide me good examples or tutorials links so that I can learn the topic "Is Python or C++ better?". Also tell me which...Is Python or C++ better?  Hi, I am beginner in Data Science
date_modify
date_modify() in PHP date_modify or DateTime::modify function modifies... by strtotime(). It returns the modify date time. Description public DateTime DateTime::modify ( string $modify ) DateTime date_modify ( DateTime $object

Ads