📄 新建 文本文档.txt
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.DecimalFormat;
public class CarPayment extends JFrame
{
private JLabel priceJLabel;
private JTextField priceJTextField;
private JLabel downPaymentJLabel;
private JTextField downPaymentJTextField;
private JLabel interestJLabel;
private JTextField interestJTextField;
private JButton calculateJButton;
private JTextArea paymentsJTextArea;
public CarPayment()
{
createUserInterface();
}
private void createUserInterface()
{
container contentPane = getContentPane();
contentPane.setLayout(null);
priceJLabel = new JLabel();
priceJLabel.setBounds(40,24,80,21);
priceJLabel.setText("Price:");
contentPane.add(priceJLabel);
priceTextField = new JTextField();
priceTextField.setBounds(184,24,56,21);
priceTextField.setHorizontalAlignment(JTextField.RIGHT);
contentPane.add(priceTextField);
downPaymentJLabel = new JLabel();
downPaymentJLabel.setBounds(40,56,96,21);
downPaymentJLabel.setText("Down payment:");
contentPane.add(downPaymentJLabel);
downPaymentJTextField = new JTextField();
downPaymentJTextField.setBounds(184,56,56,21);
downPaymentJTextField.setHorizontalAlignment(JTextField.RIGHT);
contentPane.add(downPaymentJTextField);
interestJLabel = new JLabel();
interestJLabel.setBounds(40,88,120,21);
interestJLabel.setText("Annual interest rate:");
contentPane.add(interestJLabel);
interestJTextField = new JTextField();
interestJTextField.setBounds(184,88,56,21);
interestJTextField.setHorizontalAlignment(JTextField.RIGHT);
contentPane.add(intersetJTextField);
calculateJButton = new JButton();
calculateJButton.setBounds(92,128,94,24);
calculateJButton.setText("Calculate")
contentPane.add(calculateJButton);
calculateJButton.addActionListener(
new ActionListener()
{
public void actionperformed(ActionEvent event);
{
calculateJButtonActionPerformed(event);
}
}
);
paymentsJTextArea = new JTextArea();
paymentsJTextArea.setBounds(28,168,232,90);
paymentsJTextArea.setEditable(false);
contentPane.add(paymentsJTextArea);
setTitle("Car Payment Calculator");
setSize(288,302);
setVisible(true);
}
private void calculateJButtonActionPerformed(ActionEvent event)
{
int years = 2;
int months;
doubule monthlyPayment;
paymentsJTextArea.setText("");
paymentsJTextArea.append
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -