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

 
 


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

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 Pages:
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
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
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
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
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
Help Me in My Java Work
Help Me in My Java Work  Can you help me please... Write a Java... entered so far: 1. GPA = 4.0 Enter a mark between ââ?¬Å?0ââ?¬Â? and ââ?¬Å?100ââ?¬Â? or ââ?¬Å?-1ââ?¬Â? to exit: 89 Total number of marks entered so far: 2
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
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
Load function ***PLEASE HELP
); //boolean is now false so that the loop can be exited run = false... is now false so that the loop can be exited run = false...Load function ***PLEASE HELP   Hi I am writing a program that tracks
zend2 frame work
zend2 frame work  Hi can you please detail about Zend framework 2 latest folder structure and related things in details . I already seen zend... .if any experts on zend and any good blogs can you send me details. Thankyou
I find that you have changed jobs many times so far. Why is it so?
I find that you have changed jobs many times so far. Why is it so... periods, you can simply round it off to years this way: 1989-2000- Position.... Avoid placing blame on other people for your changes. However you can mention
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 ...   
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
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
Why Apple's iPad Is Better Than A Laptop
an iPad gives you access to all sorts of apps on Apple’s website so you can...Why Apple’s iPad Is Better Than A Laptop Apple’s iPad burst... for everything from form to function. The truth is that no device can really cater
ajax code please help to solve this........
ajax code please help to solve this.  in this i am trying to get data... and use ajax onchange but when i am trying to do so it show some error...; <li><a href="workprofile.jsp">Work Profile</a>
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
Struts validation not work properly - Struts
Struts validation not work properly  hi... i have a problem... it, it can open the add.jsp, it seems like it's only allowed for 2 fields...;Hi Friend, Please
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
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 help me.
please help me.  I have a jsp page under that i add a list box under i get the countries through my database. so how can i do
please - Java Beginners
please   it did run in one of my friend computer but not mine bcoz she has editor iam running my code using Dos so can you send me the softwere...; Hi You can find many more text editor just search by "text editor" keyword
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
Is Window 8 better than Windows 7?
8 better than windows 7, its predecessor? Here we will give a point wise... version comes with built in intelligence to work according to the users... good support to multiple monitors. Different users can have different background
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
Java Help Please
Java Help Please  I can't seem to figure out how to make this program, can some one help me please? It is due soon!! 4) Write a program... ints, so the input such as 02 14 2013) for a date. The program should have
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
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
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
collection frame work
collection frame work  could you please tell me detail the concept of collection frame work
Please guide me sir - EJB
Please guide me sir  Hi I am Pradeep singh ,done SCJP 5.0 and SCWCD 5.0 .Now i want to learn further .So please tell me whether should i learn EJB... next? Because both can do same work.Please advice me .At present i am jobless
Human resources for small business
the organization today pay main attention on its HR departments so that it can.... It has to work for a collective relationship between the management and the employee. Employees can give their maximum output if they are satisfied
Why Outsource Work - Read Why Need of Outsourcing Services
Outsourcing : Why Outsource Work? Introduction Many businesses, big and small... set up is not equipped to handle all the work. At the same time, the company... becomes the tool to bridge the gap. How it Works The client company can strike
please help in jsp - JSP-Servlet
area by condtion so that when i move from main.jsp to Home.jsp, it can show some...please help in jsp  i have two Jsp's pages. on main.jsp have some list of schools. from there i can go home page of any school. home.jsp represents
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
ios work with nsdictionary
ios work with nsdictionary  How to work with NSDictionary in Objective C?   Working with NSDictionary in Objective C Basically.... It's very simple to create and retrive the key values using NSDictionary .. please
Help please, some strange errors
Help please, some strange errors  Sorry about this messy formatting... this errors so i have posted the whole program here. Here i tried to make the monopoly... play the error hits on to the console view. Can someone tell me what in the code
Situation: You belong to a category (physically challenged, a single parent, above 50 and so on) that might be considere
, above 50 and so on) that might be considered not competent enough...;t really thought about it, plant such doubts in his mind. What you can do here is to present sufficient counterbalancing information discreetly so
PHP and MySQL Work Well Together
important for anyone to use. The first thing to know is that the PHP script can work... to upload items or comments on a site. The MySQL database can work especially well... for a website to work with. This database can be programmed with a PHP script to allow
import package.subpackage.* does not work
: cannot access A bad class file: .\A.java file does not contain class A Please remove
urgent...pleAse help me.....please!
urgent...pleAse help me.....please!  please help me urgent! how can i do dictionary with the use of array code in java, where i will type the word then the corresponding meaning for that word will appear...thanks
Please HELPP
Please HELPP  The University wants to make a basic graphical display to show how many people received different grades for a piece of work... students. Your program should work with any number of student marks entered

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.