Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package xibbar
- import javax.swing.{JFrame,JLabel,JTextField,JButton,JPanel,BoxLayout}
- import java.awt.event.{ActionListener,ActionEvent}
- object LoanProcessor {
- def main(args: Array[String]){
- val window=new MainWindow()
- window.show
- window.updateResult
- }
- }
- class MainWindow extends JFrame{
- this.setSize(200,200)
- this.setTitle("ローン計算")
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
- val panel=new JPanel()
- val amountField=new JTextField(10)
- val yearField=new JTextField(10)
- val rateField=new JTextField(10)
- val monthlyPayLabel=new JLabel()
- val yearlyPayLabel=new JLabel()
- val processButton=new JButton("計算")
- val finishButton=new JButton("終了")
- val boxLayout=new BoxLayout(panel,BoxLayout.Y_AXIS)
- this.getContentPane().add(panel)
- panel.setLayout(boxLayout)
- panel.add(amountField)
- panel.add(yearField)
- panel.add(rateField)
- panel.add(monthlyPayLabel)
- panel.add(yearlyPayLabel)
- panel.add(processButton)
- panel.add(finishButton)
- amountField.setText("4000")
- yearField.setText("35")
- rateField.setText("3.05")
- processButton.addActionListener(new ActionListener(){
- def actionPerformed(e:ActionEvent){
- updateResult
- }
- }
- )
- finishButton.addActionListener(new ActionListener(){
- def actionPerformed(e:ActionEvent){
- System.exit(0)
- }
- }
- )
- def updateResult{
- val amount=amountField.getText().toInt
- val year=yearField.getText().toInt
- val rate=rateField.getText().toFloat
- val result=processing(amount,year,rate)
- monthlyPayLabel.setText("毎月支払額:"+(result).toInt)
- yearlyPayLabel.setText("年間支払額:"+(result).toInt*12)
- }
- def processing(amount: Int, year: Int, rate: Float): Double={
- amount*10000*(rate/12/100)/(1-Math.pow(1+rate/12/100,-year*12))
- }
- }
Add Comment
Please, Sign In to add comment