- #1
DarkAnt
- 195
- 0
My program has a slight gui problem. The bottom of my gui (the textboxes) are being cut off. I have no idea why this is happening and I have very little experience with GUIs. Could someone tell me why this is happening and how to fix it/better way of doing it. Thanks
ok here is my code
ok here is my code
Code:
package project_7_6;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
class Gui extends JFrame implements ActionListener{
JLabel principalLabel;
JLabel downpaymentLabel;
JLabel monthlyPaymentLabel;
JLabel interestLabel;
JLabel yearsLabel;
JTextField principalField;
JTextField downpaymentField;
JTextField monthlyPaymentField;
JTextField interestField;
JTextField yearsField;
JTextArea monthTextArea;
JTextArea totalBalanceOwedTextArea;
JTextArea interestOwedTextArea;
JTextArea principalOwedTextArea;
JTextArea paymentTextArea;
JTextArea amountOwedTextArea;
JButton calculateButton;
JScrollPane scroll1;
JScrollPane scroll2;
JScrollPane scroll3;
JScrollPane scroll4;
JScrollPane scroll5;
JScrollPane scroll6;
int month;
public double ballanceOwed, amountOwed, principal, downPayment, monthlyPayment, annualInterest, interestOwed, principalOwed, payment;
public String strPrincipal;
public String strDownpayment;
public String strMonthlyPayment;
public String strInterest;
public String strYears;
public String strBallanceOwed;
public String strPayment;
public String strMonth;
public String strAmountOwed;
public Gui() {
super("TidBit Computer Store Ripoffs");
setSize(400,500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container pane = getContentPane();
FlowLayout flow = new FlowLayout(FlowLayout.LEFT);
FlowLayout button = new FlowLayout(FlowLayout.CENTER);
GridLayout grid = new GridLayout(7,2);
pane.setLayout(grid);
JPanel row1 = new JPanel();
principalLabel = new JLabel("Principal: $", JLabel.RIGHT);
principalField = new JTextField(8);
JPanel row2 = new JPanel();
downpaymentLabel = new JLabel("Down Payment: $", JLabel.RIGHT);
downpaymentField = new JTextField(8);
JPanel row3 = new JPanel();
monthlyPaymentLabel = new JLabel("Monthly Payment:", JLabel.RIGHT);
monthlyPaymentField = new JTextField(8);
JPanel row4 = new JPanel();
interestLabel = new JLabel("Interest:", JLabel.RIGHT);
interestField = new JTextField(3);
JPanel row6 = new JPanel();
calculateButton = new JButton("Calculate");
calculateButton.addActionListener(this);
JPanel row7 = new JPanel();
monthTextArea = new JTextArea();
monthTextArea.setLineWrap(true);
monthTextArea.setWrapStyleWord(true);
monthTextArea.setRows(12);
totalBalanceOwedTextArea = new JTextArea();
totalBalanceOwedTextArea.setLineWrap(true);
totalBalanceOwedTextArea.setWrapStyleWord(true);
totalBalanceOwedTextArea.setRows(12);
interestOwedTextArea = new JTextArea();
interestOwedTextArea.setLineWrap(true);
interestOwedTextArea.setWrapStyleWord(true);
interestOwedTextArea.setRows(12);
principalOwedTextArea = new JTextArea();
principalOwedTextArea.setLineWrap(true);
principalOwedTextArea.setWrapStyleWord(true);
principalOwedTextArea.setRows(12);
paymentTextArea = new JTextArea();
paymentTextArea.setLineWrap(true);
paymentTextArea.setWrapStyleWord(true);
paymentTextArea.setRows(12);
amountOwedTextArea = new JTextArea();
amountOwedTextArea.setLineWrap(true);
amountOwedTextArea.setWrapStyleWord(true);
amountOwedTextArea.setRows(12);
scroll1 = new JScrollPane(monthTextArea);
scroll2 = new JScrollPane(totalBalanceOwedTextArea);
scroll3 = new JScrollPane(interestOwedTextArea);
scroll4 = new JScrollPane(principalOwedTextArea);
scroll5 = new JScrollPane(paymentTextArea);
scroll6 = new JScrollPane(amountOwedTextArea);
row1.setLayout(flow);
row2.setLayout(flow);
row3.setLayout(flow);
row4.setLayout(flow);
row6.setLayout(button);
row7.setLayout(button);
row1.add(principalLabel);
row1.add(principalField);
row2.add(downpaymentLabel);
row2.add(downpaymentField);
row3.add(monthlyPaymentLabel);
row3.add(monthlyPaymentField);
row4.add(interestLabel);
row4.add(interestField);
row6.add(calculateButton);
row7.add(scroll1);
row7.add(scroll2);
row7.add(scroll3);
row7.add(scroll4);
row7.add(scroll5);
row7.add(scroll6);
pane.add(row1);
pane.add(row2);
pane.add(row3);
pane.add(row4);
pane.add(row6);
pane.add(row7);
setContentPane(pane);
setVisible(true);
}
public void actionPerformed(ActionEvent event)
{
String command = event.getActionCommand();
if (command.equals("Calculate"))
{
strPrincipal = principalField.getText();
strDownpayment = downpaymentField.getText();
strMonthlyPayment = monthlyPaymentField.getText();
strInterest = interestField.getText();
principal = Integer.parseInt(strPrincipal);
downPayment = Integer.parseInt(strDownpayment);
monthlyPayment = Integer.parseInt(strMonthlyPayment);
annualInterest = Integer.parseInt(strInterest);
monthlyPayment = monthlyPayment * .01;
annualInterest = annualInterest * .01;
strMonth = "Month";
strBallanceOwed = "Ballance Owed";
strInterest = "Interest Owed";
strPrincipal = "Principal Owed";
strPayment = "Payment";
strAmountOwed = "Amount Owed";
monthTextArea.setText(strMonth);
totalBalanceOwedTextArea.setText(strBallanceOwed);
interestOwedTextArea.setText(strInterest);
principalOwedTextArea.setText(strPrincipal);
paymentTextArea.setText(strPayment);
amountOwedTextArea.setText(strAmountOwed);
amountOwed = principal - downPayment;
principalOwed = (principal - downPayment) * monthlyPayment;
month = 0;
principalOwed = principalOwed * 100;
principalOwed = Math.round(principalOwed);
principalOwed = principalOwed / 100;
while (amountOwed > 0)
{
month++;
interestOwed = annualInterest * amountOwed / 12;
interestOwed = interestOwed * 100;
interestOwed = Math.round(interestOwed);
interestOwed = interestOwed / 100;
ballanceOwed = amountOwed;
ballanceOwed = ballanceOwed * 100;
ballanceOwed = Math.round(ballanceOwed);
ballanceOwed = ballanceOwed / 100;
payment = interestOwed + principalOwed;
amountOwed = amountOwed - payment;
amountOwed = amountOwed * 100;
amountOwed = Math.round(amountOwed);
amountOwed = amountOwed / 100;
if(amountOwed <= 0)
{
principalOwed = ballanceOwed - interestOwed;
payment = ballanceOwed;
amountOwed = 0;
}
strMonth = strMonth + "\n" + month;
monthTextArea.setText(strMonth);
strBallanceOwed = strBallanceOwed + "\n" + ballanceOwed;
totalBalanceOwedTextArea.setText(strBallanceOwed);
strInterest = strInterest + "\n" + interestOwed;
interestOwedTextArea.setText(strInterest);
strPrincipal = strPrincipal + "\n" + principalOwed;
principalOwedTextArea.setText(strPrincipal);
strPayment = strPayment + "\n" + payment;
paymentTextArea.setText(strPayment);
strAmountOwed = strAmountOwed + "\n" + amountOwed;
amountOwedTextArea.setText(strAmountOwed);
}
}
}
}
Last edited: