作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是编程的新手,至少是 Java 编程,我现在正在上课,我只需要有人给我指明方向。
我在让所有 JPanel 显示在应用程序屏幕的特定位置时遇到了问题。剩下的应该是所有计算的小菜一碟。
这是我到目前为止完成的代码:
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.*;
import java.text.NumberFormat;
import java.awt.GridLayout;
public class MortgageCalculatorGUI7 extends JFrame {
JPanel panel1 = new JPanel(new FlowLayout());
JRadioButton b7Yr = new JRadioButton("7 Years",false);
JRadioButton b15Yr = new JRadioButton("15 Years",false);
JRadioButton b30Yr = new JRadioButton("30 Years",false);
JRadioButton b535Int = new JRadioButton("5.35% Interest",false);
JRadioButton b55Int = new JRadioButton("5.5% Interest",false);
JRadioButton b575Int = new JRadioButton("5.75% Interest",false);
JPanel panel2 = new JPanel(new FlowLayout());
JLabel mortgageLabel = new JLabel("Mortgage Amount $", JLabel.LEFT);
JTextField mortgageText = new JTextField(10);
JLabel termLabel = new JLabel("Mortgage Term (Years)", JLabel.LEFT);
JTextField termText = new JTextField(3);
JLabel intRateLabel = new JLabel("Interest Rate (%)", JLabel.LEFT);
JTextField intRateText = new JTextField(5);
JLabel mPaymentLabel = new JLabel("Monthly Payment $", JLabel.LEFT);
JTextField mPaymentText = new JTextField(10);
JPanel panel3 = new JPanel(new FlowLayout());
JButton calculateButton = new JButton("CALCULATE");
JButton clearButton = new JButton("CLEAR");
JButton exitButton = new JButton("EXIT");
JPanel panel4 = new JPanel(new FlowLayout());
JLabel paymentLabel = new JLabel ("Payment #");
JLabel balLabel = new JLabel (" Balance");
JLabel ytdPrincLabel = new JLabel (" Principal");
JLabel ytdIntLabel = new JLabel (" Interest");
JPanel panel5 = new JPanel(new FlowLayout());
JTextArea textArea = new JTextArea(10, 31);
public MortgageCalculatorGUI7() {
this.setLayout (new BorderLayout());
panel1.setLayout (new FlowLayout());
panel2.setLayout (new FlowLayout());
panel3.setLayout (new FlowLayout());
panel4.setLayout (new FlowLayout());
panel5.setLayout (new FlowLayout());
panel1.add (b7Yr);
panel1.add (b15Yr);
panel1.add (b30Yr);
panel1.add (b535Int);
panel1.add (b55Int);
panel1.add (b575Int);
panel2.add (mortgageLabel);
panel2.add (mortgageText);
panel2.add (termLabel);
panel2.add (termText);
panel2.add (intRateLabel);
panel2.add (intRateText);
panel2.add (mPaymentLabel);
panel2.add (mPaymentText);
panel3.add (calculateButton);
panel3.add (clearButton);
panel3.add (exitButton);
panel4.add (paymentLabel);
panel4.add (balLabel);
panel4.add (ytdPrincLabel);
panel4.add (ytdIntLabel);
panel5.add (textArea);
add(panel2, BorderLayout.NORTH);
add(panel1, BorderLayout.CENTER);
add(panel4, BorderLayout.AFTER_LINE_ENDS);
add(panel5, BorderLayout.EAST);
add(panel3, BorderLayout.SOUTH);
exitButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}});
}
public static void main(String[] args) {
MortgageCalculatorGUI7 frame = new MortgageCalculatorGUI7();
frame.setBounds (200,200,800,500);
frame.setTitle ("Mortgage Calculator 1.0.4");
frame.setDefaultCloseOperation (EXIT_ON_CLOSE);
frame.setVisible (true);
}
}
感谢高级帮助。
最佳答案
FlowLayout
只是众多选项中的一个。我建议你看看不同的Layout Managers可以找到适合您需求的。
关于Java 抵押贷款计算器 GUI 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6720859/
我正在尝试编写一个 SQL 查询来根据以下公式计算 future 贷款余额: FV( future 余额)= CV(当前余额)- P(固定还款)+ I (利息资本化) 其中 **I = (CV * A
我是一名优秀的程序员,十分优秀!