728x90
반응형
복리 이자 계산기
빈프레임 윈도우를 만들어줍니다.
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class InterestCalc {
public static void main(String[] args) {
Frame calcFrame = new Frame();
calcFrame.setTitle("복리 이자 계산기");
calcFrame.setBounds(100,100,600,400);
calcFrame.setVisible(true);
calcFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}
윈도우내의 버튼, 그룹박스, 라벨, 텍스트 필드, 라디오 버튼을 추가하여 기본 틀을 만들어줍니다.
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class Main {
public static void main(String[] args) {
Frame calcFrame = new Frame();
calcFrame.setTitle("복리 이자 계산기");
calcFrame.setBounds(100,100,600,400);
calcFrame.setResizable(false);
calcFrame.setLayout(null);
Button buttonCalc = new Button("계산");
Button buttonClose = new Button("닫기");
buttonCalc.setBounds(500,30,90,40);
buttonClose.setBounds(500,75,90,40);
calcFrame.add(buttonCalc);
calcFrame.add(buttonClose);
calcFrame.setBackground(Color.LIGHT_GRAY);
Panel panelLeft = new Panel() {
public void paint(Graphics g) {
g.setColor(Color.BLACK);
g.drawRect(5,5,230,230);
g.setColor(Color.LIGHT_GRAY);
g.drawLine(7,5,37,5);
g.setColor(Color.BLACK);
g.drawString("준비",10,10);
}
};
panelLeft.setBounds(10,35,240,240);
calcFrame.add(panelLeft);
Panel panelRight = new Panel() {
public void paint(Graphics g) {
g.setColor(Color.BLACK);
g.drawRect(5,5,230,230);
g.setColor(Color.LIGHT_GRAY);
g.drawLine(7,5,92,5);
g.setColor(Color.BLACK);
g.drawString("복리 계산 주기",10,10);
}
};
panelRight.setBounds(250,35,240,240);
calcFrame.add(panelRight);
Panel panelBottom = new Panel() {
public void paint(Graphics g) {
g.setColor(Color.BLACK);
g.drawRect(5,5,470,105);
g.setColor(Color.LIGHT_GRAY);
g.drawLine(7,5,37,5);
g.setColor(Color.BLACK);
g.drawString("결과",10,10);
}
};
panelBottom.setBounds(10,275,480,115);
calcFrame.add(panelBottom);
panelLeft.setLayout(null);
Label labelPrincipal = new Label("원금");
labelPrincipal.setBounds(30,30,40,50);
panelLeft.add(labelPrincipal);
Label labelInterestRate = new Label("이율");
labelInterestRate.setBounds(30,100,40,50);
panelLeft.add(labelInterestRate);
Label labelPeriod = new Label("기간");
labelPeriod.setBounds(30,170,40,50);
panelLeft.add(labelPeriod);
final TextField tfPrincipal = new TextField(16);
tfPrincipal.setBounds(70,38,100,30);
panelLeft.add(tfPrincipal);
final TextField tfInerestRate = new TextField(16);
tfInerestRate.setBounds(70,108,100,30);
panelLeft.add(tfInerestRate);
final TextField tfPeriod = new TextField(16);
tfPeriod.setBounds(70,178,100,30);
panelLeft.add(tfPeriod);
Label labelPer = new Label("%");
labelPer.setBounds(180,100,40,50);
panelLeft.add(labelPer);
Label labelYears = new Label("years");
labelYears.setBounds(180,170,40,50);
panelLeft.add(labelYears);
CheckboxGroup group = new CheckboxGroup();
final Checkbox checkPeriod1Month =
new Checkbox(" 1개월",group,false);
final Checkbox checkPeriod3Month =
new Checkbox(" 3개월",group,false);
final Checkbox checkPeriod6Month =
new Checkbox(" 6개월",group,false);
final Checkbox checkPeriod1Year =
new Checkbox(" 12개월",group,true);
panelRight.setLayout(null);
checkPeriod1Month.setBounds(50,30,80,50);
checkPeriod3Month.setBounds(50,80,80,50);
checkPeriod6Month.setBounds(50,130,80,50);
checkPeriod1Year.setBounds(50,180,80,50);
panelRight.add(checkPeriod1Month);
panelRight.add(checkPeriod3Month);
panelRight.add(checkPeriod6Month);
panelRight.add(checkPeriod1Year);
panelBottom.setLayout(null);
Label labelInterestEarnd = new Label("이자");
labelInterestEarnd.setBounds(30,30,40,50);
panelBottom.add(labelInterestEarnd);
Label labelAmountEarnd = new Label("총액");
labelAmountEarnd.setBounds(230,30,40,50);
panelBottom.add(labelAmountEarnd);
final TextField tfInterestEarned = new TextField(16);
tfInterestEarned.setBounds(70,38,100,30);
panelBottom.add(tfInterestEarned);
final TextField tfAmountEarned = new TextField(16);
tfAmountEarned.setBounds(270,38,100,30);
panelBottom.add(tfAmountEarned);
}
}
728x90
반응형
'즐거운프로그래밍' 카테고리의 다른 글
[자바] 간단한 슈팅게임 만들기 예제 1 (0) | 2023.10.24 |
---|---|
[자바] 대화 상자 프로그램 포팅 : Java JWT 기반(복리 이자 계산기 만들기 2) (0) | 2023.10.24 |
[자바] Canvas의 이해와 활용(그림 파일 불러오기) (0) | 2023.10.24 |
[자바] Canvas의 이해와 활용(컬러 적용하기) (0) | 2023.10.24 |
[자바] Canvas의 이해와 활용(그래픽 처리 작업) (0) | 2023.10.24 |