Friday, October 8, 2010

SOURCE CODE FOR BANK LOAN APPLICATION FORM (java language)

1 import javax.swing.*;
2 import java.awt.event.*;
3 import java.awt.Toolkit;
4 import java.awt.*;
5 import java.io.*;
6
7
public class LoanForm extends JFrame implements ActionListener{
8   static LoanForm myLoanForm;
9   JTextArea myField= new JTextArea(10,35);
10
11
12 
JScrollPane scroll = new JScrollPane (myField,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
13 JTextField name, amount,address, phone, email, accNum, date;
14 JCheckBox small, medium, large;
15 JButton confirmButton, clearButton, exitButton, saveButton, openButton;
16
17 JTextField field = new JTextField(10);
18 Font f = new Font("Book Antiqua", Font.BOLD, 16);
19
20
public LoanForm(){
21 setTitle("Loan Application Form");
22 setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE);
23
24 ImageIcon idIcon = new ImageIcon("c:\\Dogs\\z.png");
25 JButton idButton = new JButton(idIcon);
26 idButton.setBackground(Color.GREEN);
27 idButton.setBorderPainted(false);
28 idButton.setContentAreaFilled(false);
29
30
JPanel panel1 = new JPanel();
31 myField.setBackground(Color.YELLOW);
32 idButton.setBackground(Color.GREEN);
33
34
addItem(panel1, idButton , 0, 0, 1, 1, GridBagConstraints.WEST);
35 JScrollPane ss= new JScrollPane(panel1, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
36 JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
37 panel1.setLayout(new GridBagLayout());
38
39 JLabel instructions0 = new JLabel(" TANJIBO BANK OF MALAWI"); 40 addItem(panel1,instructions0 , 0, 1, 1, 1, GridBagConstraints.NORTH);
41 instructions0.setFont(new Font("Castellar", Font.BOLD, 20));
42
43 JLabel instructions1 = new JLabel("(your success is our priority!)");
44 instructions1.setFont(new Font("Book Antiqua", Font.ITALIC, 12));
45 addItem(panel1, instructions1, 0, 2, 1, 1, GridBagConstraints.CENTER);
46
47 addItem(panel1, new JLabel(""), 0, 3, 1, 1, GridBagConstraints.WEST);
48
49
50
JLabel instructions2 = new JLabel("LOAN APPLICATION FORM");
51 addItem(panel1,instructions2 , 0, 3, 1, 1, GridBagConstraints.NORTH);
52 instructions2.setFont(new Font("Times New Roman", Font.BOLD, 16));
53
54
55
56 JLabel instructions3 = new JLabel("Instructions:");57 addItem(panel1, instructions3, 0, 4, 1, 1, GridBagConstraints.WEST);
58 instructions3.setFont(new Font("Book Antiqua", Font.ITALIC, 16));
59
60 JLabel instructions13 = new JLabel("Apply for a maximum of K500 000 if you are in small enterprise; K1 000 000 if you are in medium enterprise;");
61 addItem(panel1, instructions13, 0, 5, 1, 1, GridBagConstraints.WEST);
62 instructions13.setFont(new Font("Book Antiqua", Font.ITALIC, 16));
63
64

65 JLabel instructions5 = new JLabel("and K5 000 000 if you are in a large enterprise ");
66 addItem(panel1, instructions5, 0, 7, 1, 1, GridBagConstraints.WEST);
67 instructions5.setFont(new Font("Book Antiqua", Font.ITALIC, 16));
68
69
JLabel instructions6 = new JLabel("Make sure you have filled the Applicant name's field and the amount (numbers without spaces or a K)");
70 addItem(panel1, instructions6, 0, 8, 1, 1, GridBagConstraints.WEST);
71 instructions6.setFont(new Font("Book Antiqua", Font.ITALIC, 16));
72
73 addItem(panel1, new JLabel(""), 0, 9, 1, 1, GridBagConstraints.WEST);
74
75 addItem(panel1, new JLabel("Name of the Applicant:"), 0, 10, 1, 1, GridBagConstraints.WEST);
76 addItem(panel1, new JLabel("Applicant's Phone Number:"), 0, 11, 1, 1, GridBagConstraints.WEST);
77 addItem(panel1, new JLabel("Applicant's Contact Address:"), 0, 12, 1, 1, GridBagConstraints.WEST);
78 addItem(panel1, new JLabel("Applicant's E-mail Address:"), 0, 13, 1, 1, GridBagConstraints.WEST);
79 addItem(panel1, new JLabel("Applicant's Account Number:"), 0,14,1,1, GridBagConstraints.WEST);
80 addItem(panel1, new JLabel("Date of Loan Application:"), 0,15,1,1, GridBagConstraints.WEST);
81
82 addItem(panel1, new JLabel(""), 0, 16, 1, 1, GridBagConstraints.WEST);
83
84
85
86
name = new JTextField(25);
87 phone = new JTextField(25);
88 address = new JTextField(25);
89 email= new JTextField(25);
90 accNum= new JTextField(25);
91 date= new JTextField(25);
92
93 name.setBackground(Color.YELLOW);
94 phone.setBackground(Color.YELLOW);
95 email.setBackground(Color.YELLOW);
96 accNum.setBackground(Color.YELLOW);
97 date.setBackground(Color.YELLOW);
98 address.setBackground(Color.YELLOW);
99
100 addItem(panel1, name, 0, 10, 2, 1, GridBagConstraints.NORTH);
101 addItem(panel1, phone, 0, 11, 2, 1, GridBagConstraints.NORTH);
102 addItem(panel1, address, 0, 12, 2, 1, GridBagConstraints.NORTH);
103 addItem(panel1, email, 0, 13, 2, 1, GridBagConstraints.NORTH);
104 addItem(panel1, accNum, 0, 14, 2, 1, GridBagConstraints.NORTH);
105 addItem(panel1, date, 0, 15, 2, 1, GridBagConstraints.NORTH);
106
107 addItem(panel1, new JLabel(""), 0, 16, 1, 1, GridBagConstraints.WEST);
108
109

110 Box sizeBox = Box.createVerticalBox();
111 small = new JCheckBox("Small Enterprise", true);
112 medium = new JCheckBox("Medium Enterprise");
113 large = new JCheckBox("Large Enterprise");
114 ButtonGroup sizeGroup = new ButtonGroup();
115 sizeGroup.add(small);
116 sizeGroup.add(medium);
117 sizeGroup.add(large);
118 sizeBox.add(small);
119 sizeBox.add(medium);
120 sizeBox.add(large);
121 sizeBox.setBorder(BorderFactory.createTitledBorder("Applicant's Enterprise"));
122 small.setBackground(Color.GREEN);
123 medium.setBackground(Color.GREEN);
124 large.setBackground(Color.GREEN);
125 addItem(panel1, sizeBox, 0, 17, 1, 1, GridBagConstraints.WEST);
126
127 addItem(panel1, new JLabel("Amount (in Malawian Kwacha:)"), 0, 18, 1, 1, GridBagConstraints.WEST);
128 amount= new JTextField(20);
129 addItem(panel1, amount, 0, 18, 2, 1, GridBagConstraints.NORTH);
130 amount.setBackground(Color.YELLOW);
131 Box buttonBox = Box.createHorizontalBox();
132 confirmButton = new JButton("Confirm");
133 clearButton = new JButton("Clear");
134 confirmButton.setBackground(Color.GREEN);
135 clearButton.setBackground(Color.GREEN);
136
137

138 buttonBox.add(confirmButton);
139 confirmButton.addActionListener(this);
140 buttonBox.add(Box.createHorizontalStrut(25));
141 buttonBox.add(clearButton);
142 clearButton.addActionListener(this);
143 addItem(panel1, new JLabel(""), 0, 19, 1, 1, GridBagConstraints.WEST);
144
145 myField.setEnabled(false);
146 saveButton = new JButton("Save");
147 openButton = new JButton("Open");
148 exitButton = new JButton("Exit");
149 openButton.setBackground(Color.GREEN);
150 saveButton.setBackground(Color.GREEN);
151 exitButton.setBackground(Color.GREEN);
152
153
154
addItem(panel1, saveButton, 0, 22, 1, 1, GridBagConstraints.WEST);
155 saveButton.addActionListener(this);
156 addItem(panel1, openButton, 0, 22, 1, 1, GridBagConstraints.EAST);
157 openButton.addActionListener(this);
158 addItem(panel1, exitButton, 0, 22, 1, 1, GridBagConstraints.CENTER);
159 exitButton.addActionListener(this);
160
161 addItem(panel1, buttonBox, 0, 20, 1, 1, GridBagConstraints.CENTER);
162 addItem(panel1, scroll, 0, 21, 1, 1, GridBagConstraints.CENTER);
163 panel1.setBackground(Color.GREEN);
164 setContentPane(ss);
165 setSize(726,800);
166 setVisible(true);
167
168 setResizable(false);
169 setLocation(300,0);
170 }
171 private int click=0;
172 public void actionPerformed(ActionEvent evnt){
173
174 if (evnt.getSource() == confirmButton){
175 if((name.getText().length() == 0)||(amount.getText().length()==0)){176 JOptionPane.showMessageDialog(LoanForm.this,
177 "You didn't enter your name or the amount ", "Warning!",
178 JOptionPane.INFORMATION_MESSAGE);
179 }
180 else if(small.isSelected()&& Double.parseDouble(amount.getText())>=500000){
182 amount.setText("");
183 JOptionPane.showMessageDialog(LoanForm.this,"You have to apply for less than K500 000","Warning!",
184 JOptionPane.INFORMATION_MESSAGE);
185 }
186
187 else if(medium.isSelected()&&(Integer.parseInt(amount.getText())>=1000000)){
188 amount.setText("");
189 JOptionPane.showMessageDialog(LoanForm.this,"You have to apply for less than K1 000 000","Warning!",
190 JOptionPane.INFORMATION_MESSAGE);
191 }
192
193 else if(large.isSelected()&&(Integer.parseInt(amount.getText())>=5000000)){
194 amount.setText("");
195 JOptionPane.showMessageDialog(LoanForm.this,"You have to apply for less than K5 000 000","Warning!",
196 JOptionPane.INFORMATION_MESSAGE);
197 }
198 else{
199
200 display();
201 clear2();
202
203 }
204
205 }
206
207 else if(evnt.getSource()==exitButton){
208 exitButton.addActionListener (new ChangesListener());
209 }
210
211 else if(evnt.getSource()==clearButton)
212 clear();
213 else if (evnt.getSource()==saveButton){
214 if(myField.getText().length() == 0){
215 JOptionPane.showMessageDialog(LoanForm.this,
216 "There is no information displayed ", "Warning!",
217 JOptionPane.INFORMATION_MESSAGE);
218 }
219 else{
220 saveButton.addActionListener (new SaveListener());
221 }
222 }
223 else if (evnt.getSource()==openButton)
224 openButton.addActionListener(new OpenListener());
225 }
226
227 private void addItem(JPanel p, JComponent c,int x, int y, int width, int height, int align){
228 GridBagConstraints gridBag = new GridBagConstraints();
229 gridBag.gridx = x;
230 gridBag.gridy = y;
231 gridBag.gridwidth = width;
232 gridBag.gridheight = height;
233 gridBag.weightx = 10;
234 gridBag.weighty = 10;
235 gridBag.insets = new Insets(8, 8, 5, 0);
236 gridBag.anchor = align;
237 gridBag.fill = GridBagConstraints.NONE;
238 p.add(c, gridBag);
239 }
240
241 public static void main(String [] args){
242 myLoanForm=new LoanForm();
243 }
244
245 public void clear() {
246 name.setText("");
247 address.setText("");
248 phone.setText("");
249 amount.setText("");
250 email.setText("");
251 accNum.setText("");
252 date.setText("");
253 myField.setText("");
254 }
255 public void clear2() {
256 name.setText("");
257 address.setText("");
258 phone.setText("");
259 amount.setText("");
260 email.setText("");
261 accNum.setText("");
262 date.setText("");
263 }
264
265 public void display(){
266
267 myField.append("NAME:\t\t"+name.getText()+"\n");
268 myField.append("PHONE NUMBER:\t"+phone.getText()+"\n");
269 myField.append("CONTACT ADDRESS:\t"+address.getText()+"\n");
270 myField.append("AMOUNT \t\tK"+amount.getText()+"\n");
271 myField.append("E-MAIL ADDRESS:\t"+email.getText()+"\n");
272 myField.append("ACCOUNT NUMBER:\t"+accNum.getText()+"\n");
273 myField.append("DATE:\t\t"+date.getText()+"\n");
274 // myField.append(small.getText());
275 myField.setFont(f);
276 }
277
278 public class OpenListener implements ActionListener{
279 public void actionPerformed(ActionEvent evnt){
280 JFileChooser fileChooser = new JFileChooser();
281 int result = fileChooser.showOpenDialog(myLoanForm);
282 if(result==JFileChooser.APPROVE_OPTION){
283 File inFile = null;
284 inFile=fileChooser.getSelectedFile();
285 try{
286 FileInputStream fileStream = new FileInputStream(inFile);
287 DataInputStream dataStream = new DataInputStream(fileStream);
288 String displayText = dataStream.readUTF();
289 myField.setText(displayText);
290 fileStream.close();
291 }
292 catch(IOException ioExcept){
293 JOptionPane.showMessageDialog(null, "File Not Found");
294 }
295 }
296 }
297 }
298
299 public class ChangesListener implements ActionListener{
300 public void actionPerformed(ActionEvent event){
301
302 int reply = JOptionPane.showConfirmDialog(null,"Do you want to save the changes?","Tanjibo's Loan Application Form",JOptionPane.INFORMATION_MESSAGE);
303 if(reply==JOptionPane.YES_OPTION)
304 save();
305
306 else if(reply==JOptionPane.NO_OPTION)
307 System.exit(0);
308 else
309 {}
310 }
311 }
312 public class SaveListener implements ActionListener{
314 public void actionPerformed(ActionEvent evnt){
315 save();
316 }
317 }
318 public void save(){
319 JFileChooser fileChooser = new JFileChooser();
320 int result = fileChooser.showSaveDialog(myLoanForm);
321 if(result==JFileChooser.APPROVE_OPTION){
322 File outFile = null;
323 outFile=fileChooser.getSelectedFile();
324 if (outFile.exists()){
325 JOptionPane.showMessageDialog(null, "File already exists");
326 }
327 else
328 try{
329 FileOutputStream fileStream = new FileOutputStream(outFile); 330 DataOutputStream dataStream = new DataOutputStream(fileStream);
331 dataStream.writeUTF(myField.getText());
332 fileStream.close();
333 }
334 catch(IOException e){
335 JOptionPane.showMessageDialog(null, "Error in Opening");
336 }
337 }
338 else if(result==JFileChooser.ERROR_OPTION){
339 JOptionPane.showMessageDialog(null, "ERROR OCCURS IN SAVING");
340 }
341
342 }
343 }

No comments:

Post a Comment