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



Home Answers Viewqa Swing-AWT please modify this so that it can work better

Have Programming Question? Ask it here!
 
 
 


placid
please modify this so that it can work better
3 Answer(s)      4 years and 8 months ago
Posted in : Swing AWT



Advertisement
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
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.
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
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
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 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 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
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
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
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
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
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
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
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 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 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
Strategies for better Fleet Management
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 assigns...Owner and manger of fleet must follow some important strategies for better
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 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
A better Java JSON library?
A better Java JSON library?   A better Java JSON library
how to modify QuestionServlet.java page?
how to modify QuestionServlet.java page?  Dear frnds, how to modify existing QuestionServlet. java file
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 ...
= AlbumInJava.class.getResource(path);// please what dose the work ? if (img != null...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 ...   
which is better - Subversion
which is better  Dear sir, Could u pls tell which version control is better among the following four. Subversion, git, bazaar, Mercurial
Why PHP Is So Useful
become very popular in recent years. This is a form of scripting that can work.... There are never any charges involved with getting it to work. A user can simply go online... to handle all sorts of computers. It can work across different operating systems
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
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
A few questions related to developing a blog....can anyone please help me out??
A few questions related to developing a blog....can anyone please help me out... jsp.I have a few questions.... Can anyone tell me if we can insert images...??If it is possible then how is it done?? If we can insert images in the textarea then how
Please tell me how I can access a field (data type char) of resultset in a java class
Please tell me how I can access a field (data type char) of resultset in a java...("empsex")); as erroneous. There is no method like getChar() also. Please tell me how i can access
please tell anybody how can i set a value in hiperlink for edit n delete link
please tell anybody how can i set a value in hiperlink for edit n delete link  <logic:present name="allRecords"> <logic:notEmpty name="allRecords"> <logic:iterate id="user" name
Please can I get the code for solution of producer consumer problem using semaphores?
Please can I get the code for solution of producer consumer problem using semaphores?  Please can I get the code for solution of producer consumer problem using semaphores?   import java.util.*; class Semaphore
which one is better, Flex or Java?
which one is better, Flex or Java?  Does flex has a scope to survive in IT? Which one of these two, Flex and Java, has a better scope of survival
which one is better Struts2 or JSF
which one is better Struts2 or JSF  Which framework is better for the development of core banking solution for the presentation layer Struts2 or JSF2.Request you to explain with the valide reason. Thanks in Advance
Modify Data Type with ALTER Command
Modify Data Type with ALTER Command  Is it possible to modify... EmpName INT; Is it possible to modify the above table like... the following query: ALTER TABLE Emp MODIFY EmpName int(255
jvm work
jvm work  wht is the work of jvm? deaply.   Hi Friend, Java Virtual Machine or JVM for short is a software execution engine to run the java programs. Java Virtual Machine is also known as "Java Interpreter" which
Work Email- Dos and Don?ts
Work Email- Dos and Don’ts   ... and the Internet, emails are fast replacing letters in the realm of work communications. The reasons are obvious- emails are faster, cheaper and you can afford
collection frame work
collection frame work  could you please tell me detail the concept of collection frame work
which is better server for java applications? apache or jboss?
which is better server for java applications? apache or jboss?  which is better server? apache or jboss
java please please help
[] to HashMap so that i can seperate key and value using Map.Entry.Please help me!  ...java please please help  Dear Friends plz help me to complete... to split this whole String "a" into broken tokens like a=100,b=200,c=300 so have
Java-Xml -Modify and Update Node - Java Beginners
Java-Xml -Modify and Update Node   test_final_1 2009-025T13:23...(); } } I want to modify the values of and in the above xml posted and update the values in the same xml. Please help me in this regard...   Hi
Places Every Healthcare Managers Dream to Work For
rigorous work environments that can fuel faster career growth in the industry. Some of the greatest health care facilities in the world provide work environment for the health care managers that can usher huge career opportunities
the question make me so blur
the question make me so blur  write java code that read an integer and determine and print whether it is odd or even.(Hint: use the remainder operator.An even number is a multiple of 2. Any multiple of 2 leaves a remainder of 0
Java--Xml Modify Node Value - Java Beginners
Java--Xml Modify Node Value  I have the following xml. test_final_1 2009-025T13:23:45 B2B . I want to retrieve the values.....please correct me NodeList list = doc.getElementsByTagName
Advertisements
 

 

 

DMCA.com