KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > demo > mortgage > gui > gui > Console


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2005 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id:Console.java 10:42:15 ddesjardins $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.demo.mortgage.gui.gui;
23
24 import java.awt.BorderLayout JavaDoc;
25 import java.awt.Dimension JavaDoc;
26 import java.awt.Font JavaDoc;
27 import java.awt.Rectangle JavaDoc;
28 import java.awt.event.ActionEvent JavaDoc;
29 import java.awt.event.ActionListener JavaDoc;
30 import java.io.DataInputStream JavaDoc;
31 import java.io.File JavaDoc;
32 import java.io.FileInputStream JavaDoc;
33 import java.io.InputStream JavaDoc;
34
35 import javax.swing.ImageIcon JavaDoc;
36 import javax.swing.JButton JavaDoc;
37 import javax.swing.JDesktopPane JavaDoc;
38 import javax.swing.JFrame JavaDoc;
39 import javax.swing.JLabel JavaDoc;
40 import javax.swing.JOptionPane JavaDoc;
41 import javax.swing.JTextArea JavaDoc;
42 import javax.swing.JTextField JavaDoc;
43 import javax.swing.JTextPane JavaDoc;
44
45 import org.objectweb.petals.demo.mortgage.gui.MortgageClient;
46
47 /**
48  * This class is the gui of the mortgage demonstration
49  *
50  * @author ddesjardins - eBMWebsourcing
51  */

52 public class Console extends javax.swing.JFrame JavaDoc {
53     private static final long serialVersionUID = -8117896325113377153L;
54
55     private JTextArea JavaDoc address;
56
57     private JTextPane JavaDoc addressTxt;
58
59     private JTextField JavaDoc carPayment;
60
61     private JTextPane JavaDoc carPaymentTxt;
62
63     private JTextField JavaDoc creditCards;
64
65     private JTextPane JavaDoc creditCardsTxt;
66
67     private JTextPane JavaDoc custTxt;
68
69     private JTextPane JavaDoc expensesTxt;
70
71     private JTextField JavaDoc firstName;
72
73     private JTextPane JavaDoc firstNameTxt;
74
75     private JTextField JavaDoc insurance;
76
77     private JTextPane JavaDoc insuranceTxt;
78
79     private JDesktopPane JavaDoc jDesktopPane;
80
81     private JTextField JavaDoc lastName;
82
83     private JTextPane JavaDoc lastNameTxt;
84
85     private JTextPane JavaDoc monthlyIncomeTxt;
86
87     private MortgageClient mortgageClient;
88
89     private JTextPane JavaDoc otherExpensesTxt;
90
91     private JTextField JavaDoc otherPayments;
92
93     private JTextPane JavaDoc otherPaymentsTxt;
94
95     private JTextField JavaDoc propertyTaxes;
96
97     private JButton JavaDoc reset;
98
99     private JTextArea JavaDoc result;
100
101     private JTextPane JavaDoc resultTxt;
102
103     private JTextField JavaDoc salary;
104
105     private JTextPane JavaDoc salaryTxt;
106
107     private JButton JavaDoc submit;
108
109     private JTextPane JavaDoc taxesTxt;
110
111     public Console() {
112         super();
113         initialize();
114     }
115
116     public Console(MortgageClient sampleClient) {
117         this();
118         this.mortgageClient = sampleClient;
119     }
120
121     public static void main(String JavaDoc[] args) {
122         Console inst = new Console();
123         inst.setVisible(true);
124         inst.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
125     }
126
127     public void setResponse(String JavaDoc msg) {
128         result.setText(msg);
129     }
130
131     /**
132      * Reset all the fields of the form
133      *
134      */

135     protected void resetForm() {
136         salary.setText("0");
137         lastName.setText("");
138         firstName.setText("");
139         address.setText("");
140         carPayment.setText("0");
141         insurance.setText("0");
142         creditCards.setText("0");
143         propertyTaxes.setText("0");
144         otherPayments.setText("0");
145     }
146
147     /**
148      * Tests the parameters and submits the data
149      *
150      */

151     protected void submit() {
152         // Test the data in the form
153
String JavaDoc firstName = this.firstName.getText();
154         String JavaDoc lastName = this.lastName.getText();
155         String JavaDoc address = this.address.getText();
156         String JavaDoc salary = this.salary.getText();
157         String JavaDoc taxes = this.propertyTaxes.getText();
158         String JavaDoc insurance = this.insurance.getText();
159         String JavaDoc auto = this.carPayment.getText();
160         String JavaDoc creditCards = this.creditCards.getText();
161         String JavaDoc otherPayments = this.otherPayments.getText();
162
163         String JavaDoc error = "";
164         try {
165             Float.parseFloat(salary);
166             if (Float.parseFloat(salary) <= 0) {
167                 error += "The salary must be positive! ";
168             }
169         } catch (NumberFormatException JavaDoc e) {
170             error += "The salary must be a number! ";
171         }
172         try {
173             Float.parseFloat(taxes);
174         } catch (NumberFormatException JavaDoc e) {
175             error += "The property taxes must be a number! ";
176         }
177         try {
178             Float.parseFloat(insurance);
179         } catch (NumberFormatException JavaDoc e) {
180             error += "The insurance must be a number! ";
181         }
182         try {
183             Float.parseFloat(auto);
184         } catch (NumberFormatException JavaDoc e) {
185             error += "The car payments must be a number! ";
186         }
187         try {
188             Float.parseFloat(creditCards);
189         } catch (NumberFormatException JavaDoc e) {
190             error += "The credit cards payments must be a number! ";
191         }
192         try {
193             Float.parseFloat(otherPayments);
194         } catch (NumberFormatException JavaDoc e) {
195             error += "The other payments must be a number! ";
196         }
197
198         if (!"".equals(error)) {
199             JOptionPane.showMessageDialog(this, error, "Error",
200                     JOptionPane.ERROR_MESSAGE);
201         } else {
202             if (mortgageClient != null) {
203                 mortgageClient.submit(firstName, lastName, address, salary,
204                         taxes, insurance, auto, creditCards, otherPayments);
205             } else {
206                 JOptionPane.showMessageDialog(this,
207                         "The component is not deployed in a JBI Container",
208                         "Error", JOptionPane.ERROR_MESSAGE);
209             }
210         }
211     }
212
213     /**
214      * This method initializes address
215      *
216      * @return javax.swing.JTextField
217      */

218     private JTextArea JavaDoc getAddress() {
219         if (address == null) {
220             address = new JTextArea JavaDoc(2, 20);
221             address.setWrapStyleWord(true);
222             address.setLineWrap(true);
223             address.setBounds(new Rectangle JavaDoc(150, 72, 150, 36));
224             address.setWrapStyleWord(true);
225             address.setBorder(new JTextField JavaDoc().getBorder());
226         }
227         return address;
228     }
229
230     /**
231      * This method initializes jTextPane3
232      *
233      * @return javax.swing.JTextPane
234      */

235     private JTextPane JavaDoc getAddressTxt() {
236         if (addressTxt == null) {
237             addressTxt = new JTextPane JavaDoc();
238             addressTxt.setBounds(new Rectangle JavaDoc(10, 70, 83, 22));
239             addressTxt.setEditable(false);
240             addressTxt.setText("Address:");
241             addressTxt.setOpaque(false);
242         }
243         return addressTxt;
244     }
245
246     /**
247      * This method initializes carPayment
248      *
249      * @return javax.swing.JTextField
250      */

251     private JTextField JavaDoc getCarPayment() {
252         if (carPayment == null) {
253             carPayment = new JTextField JavaDoc();
254             carPayment.setText("0");
255             carPayment.setBounds(new Rectangle JavaDoc(150, 262, 100, 18));
256         }
257         return carPayment;
258     }
259
260     /**
261      * This method initializes jTextPane62
262      *
263      * @return javax.swing.JTextPane
264      */

265     private JTextPane JavaDoc getCarPaymentTxt() {
266         if (carPaymentTxt == null) {
267             carPaymentTxt = new JTextPane JavaDoc();
268             carPaymentTxt.setBounds(new Rectangle JavaDoc(8, 260, 94, 22));
269             carPaymentTxt.setEditable(false);
270             carPaymentTxt.setText("Car payment:");
271             carPaymentTxt.setOpaque(false);
272         }
273         return carPaymentTxt;
274     }
275
276     /**
277      * This method initializes creditCards
278      *
279      * @return javax.swing.JTextField
280      */

281     private JTextField JavaDoc getCreditCards() {
282         if (creditCards == null) {
283             creditCards = new JTextField JavaDoc();
284             creditCards.setText("0");
285             creditCards.setBounds(new Rectangle JavaDoc(150, 282, 100, 18));
286         }
287         return creditCards;
288     }
289
290     /**
291      * This method initializes jTextPane621
292      *
293      * @return javax.swing.JTextPane
294      */

295     private JTextPane JavaDoc getCreditCardsTxt() {
296         if (creditCardsTxt == null) {
297             creditCardsTxt = new JTextPane JavaDoc();
298             creditCardsTxt.setBounds(new Rectangle JavaDoc(8, 280, 90, 22));
299             creditCardsTxt.setEditable(false);
300             creditCardsTxt.setText("Credit cards:");
301             creditCardsTxt.setOpaque(false);
302         }
303         return creditCardsTxt;
304     }
305
306     /**
307      * This method initializes custTxt
308      *
309      * @return javax.swing.JTextPane
310      */

311     private JTextPane JavaDoc getCustTxt() {
312         if (custTxt == null) {
313             custTxt = new JTextPane JavaDoc();
314             custTxt.setBounds(new Rectangle JavaDoc(8, 2, 185, 24));
315             custTxt.setFont(new Font JavaDoc("Dialog", Font.BOLD, 14));
316             custTxt.setEditable(false);
317             custTxt.setFont(new Font JavaDoc("Dialog", Font.BOLD, 14));
318             custTxt.setText("Customer Information:");
319             custTxt.setOpaque(false);
320         }
321         return custTxt;
322     }
323
324     /**
325      * This method initializes expensesTxt
326      *
327      * @return javax.swing.JTextPane
328      */

329     private JTextPane JavaDoc getExpensesTxt() {
330         if (expensesTxt == null) {
331             expensesTxt = new JTextPane JavaDoc();
332             expensesTxt.setBounds(new Rectangle JavaDoc(8, 160, 203, 24));
333             expensesTxt.setText("Monthly housing expense:");
334             expensesTxt.setFont(new Font JavaDoc("Dialog", Font.BOLD, 14));
335             expensesTxt.setOpaque(false);
336         }
337         return expensesTxt;
338     }
339
340     /**
341      * This method initializes firstName
342      *
343      * @return javax.swing.JTextField
344      */

345     private JTextField JavaDoc getFirstName() {
346         if (firstName == null) {
347             firstName = new JTextField JavaDoc();
348             firstName.setBounds(new Rectangle JavaDoc(150, 52, 150, 18));
349         }
350         return firstName;
351     }
352
353     /**
354      * This method initializes jTextPane2
355      *
356      * @return javax.swing.JTextPane
357      */

358     private JTextPane JavaDoc getFirstNameTxt() {
359         if (firstNameTxt == null) {
360             firstNameTxt = new JTextPane JavaDoc();
361             firstNameTxt.setBounds(new Rectangle JavaDoc(10, 50, 95, 22));
362             firstNameTxt.setEditable(false);
363             firstNameTxt.setText("First name:");
364             firstNameTxt.setOpaque(false);
365         }
366         return firstNameTxt;
367     }
368
369     /**
370      * This method initializes insurance
371      *
372      * @return javax.swing.JTextField
373      */

374     private JTextField JavaDoc getInsurance() {
375         if (insurance == null) {
376             insurance = new JTextField JavaDoc();
377             insurance.setText("0");
378             insurance.setBounds(new Rectangle JavaDoc(150, 212, 100, 18));
379         }
380         return insurance;
381     }
382
383     /**
384      * This method initializes jTextPane61
385      *
386      * @return javax.swing.JTextPane
387      */

388     private JTextPane JavaDoc getInsuranceTxt() {
389         if (insuranceTxt == null) {
390             insuranceTxt = new JTextPane JavaDoc();
391             insuranceTxt.setBounds(new Rectangle JavaDoc(8, 211, 118, 22));
392             insuranceTxt.setEditable(false);
393             insuranceTxt.setText("Hazard insurance:");
394             insuranceTxt.setOpaque(false);
395         }
396         return insuranceTxt;
397     }
398
399     /**
400      * This method initializes jDesktopPane
401      *
402      * @return javax.swing.JDesktopPane
403      */

404     private final JDesktopPane JavaDoc getJDesktopPane() {
405         if (jDesktopPane == null) {
406             jDesktopPane = new JDesktopPane JavaDoc();
407             jDesktopPane.add(getCustTxt(), null);
408             jDesktopPane.add(getLastNameTxt(), null);
409             jDesktopPane.add(getFirstNameTxt(), null);
410             jDesktopPane.add(getFirstName(), null);
411             jDesktopPane.add(getLastName(), null);
412             jDesktopPane.add(getAddressTxt(), null);
413             jDesktopPane.add(getAddress(), null);
414             jDesktopPane.add(getMonthlyIncomeTxt(), null);
415             jDesktopPane.add(getSalaryTxt(), null);
416             jDesktopPane.add(getSalary(), null);
417             jDesktopPane.add(getTaxesTxt(), null);
418             jDesktopPane.add(getPropertyTaxes(), null);
419             jDesktopPane.add(getExpensesTxt(), null);
420             jDesktopPane.add(getInsuranceTxt(), null);
421             jDesktopPane.add(getInsurance(), null);
422             jDesktopPane.add(getOtherExpensesTxt(), null);
423             jDesktopPane.add(getCarPaymentTxt(), null);
424             jDesktopPane.add(getCarPayment(), null);
425             jDesktopPane.add(getCreditCardsTxt(), null);
426             jDesktopPane.add(getCreditCards(), null);
427             jDesktopPane.add(getOtherPaymentsTxt(), null);
428             jDesktopPane.add(getOtherPayments(), null);
429             jDesktopPane.add(getSubmit(), null);
430             jDesktopPane.add(getReset(), null);
431             jDesktopPane.add(getResult(), null);
432             jDesktopPane.add(getResultTxt(), null);
433
434             byte[] buffer = null;
435             InputStream JavaDoc in = Console.class.getClassLoader()
436                     .getResourceAsStream("Petals pwd by EBM.jpg");
437             try {
438                 if (in == null) {
439                     in = new FileInputStream JavaDoc("src" + File.separator + "img"
440                             + File.separator + "Petals pwd by EBM.jpg");
441                 }
442                 DataInputStream JavaDoc dis = new DataInputStream JavaDoc(in);
443                 buffer = new byte[dis.available()];
444                 dis.readFully(buffer);
445             } catch (Exception JavaDoc e) {
446                 JOptionPane.showMessageDialog(this, e.getMessage(), "Error",
447                         JOptionPane.ERROR_MESSAGE);
448             }
449             ImageIcon JavaDoc img1 = new ImageIcon JavaDoc(buffer);
450             JLabel JavaDoc background1 = new JLabel JavaDoc(img1);
451             background1.setBounds(0, 0, img1.getIconWidth(), img1
452                     .getIconHeight());
453             jDesktopPane.add(background1, Integer.MIN_VALUE);
454         }
455         return jDesktopPane;
456     }
457
458     /**
459      * This method initializes lastName
460      *
461      * @return javax.swing.JTextField
462      */

463     private JTextField JavaDoc getLastName() {
464         if (lastName == null) {
465             lastName = new JTextField JavaDoc();
466             lastName.setBounds(new Rectangle JavaDoc(150, 32, 150, 18));
467         }
468         return lastName;
469     }
470
471     /**
472      * This method initializes lastNameTxt
473      *
474      * @return javax.swing.JTextPane
475      */

476     private JTextPane JavaDoc getLastNameTxt() {
477         if (lastNameTxt == null) {
478             lastNameTxt = new JTextPane JavaDoc();
479             lastNameTxt.setBounds(new Rectangle JavaDoc(10, 30, 84, 22));
480             lastNameTxt.setEditable(false);
481             lastNameTxt.setText("Last name:");
482             lastNameTxt.setOpaque(false);
483         }
484         return lastNameTxt;
485     }
486
487     /**
488      * This method initializes jTextPane4
489      *
490      * @return javax.swing.JTextPane
491      */

492     private JTextPane JavaDoc getMonthlyIncomeTxt() {
493         if (monthlyIncomeTxt == null) {
494             monthlyIncomeTxt = new JTextPane JavaDoc();
495             monthlyIncomeTxt.setBounds(new Rectangle JavaDoc(10, 110, 172, 22));
496             monthlyIncomeTxt.setFont(new Font JavaDoc("Dialog", Font.BOLD, 14));
497             monthlyIncomeTxt.setText("Monthly Income:");
498             monthlyIncomeTxt.setEditable(false);
499             monthlyIncomeTxt.setOpaque(false);
500         }
501         return monthlyIncomeTxt;
502     }
503
504     /**
505      * This method initializes jTextPane411
506      *
507      * @return javax.swing.JTextPane
508      */

509     private JTextPane JavaDoc getOtherExpensesTxt() {
510         if (otherExpensesTxt == null) {
511             otherExpensesTxt = new JTextPane JavaDoc();
512             otherExpensesTxt.setBounds(new Rectangle JavaDoc(8, 237, 194, 24));
513             otherExpensesTxt.setText("Other monthly expenses:");
514             otherExpensesTxt.setFont(new Font JavaDoc("Dialog", Font.BOLD, 14));
515             otherExpensesTxt.setEditable(false);
516             otherExpensesTxt.setOpaque(false);
517         }
518         return otherExpensesTxt;
519     }
520
521     /**
522      * This method initializes otherPayments
523      *
524      * @return javax.swing.JTextField
525      */

526     private JTextField JavaDoc getOtherPayments() {
527         if (otherPayments == null) {
528             otherPayments = new JTextField JavaDoc();
529             otherPayments.setText("0");
530             otherPayments.setBounds(new Rectangle JavaDoc(150, 302, 100, 18));
531         }
532         return otherPayments;
533     }
534
535     /**
536      * This method initializes jTextPane6211
537      *
538      * @return javax.swing.JTextPane
539      */

540     private JTextPane JavaDoc getOtherPaymentsTxt() {
541         if (otherPaymentsTxt == null) {
542             otherPaymentsTxt = new JTextPane JavaDoc();
543             otherPaymentsTxt.setBounds(new Rectangle JavaDoc(8, 300, 110, 22));
544             otherPaymentsTxt.setEditable(false);
545             otherPaymentsTxt.setText("Other payments:");
546             otherPaymentsTxt.setOpaque(false);
547         }
548         return otherPaymentsTxt;
549     }
550
551     /**
552      * This method initializes propertyTaxes
553      *
554      * @return javax.swing.JTextField
555      */

556     private JTextField JavaDoc getPropertyTaxes() {
557         if (propertyTaxes == null) {
558             propertyTaxes = new JTextField JavaDoc();
559             propertyTaxes.setText("0");
560             propertyTaxes.setBounds(new Rectangle JavaDoc(150, 192, 100, 18));
561         }
562         return propertyTaxes;
563     }
564
565     /**
566      * This method initializes reset
567      *
568      * @return javax.swing.JButton
569      */

570     private JButton JavaDoc getReset() {
571         if (reset == null) {
572             reset = new JButton JavaDoc();
573             reset.setBounds(new Rectangle JavaDoc(210, 340, 120, 28));
574             reset.setText("Reset");
575             reset.addActionListener(new ActionListener JavaDoc() {
576                 public void actionPerformed(ActionEvent JavaDoc evt) {
577                     resetForm();
578                 }
579             });
580         }
581         return reset;
582     }
583
584     /**
585      * This method initializes result
586      *
587      * @return javax.swing.JTextPane
588      */

589     private JTextArea JavaDoc getResult() {
590         if (result == null) {
591             result = new JTextArea JavaDoc(2, 20);
592             result.setWrapStyleWord(true);
593             result.setLineWrap(true);
594             result.setBounds(new Rectangle JavaDoc(10, 396, 290, 34));
595             result.setEditable(false);
596             result.setOpaque(false);
597             result.setBorder(new JTextField JavaDoc().getBorder());
598         }
599         return result;
600     }
601
602     /**
603      * This method initializes resultTxt
604      *
605      * @return javax.swing.JTextPane
606      */

607     private JTextPane JavaDoc getResultTxt() {
608         if (resultTxt == null) {
609             resultTxt = new JTextPane JavaDoc();
610             resultTxt.setBounds(new Rectangle JavaDoc(10, 370, 86, 24));
611             resultTxt.setFont(new Font JavaDoc("Dialog", Font.BOLD, 14));
612             resultTxt.setText("Result:");
613             resultTxt.setEditable(false);
614             resultTxt.setOpaque(false);
615         }
616         return resultTxt;
617     }
618
619     /**
620      * This method initializes salary
621      *
622      * @return javax.swing.JTextField
623      */

624     private JTextField JavaDoc getSalary() {
625         if (salary == null) {
626             salary = new JTextField JavaDoc();
627             salary.setText("0");
628             salary.setBounds(new Rectangle JavaDoc(150, 140, 100, 18));
629         }
630         return salary;
631     }
632
633     /**
634      * This method initializes jTextPane5
635      *
636      * @return javax.swing.JTextPane
637      */

638     private JTextPane JavaDoc getSalaryTxt() {
639         if (salaryTxt == null) {
640             salaryTxt = new JTextPane JavaDoc();
641             salaryTxt.setBounds(new Rectangle JavaDoc(10, 140, 90, 22));
642             salaryTxt.setEditable(false);
643             salaryTxt.setText("Salary:");
644             salaryTxt.setOpaque(false);
645         }
646         return salaryTxt;
647     }
648
649     /**
650      * This method initializes submit
651      *
652      * @return javax.swing.JButton
653      */

654     private JButton JavaDoc getSubmit() {
655         if (submit == null) {
656             submit = new JButton JavaDoc();
657             submit.setBounds(new Rectangle JavaDoc(30, 340, 120, 26));
658             submit.setText("Submit");
659             submit.addActionListener(new ActionListener JavaDoc() {
660                 public void actionPerformed(ActionEvent JavaDoc evt) {
661                     submit();
662                 }
663             });
664         }
665         return submit;
666     }
667
668     /**
669      * This method initializes jTextPane6
670      *
671      * @return javax.swing.JTextPane
672      */

673     private JTextPane JavaDoc getTaxesTxt() {
674         if (taxesTxt == null) {
675             taxesTxt = new JTextPane JavaDoc();
676             taxesTxt.setBounds(new Rectangle JavaDoc(8, 190, 94, 22));
677             taxesTxt.setText("Property taxes:");
678             taxesTxt.setOpaque(false);
679             taxesTxt.setEditable(false);
680         }
681         return taxesTxt;
682     }
683
684     private void initialize() {
685         this.setSize(new Dimension JavaDoc(410, 460));
686         this.setTitle("Petals Mortgage Demonstration");
687         // this.setContentPane(getJContentPane());
688
this.getContentPane().add(getJDesktopPane(), BorderLayout.CENTER);
689         this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
690         this.setResizable(false);
691     }
692
693 } // @jve:decl-index=0:visual-constraint="10,10"
694
Popular Tags