-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoan_Screen.java
More file actions
146 lines (103 loc) · 3.24 KB
/
Loan_Screen.java
File metadata and controls
146 lines (103 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/*****************************************************************************************************
* Represents an instance of the main loan computation screen to display to the user in the JFrame.
*****************************************************************************************************/
public class Loan_Screen extends JPanel
{
/* Pointer to the main java panel to access other panels */
private Background_Panel background;
private double loanAmount, interest;
private int years;
private JTextField loantf, yearstf, inttf;
private Output_Panel totalPaid, yearlyPayments, monthlyPayments;
private Loan loan;
/*********************************************************************************
* Main constructor used when creating a main menu.
*********************************************************************************/
public Loan_Screen(Background_Panel outerPanel)
{
setLayout(new GridLayout(7, 2));
//setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
this.background = outerPanel; // reference to outer panel
add(new Centered_Text_Panel("Loan Amount: $"));
add(loantf = new JTextField(10));
add(new Centered_Text_Panel("Duration of Loan in Years: "));
add(yearstf = new JTextField(10));
add(new Centered_Text_Panel("Interest rate of Loan: "));
add(inttf = new JTextField(10));
add(new JLabel());
add(new Submit_Button());
add(new Centered_Text_Panel("Total Payments: "));
add(totalPaid = new Output_Panel(""));
add(new Centered_Text_Panel("Yearly Payments: "));
add(yearlyPayments = new Output_Panel(""));
add(new Centered_Text_Panel("Monthly Payments: "));
add(monthlyPayments = new Output_Panel(""));
}
private class Submit_Button extends JButton
{
public Submit_Button()
{
super("Submit");
addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
fetchInput();
outputResults();
}
catch (Exception ex)
{
System.err.println(ex);
}
}
});
}
}
public void fetchInput() throws Exception
{
loanAmount = Double.parseDouble(loantf.getText());
years = Integer.parseInt(yearstf.getText());
interest = Double.parseDouble(inttf.getText());
loan = new Loan(loanAmount, interest, years);
}
public void outputResults()
{
String total = Double.toString(loan.getTotalPaid());
double payments = loan.getPaymentAmount();
totalPaid.setText(total);
yearlyPayments.setText(Double.toString(payments));
monthlyPayments.setText(Double.toString(payments / 12));
//displayOutputPanel(loan.getPayment(), loan.total)
}
private class Output_Panel extends JPanel
{
private JLabel currentText;
public Output_Panel(String text)
{
setLayout(new GridBagLayout());
add(currentText = new JLabel(text));
}
public void setText(String newText) { currentText.setText(newText); }
}
/*
private class Input_Field extends JTextField
{
public Input_Field(String place)
{
super(10);
addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
fetchInput();
outputResults();
}
});
}
}*/
} // end Loan_Screen class